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, lists, and associative arrays. To facilitate the construction of sophisticated data structures such as linked lists and trees, the language also inclues a ``reference'' type. 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, including user-defined types. 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 stem from the C language and should be quite familiar to any one familiar with C.

2.4 Error Handling

The S-Lang language has a try/throw/catch/finally exception model whose semantics are similar to that of other languages. Users may also extend the exception class hierarchy with user-defined exceptions. The ERROR_BLOCK based exception model of S-Lang 1.x is still supported but deprecated.

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.

Operating systems that support dynamic linking allow a slang interpreter to dynamically link additional libraries of intrinsic functions and variables into the interpreter. Such loadable objects are called modules. A separate chapter of this manual is devoted to this important feature.

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 more information about S-Lang

Comprehensive information about the library may be obtained via the World Wide Web from http://www.jedsoft.org/slang/. In particular see http://www.jedsoft.org/slang/download.html for downloading the latest version of the library.

Users with generic questions about the interpreter are encouraged to post questions to the Usenet newsgroup alt.lang.s-lang. More specific questions relating to the use of S-Lang within some application may be better answered in an application-specifc forum. For example, users with questions about using S-Lang as embedded in the jed editor are more likely to be answered in the comp.editors newsgroup or on the jed mailing list. Similarly users with questions concerning slrn will find news.software.readers to be a valuable source of information.

Developers who have embedded the interpreter are encouraged to join the S-Lang mailing list. To subscribe to the list or just browse the archives, visit http://www.jedsoft.org/slang/mailinglists.html.


Next Previous Contents