Author Topic: S-Lang  (Read 3194 times)

JRS

  • Guest
S-Lang
« on: December 05, 2010, 04:07:57 PM »
Quote from: Home Page
S-Lang is a multi-platform programmer's library designed to allow a developer to create robust multi-platform software. It provides facilities required by interactive applications such as display/screen management, keyboard input, keymaps, and so on. The most exciting feature of the library is the slang interpreter that may be easily embedded into a program to make it extensible. While the emphasis has always been on the embedded nature of the interpreter, it may also be used in a stand-alone fashion through the use of slsh, which is part of the S-Lang distribution.

Unlike many interpreters, the S-Lang interpreter supports all of the native C integer types (signed and unsigned versions of char, short, int, long, and long long), and both single and double precision types, as well as a double precision complex type. Other data types supported by the interpreter include strings, lists, associative arrays (hashes), user-defined structures, and multi-dimensional arrays of any data-type.

The S-Lang interpreter has very strong support for array-based operations making it ideal for numerical applications. For example,

    i = where (hypot(X,Y) <= 1);
    X = X;
    Y = Y;

is a filtering operation that removes all points from a pair of (X,Y) arrays that fall outside the unit circle. Moreover, the native support for array-based operations mean that such code will execute at the speed of compiled code even though the code is executed by the interpreter.

I really like the fxtopng S-Lang program that someone contributed and the cool scripts you can feed it.

Code: Text
  1.  define f_of_z (z)
  2.  {
  3.     z + z^2/sin(z^4-1);
  4.  }
  5.  define set_options (prefs)
  6.  {
  7.     prefs.xgrid = [-1.5:1.5:#384];
  8.     prefs.ygrid = [-1.5:1.5:#384];
  9.     prefs.iter = 3;
  10.  }
  11.  

The following console command creates this image. (frac.png)

jrs@Laptop:~/S-Lang$ ./fztopng frac.sl





AIR

  • Guest
Re: S-Lang
« Reply #1 on: December 05, 2010, 07:01:48 PM »
Interesting, that's very "C"-like.

What's the speed like?

JRS

  • Guest
Re: S-Lang
« Reply #2 on: December 05, 2010, 07:06:25 PM »
S-Lang is an embeddable interpreter with a interface similar to GTK-Server. (one call wonder) It might be fun and useful to create an SB extension module for S-Lang as well. SB isn't a barn burner with arrays at the script level and S-Lang has it's own strengths that may complement SB with enhanced math/array/graphics capabilities. (has it's own set of binding to libraries)

I would be interested in any feedback from those that have worked with S-Lang (Peter ?) and your thoughts about embedding it as a scripting tool.

JRS

  • Guest
Re: S-Lang
« Reply #3 on: December 05, 2010, 07:12:41 PM »
Quote
What's the speed like?

I see no performance issues with the little I've worked with it. It generates very complex PNG files amazingly fast.

I just installed slsh (and a few add-on goodies) using the Ubuntu Synaptic Package Installer and was able to run the example scripts off their site without a problem.


JRS

  • Guest
Re: S-Lang
« Reply #4 on: December 07, 2010, 01:28:18 AM »
Here is your standard GTK-Server demo in S-Lang. (FIFO Interface)

Code: [Select]
%
% Tested with S-Lang 1.4.9 on Slackware 10 --- http://www.s-lang.org/
%
% Feb 26, 2005 - PvE.
% Revised for GTK-server 2.0.6 at december 17, 2005
% Tested with S-Lang 2.1.4 and GTK-server 2.3.1 at december 17, 2008.
%
%--------------------------------------------------------------------

define gtk(str)
{
    variable fp, buf;

    fp = fopen ("/tmp/demo.sl", "a");
    () = fputs (str, fp);
    () = fclose (fp);

    fp = fopen ("/tmp/demo.sl", "r");
    () = fgets (&buf, fp);
    () = fclose (fp);

    return buf;
}

% Declare variables
variable WIN, TBL, BUT, LAB, EVENT;

% Start GTK-server and wait for initialization
() = system ("gtk-server -fifo=/tmp/demo.sl -detach");

% Build GUI
() = gtk ("gtk_init NULL NULL");
WIN = gtk ("gtk_window_new 0");
() = gtk ("gtk_widget_set_usize " + WIN + " 300 100");
() = gtk ("gtk_window_set_title " + WIN + " \"S-Lang with GTK\"");
() = gtk ("gtk_window_set_position " + WIN + " 1");
TBL = gtk ("gtk_table_new 20 20 1");
() = gtk ("gtk_container_add " + WIN + " " + TBL);
BUT = gtk ("gtk_button_new_with_label \"Click to Quit\"");
() = gtk ("gtk_table_attach_defaults " + TBL + " " + BUT + " 12 19 12 19");
LAB = gtk ("gtk_label_new \"S-Lang uses GTK now!!\"");
() = gtk ("gtk_table_attach_defaults " + TBL + " " + LAB + " 1 15 1 10");
() = gtk ("gtk_widget_show_all " + WIN);

% Mainloop
do {
    EVENT = gtk("gtk_server_callback wait");
} while (EVENT != BUT and EVENT != WIN);

% Exit GTK-server
() = gtk ("gtk_server_exit");

% Exit
exit (0);

* Requires standalone GTK-Server
« Last Edit: December 07, 2010, 02:57:02 AM by JRS »