[ Home | Docs | News | Resources | Download]
GAUL Documentation: Scripting

Introduction to S-Lang

S-Lang is a procedural, interpreted, programming language that shares many similarities with C. Due to these similarities, the learning curve is very shallow when compared to other comparably powerful scripting languages.

In addition the the features and advantages that would be expected of a modern scripting language, S-Lang particularly excels with its array handling and intrinsic numerical capabilities.

S-Lang is not as widely acknowledged as some scripting languages, such as Perl or Python, but it is embedded into many successful and popular open-source applications including the JED text editor, the SLRN news reader, the Lynx web browser, the Mutt email reader and several niche scientific applications.

S-Lang is included as part of all the major Linux distributions. It is highly portable, and has been demonstrated on a number of computer platforms including UNIX and Windows.

Further information about S-Lang is available at the S-Lang website.

S-Lang Primer

The basic S-Lang syntax resembles C. Its concise array syntax is said to rival those of the commercial array-based numerical computing environments. You are refered to the full S-Lang documentation, however, a very, very brief overview is given here.

Variables are declared using the "variable" keyword, and this must be done before a variable may be used. The exact type of the variable is not defined and may even change acorrding to context. For example:

variable a, b;           % This declares two variables, 'a' and 'b'.
a = 3.4 + sin(10.9);     % Sets a to approximately 3.6
b = 3;                   % Sets b to the integer value of 3.
b = "Bogus wave, dude."; % Now b is a string.

Anything on a line beyond a "%" symbol is treated as a comment, and is ignored by the interpreter.

Functions must also be declared prior to use, and this is performed by the "define" keyword. In S-Lang, functions may return none, one or more values.

define add_and_subtract( x, y ) {
  variable a=x+y;
  variable b=x-y;
  return a,b;

variable plus, minus;
(plus, minus) = add_and_subtract( 10, 6 );
% 'plus' is now 16.  'minus' is now 4.

S-Lang in GAUL

GAUL contains all the code required to enable its functions to be called from within a S-Lang script, and may also be extended by S-Lang code.

The GAUL test directory includes a simple application that will run arbitrary S-Lang scripts, but also enables them to utilise a set of intrinsic functions defined by GAUL. See tests/test_slang.c for source code and tests/test_slang.sl for a simple script that performs an evolutionary simulation. In general, the GAUL functions available through its C API are also available through the S-Lang API. A few functions have not been wrapped as S-Lang intrinsics for reasons of practicability (or laziness on my part), and these include the simple genesis functions.

C pointers are not available within S-Lang scripts, so the interface uses integer handles to index both entities and populations.


[ Home | Docs | News | Resources | Download]
Hosted by:
SourceForge Logo
GAUL Button Valid HTML 4.01!

© 2003-2009, "Stewart Adcock" <stewart@linux-domain.com> All rights reserved.
All trademarks on this page are probably owned by their respective companies. You can insert you own favourite disclaimer here.