<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE> A Guide to the S-Lang Language: Introduction</TITLE>
<LINK HREF="slang-3.html" REL=next>
<LINK HREF="slang-1.html" REL=previous>
<LINK HREF="slang.html#toc2" REL=contents>
</HEAD>
<BODY>
<A HREF="slang-3.html">Next</A>
<A HREF="slang-1.html">Previous</A>
<A HREF="slang.html#toc2">Contents</A>
<HR>
<H2><A NAME="s2">2. Introduction</A></H2>

<P> 
<P><B>S-Lang</B> 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 <B>jed</B> editor and the <B>slrn</B>
newsreader.
<P>
<H2><A NAME="ss2.1">2.1 Language Features</A>
</H2>

<P>
<P>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.
<P>
<H2><A NAME="ss2.2">2.2 Data Types and Operators</A>
</H2>

<P> 
<P>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
<CODE>Mark_Type</CODE> that the <B>jed</B> editor provides.
<P>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 (<CODE>+</CODE>) has been extended to work between
string types to permit string concatenation.
<P>The binary and unary operators work transparently with array types.
For example, if <CODE>a</CODE> and <CODE>b</CODE> are arrays, then <CODE>a + b</CODE>
produces an array whose elements are the result of element by
element addition of <CODE>a</CODE> and <CODE>b</CODE>.  This permits one to do
vector operations without explicitly looping over the array
indices.
<P>
<P>
<H2><A NAME="ss2.3">2.3 Statements and Functions</A>
</H2>

<P> 
<P>The <B>S-Lang</B> language supports several types of looping constructs and
conditional statements.  The looping constructs include <CODE>while</CODE>,
<CODE>do...while</CODE>, <CODE>for</CODE>, <CODE>forever</CODE>, <CODE>loop</CODE>, <CODE>foreach</CODE>,
and <CODE>_for</CODE>. The conditional statements include <CODE>if</CODE>,
<CODE>if-then-else</CODE>, and <CODE>!if</CODE>.
<P>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
<EM>reference</EM> data type that allows one to simulate pass by
reference.
<P>Unlike many interpreted languages, <B>S-Lang</B> 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).
<P>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.
<P>
<P>
<H2><A NAME="ss2.4">2.4 Error Handling</A>
</H2>

<P> 
<P>The <B>S-Lang</B> language defines a construct called an <EM>error-block</EM>
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++.
<P>
<P>
<H2><A NAME="ss2.5">2.5 Run-Time Library</A>
</H2>

<P> 
<P>Functions that compose the <B>S-Lang</B> run-time library are called
<EM>intrinsics</EM>.  Examples of <B>S-Lang</B> intrinsic functions available
to every <B>S-Lang</B> application include string manipulation functions
such as <CODE>strcat</CODE>, <CODE>strchop</CODE>, and <CODE>strcmp</CODE>.  The <B>S-Lang</B>
library also provides mathematical functions such as <CODE>sin</CODE>,
<CODE>cos</CODE>, and <CODE>tan</CODE>; however, not all applications enable the
use of these intrinsics.  For example, to conserve memory, the 16
bit version of the <B>jed</B> editor does not provide support for any
mathematics other than simple integer arithmetic, whereas other
versions of the editor do support these functions.
<P>Most applications embedding the languages will also provide a set of
application specific intrinsic functions.  For example, the <B>jed</B>
editor adds over 100 application specific intrinsic functions to
the language.  Consult your application specific documentation to
see what additional intrinsics are supported.
<P>
<P>
<H2><A NAME="ss2.6">2.6 Input/Output</A>
</H2>

<P>
<P>The language supports C-like stdio input/output functions such as
<CODE>fopen</CODE>, <CODE>fgets</CODE>, <CODE>fputs</CODE>, and <CODE>fclose</CODE>.  In
addition it provides two functions, <CODE>message</CODE> and <CODE>error</CODE>,
for writing to the standard output device and standard error.
Specific applications may provide other I/O mechanisms, e.g.,
the <B>jed</B> editor supports I/O to files via the editor's
buffers.
<P>
<H2><A NAME="ss2.7">2.7 Obtaining <B>S-Lang</B></A>
</H2>

<P> 
<P>Comprehensive information about the library may be obtained via the
World Wide Web from <CODE>http://www.s-lang.org</CODE>.
<P><B>S-Lang</B> as well as some programs that embed it are freely available
via anonymous ftp in the United States from
<UL>
<LI> 
<A HREF="ftp://space.mit.edu/pub/davis">ftp://space.mit.edu/pub/davis</A>.</LI>
</UL>

It is also available outside the United States from the following
mirror sites:
<UL>
<LI> 
<A HREF="ftp://ftp.uni-stuttgart.de/pub/unix/misc/slang/">ftp://ftp.uni-stuttgart.de/pub/unix/misc/slang/</A></LI>
<LI> 
<A HREF="ftp://ftp.fu-berlin.de/pub/unix/news/slrn/">ftp://ftp.fu-berlin.de/pub/unix/news/slrn/</A></LI>
<LI> 
<A HREF="ftp://ftp.ntua.gr/pub/lang/slang/">ftp://ftp.ntua.gr/pub/lang/slang/</A></LI>
</UL>
<P>The Usenet newsgroup <CODE>alt.lang.s-lang</CODE> was created for <B>S-Lang</B>
programmers to exchange information and share macros for the various
programs the embed the language.  The newsgroup <CODE>comp.editors</CODE>
can be a useful resource for <B>S-Lang</B> macros for the <B>jed</B> editor.
Similarly, <B>slrn</B> users will find <CODE>news.software.readers</CODE> to be a
valuable source of information.
<P>Finally, two mailing lists dealing with the <B>S-Lang</B> library have been
created: 
<UL>
<LI> <CODE>slang-announce@babayaga.math.fu-berlin.de</CODE></LI>
<LI> <CODE>slang-workers@babayaga.math.fu-berlin.de</CODE></LI>
</UL>

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
<CODE>slang-announce-subscribe@babayaga.math.fu-berlin.de</CODE> and include
the word <CODE>subscribe</CODE> in the body of the message.  To subscribe to
the developers list, use the address
<CODE>slang-workers-subscribe@babayaga.math.fu-berlin.de</CODE>.
<P>
<P>
<P>
<HR>
<A HREF="slang-3.html">Next</A>
<A HREF="slang-1.html">Previous</A>
<A HREF="slang.html#toc2">Contents</A>
</BODY>
</HTML>
