5. An example of Gamma code

Gamma is an implementation of a loadable grammar for SCADALisp. It provides a C-like programming interface to all of the SCADALisp functionality. There is no run-time cost penalty associated with using Gamma instead of SCADALisp. A Gamma program can take advantage of any Lisp code, as it maintains the Lisp parser and writer. Functions that are difficult or impossible to create in Gamma can be written in Lisp and included into the Gamma program, however many people find Gamma far easier to understand than Lisp. For example:

Lisp code:

    ;;; A particularly nasty-looking Lisp function which loops to print
    ;;; some numbers, while creating a list of the squares of the numbers.
    
    	(defun print-nums (start end)
    	  (let (square-list square)
    	    (do ((i start (+ i 1)))
    	        ((>= i end) (reverse square-list))
    	        (setq square (* i i))
    	        (princ "Number: " i ", Square: " square "\n")
    	        (setq square-list (cons square square-list))
    	        )
    	    )
    	  )

Gamma code:

    /* A not-so-nasty-looking Gamma loop to print some numbers while
       creating a list of the squares. */
    
    	function print-nums (start, end)
    	{
    	    local	square-list, square, i;
    
    	    for (i=start; i<end; i++)
    	    {
    	        square = i * i;
    	        princ ("Number: ", i, ", Square: ", square, "\n");
    	        square-list = cons (square, square-list);
    	    }
    	    reverse (square-list);
    	}

Note that Gamma inherits data abstraction and symbols with embedded '-', and '*' from Lisp. Gamma also supports all of the data types found in SCADALisp, including lists and arrays.

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.