S-Lang

{{Short description|Software library and scripting language}}

{{Infobox software

| name = S-Lang

| screenshot = JED-editor-slang-source.png

| caption = S-Lang based editor, JED

| developer = John E. Davis{{cite web |last1=Davis |first1=John |title=A little bit about me |url=https://www.jedsoft.org/aboutme.html |website=John E. Davis Software |accessdate=1 June 2020 |archiveurl=https://web.archive.org/web/20200601010922/https://www.jedsoft.org/aboutme.html |archivedate=1 June 2020 |date=26 November 2017}}

| latest release version = {{wikidata|property|preferred|references|edit|Q2204463|P348|P548=Q2804309}}

| latest release date = {{wikidata|qualifier|preferred|single|Q2204463|P348|P548=Q2804309|P577}}

| latest preview version = {{wikidata|property|preferred|references|edit|Q2204463|P348|P548=Q51930650}}

| latest preview date = {{wikidata|qualifier|preferred|single|Q2204463|P348|P548=Q51930650|P577}}

| programming language = S-Lang scripting language

| operating system = POSIX

| genre = Widget toolkit

| license = GPL-2.0-or-later{{cite web |last1=Davis |first1=John |title=S-Lang Software License Information |url=http://jedsoft.org/slang/license.html |website=John E. Davis Software |accessdate=31 May 2020 |archiveurl=https://web.archive.org/web/20200601011204/http://jedsoft.org/slang/license.html |archivedate=1 June 2020 |date=4 March 2018}}

| website = {{Official URL}}

}}{{Not to be confused with|S (programming language)}}

The S-Lang programming library is a software library for Unix, Windows, VMS, OS/2, and Mac OS X. It provides routines for embedding an interpreter for the S-Lang scripting language, and components to facilitate the creation of text-based applications.Linux Bible 2010 Edition: Boot Up to Ubuntu, Fedora, KNOPPIX, Debian, openSUSE, and 13 Other Distributions, by Christopher Negus, Wiley, 2009, {{ISBN|978-0-470-48505-7}}, p.775 The latter class of functions include routines for constructing and manipulating keymaps, an interactive line-editing facility, and both low- and high-level screen/terminal management functions. It is distributed under the terms of the GNU General Public License.

Brief history

The S-Lang programming library was started in 1992 by John E. Davis, considering that functions he wrote for a text editor might be useful in other programs.{{cite web |url=http://www.jedsoft.org/slang/doc/html/slang-1.html#ss1.1 |title=A Brief History of S-Lang |accessdate=June 6, 2017}} The earliest version of the library contained input/output routines for interacting with computer terminals and an implementation of a simple stack-based interpreter with a PostScript-like syntax that he developed for use in a scientific plotting program. The JED text editor was the first program to both embed the interpreter and use the terminal I/O components of the library.

Interpreter

The interpreter makes up most of the S-Lang library, and is also where most of the development takes place. Although the original syntax supported by the interpreter resembled PostScript, the syntax has evolved to be much more C-like, with additional support for object-oriented style constructs. As a reflection of Davis's background in physics and professional interest in scientific computing, the language natively supports many vectorized array-based operations similar to MATLAB and IDL.Getting more from your multicore: exploiting OpenMP from an open-source numerical scripting language, Noble, M. S., Concurrency and Computation: Practice and Experience

Volume 20, Issue 16, pages 1877–1891, 2008, doi: 10.1002/cpe.1296

Until version 2.0, the interpreter was not a standalone program. Instead, Davis advocated embedding it into applications to make them extensible. Using the interpreter meant either embedding it in a C program, or using it in the context of another application (e.g., the JED editor). The S-Lang shell, slsh, was a demonstration program capable of little more than running scripts. Version 2.0, released in 2005, made slsh interactive, and it has evolved into an application in its own right, with a number of external modules for use by it. As such, it has become the S-Lang interpreter.

Screen management

In the mid-1990s while porting the sc spreadsheet to the S-Lang library, Davis developed the library's screen management facility.{{citation needed|date=October 2017}} This component was designed to optimize screen output (by minimizing the number of characters sent to the terminal), and provide a simple way to support a variety of terminals through an extra layer of abstraction between the application code and the terminal. The slrn newsreader was the first application to make full use of this interface.{{citation needed|date=October 2017}} Since then, a number of other programs (e.g., Mutt{{Cite web

|url=http://web.mit.edu/ghudson/dev/nsanch/balsa-1.2.pre2/libmutt/INSTALL

|title=Mutt install guide

|accessdate=2015-10-04

}}) have taken advantage of this feature of the library, and it has become arguably the most used aspect of the library, as this component is considered to be an alternative to curses.MySQL Developer's Library, by Paul Dubois, Pearson Education, 2009, {{ISBN|9780672329388}}, section 6.1Linux application development, by Michael K. Johnson and Erik W. Troan, Addison-Wesley, 2005, {{ISBN|9780321219145}}, p513 Since version 2.0, the screen management routines have had transparent support for UTF-8.

Example source code

  1. ! /usr/bin/env slsh

% The program below solves the following problem:

% Sort an input file that consists of lines like this

%

% var1=23 other=14 ditto=23 fred=2

private variable Keys, Values;

private define sort_fun (i, j)

{

variable s, a, b;

s = Values[i] - Values[j];

!if (s)

return strcmp (Keys[i], Keys[j]);

return s;

}

define slsh_main ()

{

variable line, len, i, vals;

foreach line (stdin)

{

% Split string into an array of strings %

% by using white chars and = as delimite

%

line = strtok (line, " \t\n=");

len = length(line)/2;

if (len == 0)

continue;

% Even elements are keys, odd are values

% The [0::2] is an array containing indexes with a 2 specifying step

% and creating indexes from 0 to the length(line)

Keys = line0::2;

vals = line1::2;

% The variable is declared above

Values = atoi (vals);

i = array_sort ([0:len-1], &sort_fun);

% There are different ways of writing the result. Here is a

% fast way that avoids a loop.

% The empty parenthesis () denote variable declaration and specifies

% that return value should be discarded

() = printf ("%s\n", strjoin (Keys[i] + "=" + vals[i], " "));

}

}

See also

{{Portal|Free and open-source software}}

References

{{Reflist}}