The Sling programming language is a general-purpose, object oriented programming language that can be used for all kinds of software development, including web and mobile application development, backend systems and database programming, server applications, desktop applications and embedded software. The language reference documentation specifies and describes the various features of the language in detail.

Filed under

Before You Read This Documentation

If you do not yet fully know what Sling is or what it is for, you might want to start with the following:

Sling homepage on EQDN

Introduction

The syntax of the Sling programming language was originally designed on the foundation of the pre-existing EQ programming language, which in turn derived many of its original ideas from languages such as Java, C# and C/C++. However, the development of Sling itself was also inspired by many other languages, including (but not limited to) FoxPro, Visual Basic, Lua, Python and other modern (and less modern) languages. Overall, it could be said that the language still belongs in the "C" syntax family (as it uses curly braces for grouping), but carries a very distinct syntax in many places.

The sample program below serves as a sample demonstrating the general syntax:

// MyClass.sling -- Sling code files are saved with the ".sling" extension

/*
 * This is a class declaration. The name of the class is automatically
 * determined from the name of the file. Continues until
 * the end of the file.
 */

class:

// This is the class constructor.

ctor
{
}

// This is a method inside the class: It receives one integer parameter
// and returns an integer value.

func doSomething(x as int) as int
{
	var n = 100
	n = n + x
	return n
}

// This is another method that takes no parameters and returns no value.
// This method prints the word "Hello" one hundred times.

func execute
{
	for(var n=0; n<100; n++):
		PRINT "Hello"
}

The purpose of this documentation is to provide a comprehensive specification of the language and its feature. At the same time, this document is meant to be readable also for the practical purpose of learning the language and understanding how it can be used.

General Language Features

The following topics describe many commonly used, fundamental features of the language:

The Sling language: Common terminology

General syntax of a Sling program

Comments and documentation strings in Sling

Modifiers in Sling

Data types in Sling

Variables and variable declarations in Sling

Entities

Each source code file in a Sling program is used to define at least one entity. Entities represent blocks of code that are used in different ways (depending on the type of the entity) to combine functionality and to define the unique character, functionality and structure of the entity. While it is generally possible to declare several entities in a single file, it is usually not a recommended practice.

Commonly used entity types are classes and interfaces.

All entities have a name, which must be a valid identifier. Furthermore, each entity declaration also always declares a data type that can be used eg. in variable declarations, function parameters, etc. Sling currently defines the following types of entities:

Classes in Sling

Interfaces in Sling

Functions and methods in Sling

Expressions

Expressions are used in many parts of programs including as components of statements, variable values and as default values for function parameters. An expression always returns a value of a specific data type, depending on the expression and its parameters, and is often composed of a number of "sub-expressions" connected to each other via operators (see below). The primary expressions are fundamental building blocks that can be combined together by the use of operators, or as parts of compound expressions.

Primary expressions in Sling

Sling operators

Compound expressions in sling

Sling: User Interface Expressions

Statements and control structures

The Sling language defines a number of standard built-in statements and control structures, described in the articles below. Note that while many of the statements come with two optional syntaxes, one with the use of parenthesis around the parameter expression and one without, the version WITHOUT the parenthesis is always preferred and encouraged. Future versions of the Sling compilers may issue warnings or even errors when parenthesis are used where they are not necessary.

Sling: Empty statement

Sling: Block statement

Sling: Variable declaration statement

Sling: If statement

Sling: While statement

Sling: For statement

Sling: Foreach statement

Sling: Loop statement

Sling: Break statement

Sling: Continue statement

Sling: Return statement

Sling: Switch statement

Sling: Critical statement

Sling: Try-catch statements

Sling: Throw statement

Sling: Assert statement

Sling: Preprocessor statements

Sling: Print statement

Sling: Error statement

Sling: Trace statement

Sling: Lang statement

Sling: Template statement

Other features

For other language features not particularly discussed above, see the following:

Sling: Vector operations

sling-map

sling-string

Sling Data Models


Twitter Facebook LinkedIn Youtube Slideshare Github