Next Previous Contents

2. Introduction

S-Lang is a powerful interpreted language that may be embedded into an application to make the application extensible. This enables the application to be used in ways not envisioned by the programmer, thus providing the application with much more flexibility and power. Examples of applications that take advantage of the interpreter in this way include the jed editor and the slrn newsreader.

2.1 Language Features

The language features both global and local variables, branching and looping constructs, user-defined functions, structures, datatypes, and arrays. In addition, there is limited support for pointer types. The concise array syntax rivals that of commercial array-based numerical computing environments.

2.2 Data Types and Operators

The language provides built-in support for string, integer (signed and unsigned long and short), double precision floating point, and double precision complex numbers. In addition, it supports user defined structure types, multi-dimensional array types, and associative arrays. To facilitate the construction of sophisticated data structures such as linked lists and trees, a `reference' type was added to the language. The reference type provides much of the same flexibility as pointers in other languages. Finally, applications embedding the interpreter may also provide special application specific types, such as the Mark_Type that the jed editor provides.

The language provides standard arithmetic operations such as addition, subtraction, multiplication, and division. It also provides support for modulo arithmetic as well as operations at the bit level, e.g., exclusive-or. Any binary or unary operator may be extended to work with any data type. For example, the addition operator (+) has been extended to work between string types to permit string concatenation.

The binary and unary operators work transparently with array types. For example, if a and b are arrays, then a + b produces an array whose elements are the result of element by element addition of a and b. This permits one to do vector operations without explicitly looping over the array indices.

2.3 Statements and Functions

The S-Lang language supports several types of looping constructs and conditional statements. The looping constructs include while, do...while, for, forever, loop, foreach, and _for. The conditional statements include if, if-then-else, and !if.

User defined functions may be defined to return zero, one, or more values. Functions that return zero values are similar to `procedures' in languages such as PASCAL. The local variables of a function are always created on a stack allowing one to create recursive functions. Parameters to a function are always passed by value and never by reference. However, the language supports a reference data type that allows one to simulate pass by reference.

Unlike many interpreted languages, S-Lang allows functions to be dynamically loaded (function autoloading). It also provides constructs specifically designed for error handling and recovery as well as debugging aids (e.g., function tracebacks).

Functions and variables may be declared as private belonging to a namespace associated with the compilation unit that defines the function or variable. The ideas behind the namespace implementation stems from the C language and should be quite familiar to any one familiar with C.

2.4 Error Handling

The S-Lang language defines a construct called an error-block that may be used for error handling and recovery. When a non-fatal run-time error is encountered, any error blocks that have been defined are executed as the run-time stack unwinds. An error block can optionally clear the error and the program will continue running after the statement that triggered the error. This mechanism is somewhat similar to try-catch in C++.

2.5 Run-Time Library

Functions that compose the S-Lang run-time library are called intrinsics. Examples of S-Lang intrinsic functions available to every S-Lang application include string manipulation functions such as strcat, strchop, and strcmp. The S-Lang library also provides mathematical functions such as sin, cos, and tan; however, not all applications enable the use of these intrinsics. For example, to conserve memory, the 16 bit version of the jed editor does not provide support for any mathematics other than simple integer arithmetic, whereas other versions of the editor do support these functions.

Most applications embedding the languages will also provide a set of application specific intrinsic functions. For example, the jed editor adds over 100 application specific intrinsic functions to the language. Consult your application specific documentation to see what additional intrinsics are supported.

2.6 Input/Output

The language supports C-like stdio input/output functions such as fopen, fgets, fputs, and fclose. In addition it provides two functions, message and error, for writing to the standard output device and standard error. Specific applications may provide other I/O mechanisms, e.g., the jed editor supports I/O to files via the editor's buffers.

2.7 Obtaining S-Lang

Comprehensive information about the library may be obtained via the World Wide Web from http://www.s-lang.org.

S-Lang as well as some programs that embed it are freely available via anonymous ftp in the United States from

It is also available outside the United States from the following mirror sites:

The Usenet newsgroup alt.lang.s-lang was created for S-Lang programmers to exchange information and share macros for the various programs the embed the language. The newsgroup comp.editors can be a useful resource for S-Lang macros for the jed editor. Similarly, slrn users will find news.software.readers to be a valuable source of information.

Finally, two mailing lists dealing with the S-Lang library have been created:

The first list is for announcements of new releases of the library, while the second list is intended for those who use the library for their own code development. To subscribe to the announcement list, send an email to slang-announce-subscribe@babayaga.math.fu-berlin.de and include the word subscribe in the body of the message. To subscribe to the developers list, use the address slang-workers-subscribe@babayaga.math.fu-berlin.de.


Next Previous Contents