www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/09/13/16:25:00

Date: Tue, 13 Sep 1994 12:38:46 -0400
From: davis AT amy DOT tch DOT harvard DOT edu ("John E. Davis")
To: djgpp AT sun DOT soe DOT clarkson DOT edu, sands AT clipper DOT ens DOT fr
Subject: RE: User defined functions

>In any case I'm sure someone must have already had this "user defined
>function problem" and solved it better than I ever could.
>
>Does anybody know how to do this or what I should be doing?

   (Note: availablility of program is listed at the end of the email.
   Briefly, it is freeware available via ftp from amy.tch.harvard.edu)
   
Have you looked at S-Lang?  S-Lang is a C-like embedded interpreter and
programmers library.  S-Lang runs on VMS, OS/2, MSDOS, and Unix.  For your
purposes, it compiles just fine usig DJGPP (makefile.djg).

By C-Like I mean that a user can defined things like:

    define something_silly (n, x)
    {
       variable sum = 0, i, imax;
       
       if (n < 0) error ("n is invalid.");
       
       imax = compute_imax (n, x);
       for (i = 0; i < max; i++)
         {
	    sum += another_function (n, x);
	    n++;
	 }
       while (n > 0) sum -= sum / n;
       return sum;
    }
    
This silly function is designed to illustrate S-Lang's syntax.
Here is a simple C program that embeds S-Lang and reads in a file, 'test.sl'
that may contain functions like the above.

------------------------------------------------------------
#include <stdio.h>
#include "slang.h"

void my_error (char *s) {
  fputs (stderr, s);
  SLang_Error = INTRINSIC_ERROR;
}

SLang_Name_Type slang_function_table[] = {
	MAKE_INTRINSIC (".error", my_error, VOID_TYPE, 1),
	SLANG_END_TABLE
};

int main (void) {
  if (!init_SLang() || !init_SLmath()
      || !init_SLunix() || !init_SLfiles()) 
    {
        my_error ("Unable to initialize S-Lang.");
	return (1);
    }
  SLang_add_table (slang_function_table, "my_table");
  SLang_load_file ("test.sl");
  return SLang_Error;
}
------------------------------------------------------------
There, in less than 20 lines, you have a program that 

   1.  embeds a C-like language interpreter 
   2.  declares an intrinsic function 'error' to the interpreter.
   3.  loads a file and executes ``commands'' in the file.
   
As I said earlier, S-Lang is also a programmer's library.  In fact, S-Lang
also has functions for:

    1.  Low level keyboard I/O
    2.  A GNU-Like readline facility
    3.  Screen management facility that supports colors and, in my opinion,
        outperforms (n)curses.  For example, it knows how to scroll the
	screen intelligently.
    4.  Easy support for keymaps.
    5.  A new ``VMS-like'' help facility.  I am now documenting all of the
	library using this form of help.
    6.  Regular expression and searching functions

   and more...

The beauty of all of this is that it is system independent.  The same
function call works across all platforms that S-Lang supports (MSDOS, OS/2,
VMS, and Unix).

S-Lang is freeware and is available from amy.tch.harvard.edu in pub/slang.
Also available on that machine are the following programs that embed parts
of the S-Lang library:

   slrn:  NNTP based newsreader resembling GNUS.  It is still under
          development but it is quite usable.  I use nothing else.  It uses
	  S-Lang for searching, screen management, readline, and keymaps.
	  
   slsc:  The public domain sc spreadsheet program with an Emacs-like
          interface, user definable keymaps, color, VMS-help, and more.
	  
   jed:   My editor.  It is feels like emacs, embeds S-Lang as an extension
          language ==> C-like extension language, color syntax highlighting
	  in TeX, C, and Fortran modes, and much much more.  It runs on all
	  systems that S-Lang supports.
	  
Again, this is freeware and can be used in commercial applications.  All I
ask is that changes to S-Lang be sent back to me for incorporation into
future versions of S-Lang so that others can benefit.

Enjoy.
--John
  

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019