        
                                                                 <Page No.   1>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||                                                                    ||
       ||                                                                    ||
       ||                    The SAM76 and LISP languages                    ||
       ||                                                                    ||
       ||                        A comparative study                         ||
       ||                                                                    ||
       ||                                                                    ||
       ||                       Technical Note No. 17                        ||
       ||                                                                    ||
       ||                                                                    ||
       ||                                                                    ||
       ||                         Claude A. R. Kagan                         ||
       ||                                                                    ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
       
                                       CONTENTS                                
       
       
         2      Notes and Notices
         2      Copyright 1986, SAM76 Inc., Pennington, N. J.
         3      INTRODUCTION
         7      Notation and other operating characteristics
        11      THE CHARACTER SET
        13      Arithmetic Functions
        14      Number System and Radix control in LISP and SAM76
        16      Use of PRINT - (os) "output string",
                READ - (is) "input string",|and EQUAL - (ii) "if identical"
        17      LISP BASIC PRIMITIVE FUNCTIONS
        17      Taking Lists Apart - LISP CAR and CDR
        18      SAM76 Extracts or Fetches elements or arguments
        21      Putting Things Together,   LISP - CONS, APPEND and LIST
        22      Concatenation mechanism in SAM76 language
        24      THE EVALUATION PROCESS - LISP and SAM76
        27      String Manipulation - LISP CONS and REMOVE
        28      Equality and Comparison Predicate functions in LISP and SAM76
        30      Function Definition, Viewing Defined Functions, and Parameters
        31      Factorial function - (Recursive)
        32      Towers of HANOI - (Recursive)
        33      Memory management of "texts," "forms," and variables
        35      Interaction with system files
        37      Some Additional Features which may not exist in LISP
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||                  Preliminary Draft - August 1986                   ||
       ||                                                                    ||
        ______________________________________________________________________ 
               
                                                                 <Page No.   2>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||                         Notes and Notices                          ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
       
       The versions of the LISP and SAM76 language implementations experimented
       with are identified in the following list:
       
       
       Language        Producer                        System Size  Graphics
       
       
       WALTZ LISP      ProCode International           CP/M    24K
       WALTZ LISP      ProCode International           MSDOS   34K
       COMMON LISP     Gold Hill Computers             MSDOS  147K   hires     
       LeLISP          ACT Informatique                MSDOS  256K   hires
       SAM76           SAM76 Inc.                      CP/M    16K   hires
       SAM76           SAM76 Inc.                      MSDOS   20K   hires
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
               
                                                                 <Page No.   3>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||                            INTRODUCTION                            ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
       
       The  purpose of this exposition is to provide a comparative study of the
       languages  LISP  and  SAM76. In addition this study provides a series of
       comparisons   of  functionally  equivalent  LISP  "programs"  and  SAM76
       Language  "scripts"  to give the user of either language an insight into
       the  other.  Attempt  was made to show the best possible solution to the
       problem solved in each example. The execution of the examples in each of
       the  two  languages may not always result in absolutely identical visual
       presentations.  In  general this is due to the fact that additional code
       is  required  in the LISP programs merely to enhance the presentation of
       output, and it was felt that burdening the LISP code with extra elements
       would  detract  from an understanding of the underlying algorithms being
       demonstrated.
       
       
       It  is  also recognized that both languages are extensible, both insofar
       as built-in or primitive functions are concerned, as well as in the form
       of  user  defined  functions,  programs  or  scripts.  Consequently  the
       presence  or  absence of particular functions in one or the other of the
       two  languages  will not be viewed as being a "plus" or a "minus". There
       are   cases,  however,  where  the  absence  of  certain  primitives  or
       functionalities make the use of the language awkward at best. These will
       be noted where appropriate.
       
       
       Definitions and examples of both LISP and SAM76 language expressions and
       "scripts"  or  "programs"  were  obtained  or  derived from a variety of
       sources:
       
       
       LISP References
       
       1.      Winston & Van Horn, "LISP," second edition - 1985
       2.      SAN MARCO Explorer
       3.      Howorka, Ed "WALTZ Lisp {pc6300 and cp/m}", ProCode 1985
       4.      Golden Hill Computers " Golden Common Lisp" 1985
       5.      Steele, Guy L. Jr., "Common Lisp Ref. Man" 1984
       6.      Gloess, P.Y., "Understanding LISP" ALFRED, 1982
       7.      Foderaro, John, "FRANZ LISP {unix vax}", 1981
       8.      Betz, David, "XLISP {unix vax}", 1985
       
       
       SAM76 References
       
       1.  Kagan, C.A.R., "Neutral Implied ... ", ACM SIGPLAN 1969
       2.  Kagan, C.A.R., "String Proc. for Sm. Mach." ACM Symp. 1970
       3.  Kagan, C.A.R., "Multigap Function ... " ACM SIGPLAN 1972
       4.  Kagan, C.A.R. "The SAM76 Language," IEEE 1976, and Dr. Dobbs 1977
       5.  Roichel (& al.), "SAM76 Language Manual, 2nd. Ed."
       6.  Kagan, C.A.R. "SAM76 Language," Mc Graw Hill Encyclopedia 1985
       
               
                                                                 <Page No.   4>
       ------------------------------------------------------------------------
       
       
       
       Other useful and interesting References
       
       1.      Bobrow,  Daniel G. "Symbol manipulation languages and techniques
       -  Proceedings  of  the  IFIP  (1966)  conference on Symbol Manipulation
       Languages." North Holland Publishing Company, 1971.
       
       
       2.      Eastwood,  D.  E., and McIlroy, "Macro compiler modifications of
       SAP." Bell Telephone Laboratories 1959.
       
       
       3.      Strachey,   C.  "A  general  purpose  macrogenerator,"  Computer
       Journal 1965, Page 225.
       
       
       4.      Church,  Alonzo,  "The  calculi of Lambda conversion," Princeton
       University Press, Princeton 1941.
       
       
       6.      Knowlton,  K. "A programmer's description of L6." Bell Telephone
       Laboratories, and CACM Volume 9 No. 8, 1966.
       
       
       7.      Gimpel, Jim, "Algorithms in SNOBOL4." xxx.
       
               
                                                                 <Page No.   5>
       ------------------------------------------------------------------------
       
       
                                                        ______________________ 
       The  factor  that was the primary influence in  ||                    ||
       the  preparation  of this study was the desire  ||     Motivation     ||
       of the author, the main developer of the SAM76  ||  Acknowledgements  ||
       language    to  learn,  thoroughly understand,  ||                    ||
                                                        ______________________ 
       and  use the LISP language. The thoughtful and                          
       careful  review  of a number of LISP experts was required to enhance the
       accuracy  and  fairness  of  the  author's  statements  and opinions: Ed
       Howorka,   Jay   Yusko,   ...   
       
        ______________________                                                 
       ||                    ||  The  fundamental  difference between these two
       ||   SAM76 and LISP   ||  languages   relates   to  the  view  of  their
       ||                    ||
        ______________________   strings.  In  SAM76  the  strings  are  at the
                                 "object" or "literal string" level, whereas in
       LISP  any  string  (unless possibly a "quoted" one) is a variable; it is
       either  the  name  of an object already in storage or to be subsequently
       defined. These two types of variables are "free" and "bound". The quoted
       string   is   a   special   case.   
       
       
       Another  major  difference  is  that  the evaluation of a SAM76 language
       expression  is  not  undertaken until all the internal strings have been
       scanned  and  evaluated.  The parsing sequence within an expression does
       not  depend  upon  the  function identified in the first argument of the
       expression. In LISP, on the other hand, it would appear that the parsing
       process  within  an  expression  depends upon what is found in the first
       atomic symbol of the expression.
       
       
       Treatment  of  the  null  string  appears  to  be much more rational and
       logical  in  the  SAM76 language than it does in LISP. At first it would
       appear to the language designer  that treating "nothing" in a consistent
       and  rational matter is very simple; that is not the case because of the
       variety  of  "nothings" that one may encounter in a variety of contexts.
       The  basic  rule  in SAM76 is that the null string is a string of length
       zero.  That  means  that  one can quite properly create a variable whose
       name is the "null string", ie.: a name of zero length.
       
       
       The  second  consistent  rule  regarding  the  null  string in the SAM76
       language  states  that omitted arguments of an expression have the value
       of the null string, regardless of their position in the argument list.
       
       
       The  third  consistent  rule  relates  to  the use of the null string in
       arithmetic  expressions,  or  in  arguments  which  are  expected  to be
       numbers. In that case the null string is regarded as having the value of
       a single numeric zero.
       
               
                                                                 <Page No.   6>
       ------------------------------------------------------------------------
       
       
       
       The  foregoing  should  be contrasted with the treatment of "nothing" in
       LISP, and then one notes that this treatment would appear to change with
       the  opinions of the various authors or implementers. Is NIL a character
       string,  an atom, a name, a null list; is it equivalent to the character
       string  FALSE  or  perhaps  does  it mean a false situation in a logical
       predicate;  does NIL represent some of these or all of these, or is this
       author particularly obtuse or simple minded?
       
       
       Other  differences in the philosophy of handling the strings which would
       appear  a  priori  to make the SAM76 language considerably more flexible
       than LISP, will be noted in the detailed discussions that follows.
       
               
                                                                 <Page No.   7>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||            Notation and other operating characteristics            ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
                                                        ______________________ 
       Both   LISP   and   the   SAM76  language  are  ||                    ||
       interactive.  That  is  to say the user enters  ||  USER INTERACTION  ||
       symbols  using  a keyboard and upon receipt of  ||                    ||
                                                        ______________________ 
       an  explicit  signal  the  language  processor                          
       takes  over  and  proceeds  to  examine  and act on the user input. This
       process  is  known as scanning and evaluation. The signal used by GOLDEN
       COMMON  LISP  is  the  recognition  that  a closing parenthesis has been
       entered  which balances precisely the first opening parenthesis that had
       been  entered  earlier.  This  "grabbing"  away control from the user is
       sometimes disconcerting in that it makes it difficult to suddenly have a
       change   of   mind   about   that   last   closing   paren.   
       
       
       The  signal used by WALTZ and FRANZ LISP is the carriage return which is
       convenient, but makes it difficult to enter that character in the symbol
       stream.
       
        ______________________                                                 
       ||                    ||  There are several signals which may be used by
       ||  SAM76 ACTIVATOR   ||  the SAM76 language to indicate the end of user
       ||                    ||
        ______________________   input  of  strings  of arbitrary or stipulated
                                 length:                                       
       The  most common signal is the "activating character", the default being
       an  equal  sign. This "activating character" may be changed at any time,
       either  by  the  user  or during the actual evaluation of SAM76 scripts.
       This is done through the use of a built-in primitive "Change Activator",
       the   mnemonic   for   which   is   "ca".   
       
       
       A  second method available is through the use of an input function which
       specifies  the  precise number of characters which must be entered. When
       that  number of symbols has been entered, then control is assumed by the
       language processor.
       
       
       A  third  method available is through the use of an input function which
       specifies  an  arbitrary  number  of  strings, the receipt of any one of
       these  strings  by  the  language processor becomes the signal for it to
       take over.
       
       
       A  fourth  method  is by presetting with an appropriate function a timer
       which  is started the moment an input function is recognized. Control is
       assumed  by  the  language  processor at the end of the preset amount of
       time, regardless of the amount of input actually received.
       
               
                                                                 <Page No.   8>
       ------------------------------------------------------------------------
       
       
                                                        ______________________ 
       Generally the SAM76 implementations do not, in  ||                    ||
       the  default case, provide a visible prompt to  ||    User PROMPTS    ||
       the  user other than a neat return to the next  ||                    ||
                                                        ______________________ 
       line.  The  knowledgeable  SAM76 language user                          
       knows  when  it  is his turn to "talk" to the language processor. On the
       other  hand  various  LISP  implementations do in fact provide a visible
       prompt,  asterisk  followed  by  a space in some cases, other symbols in
       other  cases.  Prompts  may  be shown in the LISP interactions described
       later.   
       
                                                        ______________________ 
       LISP  provides  only  one  type of boundary to  ||                    ||
       delineate  the  scope of lists or expressions.  ||Lists & Expressions ||
       This  type  consists  of  a  matched  pair  of  ||                    ||
                                                        ______________________ 
       parentheses   as   illustrated   below.   The                           
       elements,  or  arguments of the lists so bounded are separated by "white
       space",  namely  "space"  where  several  adjacent  spaces have the same
       impact  as  only  one  space,  or  "tabs" and also "new lines" sometimes
       refered   to   as   "line   feeds".   
       
       
       The functionality or purpose of this single type of boundary is extended
       through  the  use  of characters which are reserved for that purpose and
       may  be  placed either immediately in front of an open parentheses or in
       the symbol stream itself.
       
       
       The  SAM76  language,  on  the  other  hand  provides  several  types of
       boundaries for expressions or lists. These are also viewed as pairs, the
       left  one being a signal to start a list or expression, and the matching
       right hand one identifying the end of that list or expression.
       
       
       Elements  or  arguments  in SAM76 language scripts are usually separated
       from  each  other  by  single  commas. White spaces, which are viewed as
       separators in LISP, are treated as legitimate characters or symbols.
       
       
       LISP                                    SAM76
       
       (THIS IS A LISP LIST)                   ,this,is,a,sam76,list
       
       '(THIS IS A QUOTED LIST)                !,protected,list/
                                               (,protected,list)
                                               <,protected,list>
                                               ),protected,list(
                                               >,protected,list<
       
                                               &neutral,with,a,list/
                                               %active,with,a,list/
       
       
       The  various  types  of  SAM76 language lists and functional expressions
       shown  above  may be nested or placed in other lists in exactly the same
       manner as done when using LISP.
       
               
                                                                 <Page No.   9>
       ------------------------------------------------------------------------
       
       
                                                        ______________________ 
       There  exists  in  LISP  a  formal distinction  ||                    ||
       between LISTS, ATOMS, SYMBOLS and NUMBERS, and  ||    Lists, Atoms    ||
       misapplication  of  these  objects  in various  ||Symbols and Numbers ||
       functions will cause a variety of errors to be  ||                    ||
                                                        ______________________ 
       indicated.   For  instance  (SETQ  5  'HOUSE),                          
       namely  attempting  to  assign to a name "5", the quoted string HOUSE is
       not permitted since "5" is by definition only usable as a number and not
       a   symbol.   
       
       
       On  the  other  hand  the  SAM76  language does not make any such formal
       distinction except in the manner in which various functions act on these
       objects,  attempting to handle them in a manner contextually appropriate
       for  the function in which the object is used. It is therefore permitted
       to  assign  to  the  name "5" the string HOUSE: %dt,5,HOUSE/=, where the
       mnemonic "dt" invokes the "define text" primitive.
       
       
       For  instance a number used as an element of a function designed to deal
       with symbols will be viewed as a symbol. Conversely a symbol found as an
       element  of  an  arithmetic  function will, by definition be viewed as a
       number of value numeric zero.
       
       
       A  list will be viewed in the SAM76 language as a list only when used as
       part of a function which expects to deal with lists and only that number
       of  elements  from  the head (or left) end of the list that the function
       actually  requires.  If  the  list  does not contain as many elements or
       arguments  that  the function requires, then the balance of the required
       arguments will be provided in the form of "null strings".
       
       
       This  difference of philosophy between LISP and the SAM76 language has a
       profound  effect  on  the  manner  in  which "programs" or "scripts" are
       written:
       
                               SAM76                   LISP
       
       
       Assign to "x" a list    %dt,x,!,5,6//=          (SETQ X '(5 6))
       
       Add contents of list    %ad%x//=11              (+ x)
                                                       (5 6)
       
       
       The  problem seen above in the LISP version is easily solved by defining
       in LISP a new function "ad" as follows:
       
                                       (DEFUN AD (X)
                                       (+ (CAR X) (CAR (CDR X))))
                                       (AD X)
                                       11
       
       This  function  will  not,  however  accept pairs of numbers in the same
       manner as the primitive LISP "+". A more complicated definition for "ad"
       could  be  written which would test the parameters to see if they were a
       list  or  numbers,  and based on the test results select the appropriate
       mode of performing the addition.
       
               
                                                                 <Page No.  10>
       ------------------------------------------------------------------------
       
       
       
       The   foregoing  discussion  serves  to  highlight  another  fundamental
       difference  between  LISP  and the SAM76 language, namely the meaning or
       value  of  atoms.  In LISP atoms may be either SYMBOLS (as A, XYZ, HOUSE
       &c.)  or  NUMBERS  (as  5,  2, 137). The value of a number is the number
       itself. The value of a symbol is that which it was defined to be. When a
       symbol  or  a  list  in  LISP  are not to be evaluated then they must be
       quoted by an immediately preceding apostrophe (eg: 'A, 'XYZ, 'HOUSE).
       
       
       Since  the  SAM76  language  does  not  distinguish  between numbers and
       symbols, merely accepting them at their face value, atoms whose value is
       desired  rather than the characters which form the atom, are enfolded in
       what  one  might loosely call an invocation pair: %A/, %XYZ/, %HOUSE/ or
       even %5/, %2/ and %137/. This is illustrated below:
       
       
       LISP                                    SAM76
       
       '(THIS IS TEXT)                         THIS IS TEXT
       (+ 5 6)                                 %ad,5,6/
       (+ '5 '6)                               %ad,5,6/
       (SETQ XYZ 5)                            %dt,xyz,5/
       (+ XYZ 6)                               %ad,%xyz/,6/
       (SETQ HOUSE 6)                          %dt,house,6/
       (+ XYZ HOUSE)                           %ad,%xyz/,%house//
       
       All  of  the  mathematical  expressions  above  yield  the same value or
       result, namely 11.
       
                                                        ______________________ 
       The  concept  of  the "Null String" is handled  ||                    ||
       somewhat  differently in LISP and in the SAM76  ||  The Null String   ||
       language.  In  LISP  the list "()" is known as  ||                    ||
                                                        ______________________ 
       "NIL".  This  is sometimes returned as a value                          
       from some evaluation process. Predicates of the LISP language may return
       the letter "T" (or some actual value) for true, and "NIL" for false. The
       "NIL" may not be used as the name of a function or list, and it does not
       have   a   numeric   value.   
       
       
       In  the  SAM76  language the "null string" is viewed as a string of zero
       length   which   in  the  case  of  arithmetic  functions  acquires,  by
       definition, the value of numeric zero. In the expression: %ad,,5/, there
       is  an  explicit  null  string  between the two adjacent commas, and the
       value  of  that  null string, being in a numeric expression, is zero and
       consequently  the  result of evaluating that expression is "5". Likewise
       omission of arguments are implicit definitions that these arguments have
       the value of the null string.
       
               
                                                                 <Page No.  11>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||                         THE CHARACTER SET                          ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
                                                        ______________________ 
       There  are  a  number  of different methods in  ||                    ||
       which  the  character  set is defined and used  ||    COMMON LISP     ||
       among the variety of LISP implementations. For  ||                    ||
                                                        ______________________ 
       practical  purposes  only the definition given                          
       for   COMMON   LISP,   (LISP   reference  No.  5)  will  be  considered.  
       
       
       The  COMMON  LISP  standard  character  set  consists of the ninety-four
       printing  characters  of  the USASCII code plus the non printing "space"
       character  and  the format effector code for "new-line". The "delete" or
       "rubout" code is not included.
       
       
       Internally  to  the  operation of the COMMON LISP system, the "new-line"
       code  is  that  which  corresponds  to  the  USASCII  control  code  for
       "line-feed".  The  code  for  "carriage-return"  is  processed variously
       according to the desires of the implementors.
       
       
       Of the ninety-four non-blank printing characters, the following are used
       in only limited ways in the syntax of COMMON LISP programs:
       
               [ ] { } ? ! ^ _ ~ $ %
       
       
       All  of these characters except ! and _ are used within "format" strings
       as  formatting directives. Except for this, [ ] { } ? and ! are not used
       in  COMMON LISP and are reserved to the user for syntactic extensions; ^
       and  _  are  not  yet used in COMMON LISP, but are part of the syntax of
       reserved tokens, and are reserved for implementors; ~ is not yet used in
       COMMON  LISP,  and is reserved to implementors; and $ and % are normally
       regarded  as alphabetic characters, but are not used in the names of any
       standard COMMON LISP functions, variables, or other entities.
       
       
       Characters  may  be  symbolically  notated by writing #\ followed by the
       character  itself. Non printing characters have names and can be notated
       by  writing  #\  and  then the name; for example #\space means the space
       character.
       
       The following characters are standard:
       
                #\space  #\newline
       
       The following characters are called "semi-standard":
       
                #\backspace  #\tab  #\linefeed  #\page  #\return  #\rubout
       
               
                                                                 <Page No.  12>
       ------------------------------------------------------------------------
       
       
                                                        ______________________ 
       The  SAM76  character  set  consist of all 128  ||                    ||
       USASCII  codes, that is to say the ninety-four  ||       SAM76        ||
       printing   characters,   the   "space",   the   ||                    ||
                                                        ______________________ 
       "rubout",  and  the  thirty-two  control codes                          
       which  include the various format effectors such as "newline", "tab" &c. 
       
       
       Of  the ninety-four non-blank printing characters the following "warning
       characters" are used in the syntax of SAM76 language programs:
       
               % & ! # : ; ( ) < > [ ] / , @ `
       
       There  is  a  primitive  function  which  permits  reassignment  of  the
       syntactic  function  performed  by  the  foregoing  characters to a user
       defined set of his own choosing.
       
       
       In  addition  to the character set which the user, or user's program can
       directly  enter into the SAM76 language processor input stream there are
       some  internal  "super" and "multi" characters which are created through
       the  use  of  certain primitive functions and which serve as markers for
       the  passing  of parameters. These may be seen in displayed form through
       the  use of the (vt) "View Text" function or some user defined procedure
       which  will provide identifiable parameters when the function containing
       these markers is invoked.
       
       
       Super  characters (also known as partitions) are created through the use
       of  the  (pt) "partition text" and (sc) "super character" functions. The
       (vt)  "view  text" function displays them as a number of arbitrary range
       enfolded by square brackets:
       
       
               %dt,x,%sc,47//=         ;defining "x" as part. 47
               %dt,y,abcdefg/=         ;defining a text named "y"
               %pt,y,,,ab,,ef/=        ;creating partitions 2 & 4
       
               %vt,x/=[47]             ;viewing text named "x"
               %vt,y/=[2]cd[4]g        ;viewing text named "y"
       
       
       In  a  similar  manner multi characters (also known as multi partitions)
       are created through the use of the (mt) "multipart text" and (mc) "multi
       character"  functions.  The  (vt)  "view  text function display these as
       numbers  with  a  preceding  #  sign  enfolded  between a pair of square
       brackets.
       
        ______________________                                                 
       ||                    ||  The  philosophy  as  to  the  treatment of the
       ||    NEWLINE CODE    ||  "newline"  code  is identical in SAM76 to that
       ||                    ||
        ______________________   espoused  by  COMMON LISP. The only difference
                                 is  that this code is not explicitly viewed as
       a  syntactic argument or element separator. The "return" code is treated
       by  SAM76  as  just  that, permitting overstrikes and underlines of text
       strings.   
       
               
                                                                 <Page No.  13>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||                        Arithmetic Functions                        ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
       
       Function                SAM76                   LISP
       
       
       Addition                %ad,5,5/=10             (+ 5 5)
                                                       10
       
       
       Subtraction             %su,6,2/=4              (- 6 2)
                                                       4
       
       
       Multiplication          %mu,3,7/=21             (* 3 7)
                                                       21
       
       
       Division                %di,48,6/=8             (/ 48 6)
                                                       8
       
         a. omitting argument  %di,2/={null}           (/ 2)
            as in Waltz Lisp                           2
       
         b. omitted argument   %di,2,,xxx/=xxx         (/ 2)
            as in WINSTON                              0.5
       
         c. divide by zero     %di,2,0,xyz/=xyz        (/ 2 0)
                                                       ;Eval Error
       
       
       COMMENTS:
       
       It  would  appear  that  the matter of omitted arguments and the special
       case  of  division  by  zero  is  handled  variously  by  different LISP
       implementations.
       
       In  the  case of the SAM76 implementation the basic rule about arguments
       is  that  omitted  arguments have the value of the "null string", AND in
       the execution of arithmetic functions the "null string" has the value of
       a  numeric  zero. With respect to the SAM76 language "division" function
       there  is  an  explicit  possibility  of  one  additional argument which
       becomes  the  value  in  the  special  case of division by zero. If this
       argument  is  omitted then a divide by zero yields a "null string" which
       may  be  tested  by  the user program and thus identifies the condition.
       Alternatively  if  this  argument  is  specified,  then the value of the
       expression  is  that  argument which in turn may be a procedure or other
       signal that the user may desire.
       
       
       The  disadvantage  of  this  particular  way  of  defining  the division
       function in the SAM76 language is that it precludes the possibility of a
       continuing  list  of  divisors  as  in  LISP:  (/ 96 2 6 ... ).  This is
       solvable  in SAM76 by using a different definition of division where the
       special  case  is  covered  by  the  argument  immediately following the
       primitive: %diz,if-zero,96,2,6,.../.
       
               
                                                                 <Page No.  14>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||         Number System and Radix control in LISP and SAM76          ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
                                                        ______________________ 
       The  principal  number system of both LISP and  ||                    ||
       the  SAM76  language  is  arbitrary  precision  ||   NUMBER SYSTEM    ||
       integer.  That  is  to  say  that  unlike most  ||                    ||
                                                        ______________________ 
       programming  languages, neither LISP nor SAM76                          
       impose  a  limit on the magnitude of an integer. COMMON LISP does define
       formally  three  additional types of numbers: "ratios", "floating-point"
       and   "complex".   
       
       
       There  are  some internal differences in the method by which numbers are
       operated  on.  These  differences  relate to the promotion of efficiency
       when  small  numbers  are  used,  which  is  most  of the time. A formal
       distinction  is provided for in COMMON LISP - "fixnum" and "bignum". The
       values of these two is strictly implementation dependent.
       
       
       There  is a fundamental difference in which COMMON LISP defines floating
       point  numbers  from  that in which some implementations of SAM76 handle
       them. COMMON LISP provides for a specification of floating point numbers
       in  terms  of  the number of bits used for the "precision" and "exponent
       size" components.
       
       
       The  preferred  implementation  in  the  SAM76  language is based on the
       concept of "drifting point". In this concept the precision of the result
       of   any   arithmetic  operation  is  based  on  the  maximum  precision
       encountered  during  the  execution  of  an arithmetic function. If more
       precision  is  desired,  then  it is incumbent on the user to place more
       zeroes to the right of the decimal point as illustrated below:
       
               %ad,5,6.732/=11.732
               %mu,5,6.732/=33.660
               %di,1,3/=0
               %di,1.0000,3/=.3333
               %di,2.000000,3/=.666666
       
               
                                                                 <Page No.  15>
       ------------------------------------------------------------------------
       
       
                                                        ______________________ 
       The  ability  to  change  the  number base for  ||                    ||
       arithmetic  operations  is  important when the  ||      RADICES       ||
       application   program   must  manipulate  data  ||                    ||
                                                        ______________________ 
       coming  from  certain  peripherals,  and where                          
       that data is of a binary nature. Both COMMON LISP and the SAM76 language
       contain mechanisms for handling numbers in radices other than ten. These
       mechanisms are different. COMMON LISP allows integers to be "notated" in
       radices  other than ten ranging from 2 to 36 inclusive. SAM76 provides a
       primitive  to  change  the number base, and this change remains in force
       until   the   radix   is   changed   again.   
       
       
       The notation scheme used in LISP is shown below:
       
               #nnRddddddd             ;nn is radix in decimal, R is marker
                                       ;and d...d is number in that radix
       
       The change scheme and an example using SAM76 is as follows:
       
               %cnb,nn/=               ;change number base to "nn" decimal
       
               %cnb,16/=               ;change number base to 16
               %mu,A,A/=100            ;product in base 16
               %cnb,10=                ;change back to base 10
               %mu,A,A/=A0             ;as per spec for multiply
       
       
       NOTE: The foregoing treatment of radix is as specified in LISP reference
       No.  5.  Winston  in  his book (LISP reference No. 1) merely states that
       "the  radix  in  COMMON  LISP is ten unless the user asks LISP to change
       it".  GOLDEN  HILL  version  of LISP seems to ignore the whole matter of
       radix entirely.
       
       Howorka  (LISP  reference  No.  3) provides a "radix" function where the
       argument  is  a "number" which confusingly must be in the current radix.
       Furthermore the arithmetic functions require "numbers" only although the
       result does in fact include alphabetic symbols if the radix is set to be
       greater than ten.
       
               
                                                                 <Page No.  16>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       || Use of PRINT - (os) "output string",  READ - (is) "input string",  ||
       ||                  and EQUAL - (ii) "if identical"                   ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
       
       LISP (San Marco)
       
       * (PROGN (PRINT '(WHAT IS THE BLOCK ON))
               (TERPRI)
               (PRIN1 '***)
               (LET ((ANSWER (READ)))
                 (IF (EQUAL ANSWER 'TABLE)
                       (PRINT '(OK ITS ON THE TABLE))
                       (PRINT '(OK ITS NOT ON THE TABLE)))
                 ANSWER))
       (WHAT IS THE BLOCK ON)
       ***B52
       (OK ITS NOT ON THE TABLE)
       B52
       
       
       SAM76   (first example)
       
       %os,
       WHAT IS THE BLOCK ON
       ***/%dt,ANSWER,%is//`
       %ii,%ANSWER/,TABLE,`
       !%os,OK ITS ON THE TABLE//,`
       !%os,OK ITS NOT ON THE TABLE///=
       WHAT IS THE BLOCK ON
       ***B52
       OK ITS NOT ON THE TABLE
       
       
               (second example - tighter code)
       
       %os,
       What is the block on
       ***%ii,%is/,TABLE, ok its, ok its not/ on the table/=
       What is the block on
       ***B52 ok its not on the table
       
       
               (third example - tighter code yet)
       
       %os,
       What is the block on
       *** ok its%ii,%is/,TABLE,, not/ on the table/=
       What is the block on
       ***B52 ok its not on the table
       
               
                                                                 <Page No.  17>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||                   LISP BASIC PRIMITIVE FUNCTIONS                   ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||               Taking Lists Apart - LISP CAR and CDR                ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
       
       The  talent  of  LISP  for  manipulating expressions is based on a basic
       family of primitive functions:
       
               CAR     Returns the first element of a list
               CDR     Returns all but the first element of a list
       
       In  some  LISP  implementations  CAR  is also known as FIRST, and CDR as
       REST.  Extracting other than the first element of a list (viz: the third
       one) requires a nested combination of CAR and CDR functions:
       
               (CAR (CDR (CDR '(ONE TWO THREE FOUR FIVE SIX))))
               THREE
       
       Composite  primitives  of the form CXXXXXXR, where X is either absent or
       an  A  or  a  D  as required to do the task, are sometimes provided. The
       composite primitive for the foregoing example is CADDR.
       
               
                                                                 <Page No.  18>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||          SAM76 Extracts or Fetches elements or arguments           ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
       
       A  single SAM76 language function (ra) "Return Argument" is available to
       select  any  single one of an arbitrary number of arguments in a list as
       illustrated below:
       
               %ra,3,one,two,three,four,five,six/=three
       
       
       There  are no single SAM76 language functions equivalent to the LISP CDR
       that will return all but the first (namely the REST) elements of a list.
       There are several ways of doing this if necessary.
       
       A  method  uses  one  of  the  several primitives that move the internal
       pointer  with  which  each defined text or list is equipped to a desired
       position  along  the list continuum. Then the value of the matter to the
       right  of the pointer is returned. After that the pointer is restored to
       its initial or default position at the extreme left of the text or list.
       
       
       Making a list           %dt,L,one two three four five six seven/=
       The function            %dt,rest,!%nu,fdm,q1,q2, /%q1/%md,q1,0///=
       Parametrizing           %pt,rest,q1,q2/=
       Using it                %rest,L,5/=six seven
         or also               %rest,L,1/=two three four five six seven
       And note                %rest,L/=one two three four five six seven
       
       
       In  the  above  example on the line headed "the function", the mechanism
       which  sweeps  the  internal  pointer  to  the  proper  position in this
       particular case if the "fdm" function. This function ("fetch d matches")
       is  one of several pattern matching function used in the SAM76 language.
       This  function  will operate with reference to the named text denoted by
       "q1",  seek  out a number (denoted by "q2") of occurences of the pattern
       desired  -  in  this  case a "space" and leave the internal pointer just
       past that particular "space".
       
       
       The "nu" that immediately precedes "fdm" in the expression is a function
       "NULL"  which  specifies  that  no  value  is  to  be  returned  by  the
       expression, but that the side effect of moving the pointer be performed.
       The  expression following is merely an invocation of the named text, the
       value of which will be only that which is found to the right of the, now
       moved,  pointer.  The  last expression on that line (md) "move divider",
       serves  to restore the pointer in the text whose name is denoted by "q1"
       back to its left (or zero) end.
       
               
                                                                 <Page No.  19>
       ------------------------------------------------------------------------
       
       
       
       A  simpler  and  much  more  elegant method, albeit difficult to explain
       briefly,  is  through  the use of the "multi-partition" mechanism of the
       SAM76 language:
       
       %dt,REST,%mc,1//=
       %dt,list,(,one,two,three,four,five,....)/=
       %REST%list//=,two,three,four,five,....
       
                                                        ______________________ 
       Another   mechanism  available  in  the  SAM76  ||                    ||
       language  for bringing into play a "REST" of a  ||The Multi-Partition ||
       list  makes  use of the characteristics of the  ||                    ||
                                                        ______________________ 
       "multi-partition"  concept.  This is a type of                          
       parameter  wchich  is  replaced by all of the elements of the list whose
       ordinal position is equal to or greater than the parameter marker value:
       
       
       
       First we define a list:         %dt,L,(,one,two,three,four,five,six)/=
       
       Making a multi-partition:       %dt,P,%mc,3//=
       
       Now invoking P with list L      %P%L//=,three,four,five,six
       
       
       This  mechanism  is used extensively when it is desired to sweep through
       lists  in a continuous looping procedure until the list is exhausted. In
       this case a test for the end of the list is provided as in the following
       example:
       
       
               %dt,loop,!%ii,q1,,,!%proced,q1,q2/%loopmp3/////+=
               %mt,loop,,,mp3/%pt,loop,q1,q2/=
               %vt,loop/=
               %ii,[1],,,!%proced,[1],[2]/%loop[#3]///
       
       
       In  the above example the invocation of loop with a list, "%loop%list//"
       will,  if there are terms still left in the list, execute a user defined
       function  "proced"  with two arguments, namely the next two on the list,
       and then "loop" will be reinvoked with the third and subsequent elements
       of the list.
       
       For  details about the mechanism available to define and pass parameters
       see the section which discusses "Function Definition, ..." ; for details
       about  the  Multi-partition  parameter concept see SAM76 reference No. 3
       (ACM SIGPLAN Notices).
       
               
                                                                 <Page No.  20>
       ------------------------------------------------------------------------
       
       
        ______________________                                                 
       ||                    ||  There  are  a number of functions which may be
       ||  Internal Divider  ||  used to move the internal text pointer for the
       ||                    ||
        ______________________   purpose   of  "dividing"  the  text  into  two
                                 individually accessible parts. This pointer or
       divider  may  be thus placed anywhere within the body of a text, and its
       position   may   be   queried   or   viewed   at   any   time:   
       
       
       defining a text         %dt,x,This is a dog or a cat or a horse/=
       moving the pointer      %fr,x,dog/=This is a
       viewing it              %vt,x/=This is a dog^ or a cat or a horse
       characters to right     %crd,x/=13
       characters to left      %cld,x/=20
       retrieving "x"          %x/= or a cat or a horse
       returning pointer       %md,x,0/=
       viewing again           %vt,x/=This is a dog or a cat or a horse
       
       
       There  are  a  number  of  functions  which  affect  the position of the
       internal  divider.  This  position  is  always updated after using these
       functions, and the value of this position is stored as part of the named
       text  header. Because this is part of the data structure, this number is
       not  automatically  stored  in  ASCII, or typeable files and the user is
       therefore required, if such a file is to be used, to provide appropriate
       scripts  to  position the pointer appropriately if it is not in the home
       or left end position.
       
       
       When  files  are  created  using the SAM76 language "sf" store file, and
       retrieved  using the "bf" bring file functions, then the position of the
       divider  is preserved and retrieved without any explicit action required
       of the user.
       
               
                                                                 <Page No.  21>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||      Putting Things Together,   LISP - CONS, APPEND and LIST       ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
       
       There are three LISP primitives available to put together lists:
       
       The  first of these is APPEND which strings together the elements of all
       lists supplied to the function as its arguments.
       
       Assuming we first create a list "K" and another "L":
       
               SETQ K '(Y Z)
               Y Z
       
               (SETQ L '(A B))
               (A B)
       
       Then we use "append" to string together these lists as shown:
       
               (APPEND L K L L)
               (A B Y Z A B A B A B)
       
       
       The  second LISP primitive is LIST. Unlike APPEND it does not run things
       together. Instead it makes a list out of its arguments:
       
               (LIST L L)
               ((A B) (A B))
       
               (LIST 'L L)
               (L (A B))
       
       
       The third LISP primitive that puts lists together is CONS. This function
       takes a list in inserts a new first element as illustrated:
       
               (CONS L L)
               ((A B) A B)
       
               (CONS 'L L)
               (L A B)
       
               
                                                                 <Page No.  22>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||             Concatenation mechanism in SAM76 language              ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
       
       The  SAM76 language does not provide an explicit "append" function. This
       capability  is  implicit in the mechanism of the language processor. The
       LISP example above is repeated below using the SAM76 system:
       
               %dt,K,Y Z /=                    defining list "K"
               %dt,L,A B /=                    defining list "L"
       
               %L/%K/%L/%L/=A B Y Z A B A B
       
       
       There  is,  however,  in  the  SAM76  language an explicit concatenation
       primitive  that  may be used to create or define texts in the same sense
       that  SETQ  in  LISP  and  (dt)  "define  text" in SAM76. The created or
       defined  text  is  the  concatenation  of  the  named texts found in the
       argument  list  of the (ct) expression. Given the previous example it is
       desired to create a new list containing the results shown above:
       
               %ct,NEWLIST,L,K,L,L/=           we make "NEWLIST"
               %NEWLIST/=A B Y Z A B A B       we look at it
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||               LISP - LENGTH, REVERSE, SUBST and LAST               ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
       
       LENGTH counts the number of "top elements" in a list as shown:
       
               (LENGTH '(A B))
               2
       
               (LENGTH '((A B) (A B)))
               2
       
       
       There is no really equivalent function in the SAM76 language. There is a
       function  that  will  return  as  its  value  the  number  of particular
       patterns,  and this function can be used to count elements by making the
       desired  pattern the comma. This function works only with reference to a
       named list or text, and pays no attention to "levels".
       
       
       REVERSE turns the top level of a list around:
       
               (REVERSE ((A B) (X Y)))
               ((X Y) (A B))
       
       
       There  is  in  the  SAM76  language no equivalent function, but one that
       performs  in  the  same  manner  may  be defined by the user without any
       difficulty.
               
                                                                 <Page No.  23>
       ------------------------------------------------------------------------
       
       
       
       SUBST  which takes three arguments is used for minor in place editing by
       replacing  with  the  expression  which is the first argument, the atome
       denoted by the second argument in the list which is the third argument:
       
               (SUBST 'B 'A '(A B C))
               (B B C)
       
       
       In  the  case of "quoted" strings there is no particular function in the
       SAM76  language  that  can  do  this. It does not appear to be necessary
       within  the  semantics of that language. In the case of defined texts or
       lists  then  this  is accomplished through the use of appropriate simple
       user defined procedures as needed.
       
       
       LAST  returns  a  list  that  contains only the last element of the list
       given as the argument.
       
               (LAST '((A B) (C D)))
               ((C D))
       
       
       There is no function in the SAM76 structure which will do this directly,
       but  this is readily implemented as a user defined procedure through the
       use  of the (md) "move divider" function followed by a left move of that
       divider  to  point  to  the  beginning  of  the  last  element, and then
       restoring  the  divider to its "zero" or normal location at the left end
       of the string.
       
               
                                                                 <Page No.  24>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||              THE EVALUATION PROCESS - LISP and SAM76               ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
                                                        ______________________ 
       When  a  form  is  typed by a LISP user, it is  ||                    ||
       automatically  handed  to  the primitive EVAL.  ||        LISP        ||
       The diagram in figure [x.x] describes how this  || Patrick H. Winston ||
       primitive   works.  Note  that  EVAL  normally  ||                    ||
                                                        ______________________ 
       evaluates  all of the arguments before feeding                          
       them  to  the  specified  procedure. Numeric atoms, however, are treated
       specially,   in   that   they   are   not   evaluated.   
       
       
       Also,  a  form whose first element is the name of one of certain special
       primitives  is  "not"  treated  in  the  standard way. Instead, EVAL may
       evaluate  the  arguments strangely or not evaluate them at all. Forms in
       which these special primitives occur are called "special forms". SETQ is
       one of the exceptional primitives, because it handles its arguments in a
       special  way:  it  does  not  evaluate  the  first  one. This is a great
       convenience,  for  otherwise  we  would have to quote the first argument
       every time.
       
               
                                                                 <Page No.  25>
       ------------------------------------------------------------------------
       
       
                                                        ______________________ 
       The  system scanner evaluates expressions from  ||                    ||
       inside  out  and left to right. When the scope  ||       SAM76        ||
       (left  and  right  end)  of  an  expression is  ||     the author     ||
       found,  its  type (Active, Neutral, Protected)  ||                    ||
                                                        ______________________ 
       is  recorded to determine after evaluation how                          
       the  value  returned should be processed: either re-evaluated or skipped
       over.   
       
       
       The  type  of  the  expression  is  specified  by  the  user through the
       appropriate  selection  of  symbols to delimit the left and right end of
       the  expression.  These  symbols  when  used in this manner are known as
       "function markers" and are shown below:
       
               %...,.....,.....,.....,../      - Active Expression
               &...,.....,.....,.....,../      - Neutral Expression
       
       
       Next  the  expression  whose  scope has been found is handed over to the
       evaluator  which  evaluates  "all" of the arguments. The manner in which
       the  arguments  are  treated  is  the  responsibility  of the individual
       functions  named  in  the first element of the expression. Note that the
       first  element  itself  may be an expression which after evaluation will
       ultimately become the name of a function, be it only the "null string".
       
       
       Once the scope of the expression and its type have been established, and
       the  name  of the function is known the arguments are handed over to the
       function for evaluation. Note that there are two lists of functions, one
       is  the  resident  or  built-in  list, and the other is the user defined
       list.  The  sequence in which these two lists are searched is controlled
       by  the  type  of  function  marker  used  to delineate the scope of the
       expression.  In  the normal case, using the function markers illustrated
       above,  the  first  list  to  be  searched  is  that for the built-in or
       resident set of functions. Then if not found there the user defined list
       is  examined.  If the function is found in neither of the two lists then
       the  value  of  the  expression  is  the null string "without giving any
       notice to the user."
       
       
       The  user  may reverse the search sequence to first seek the function in
       the  user  defined list and then the resident list by using the function
       marker set (known as the "M" set) shown below:
       
               #...,.....,.....,.....,..:      - Active Expression
               #...,.....,.....,.....,..;      - Neutral Expression
       
               
                                                                 <Page No.  26>
       ------------------------------------------------------------------------
       
       
       
       Note  that there is absolutely no restriction on the name that users may
       give to user defined texts or functions. These include numerals, symbols
       normally  used  as  function  markers,  and  even  the  null  string  as
       illustrated below:
       
               %dt,,This is a string named ""/=        ;defining it
               %/=This is a string named ""            ;invoking it
       
       
       One  can  also  give  a  user  defined text or function a name which is,
       itself, an executable expression as for instance:
       
               %dt,(%ad,5,5/),Name is expression/=     ;defining it
               %vt,(%ad,5,5/)/=Name is expression      ;viewing text but
               %ad,5,5/=10                             ;just adds 5 and 5
               %lt, /= 10                              ;listing text names
               &lt, /= %ad,5,5/                        ;neutral listing
       
               
                                                                 <Page No.  27>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||             String Manipulation - LISP CONS and REMOVE             ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
       
       The  LISP  examples  shown  below  are  explained  in  WINSTON  near the
       beginning  of  chapter  2.  The  purpose  of these examples is to create
       associations and to edit these associations.
       
       
       LISP                                    SAM76
       
       
       (SETQ FRIENDS '(DICK JANE SALLY))       %dt,friends,dick jane sally/=
       
       
       (FRIENDS)                               %friends/=dick jane sally
         (DICK JANE SALLY)
       
       
       (SETQ ENEMIES '(TROLL GRINCH GHOST))    %dt,enemies,troll grinch ghost/=
       
       
       (SETQ ENEMIES (REMOVE 'GHOST ENEMIES))  %pt,enemies,ghost /%ep,enemies/
       (SETQ FRIENDS (CONS 'GHOST FRIENDS))    %dt,friends,ghost %friends//=
       
       
       ENEMIES                                 %enemies/=troll grinch
         (TROLL GRINCH)
       FRIENDS                                 %friends/=ghost dick jane sally
         (GHOST DICK JANE SALLY)
       
       
       LISP Procedure that does the same job:
       
       (DEFUN NEWFRIEND (NAME)
         (SETQ ENEMIES (REMOVE NAME ENEMIES))
         (SETQ FRIENDS (CONS NAME FRIENDS)))
       
       
       SAM76 Language equivalent procedure:
       
       %dt,newfriend,!%pt,enemies,q1 /%ep,enemies/%dt,friends,q1 %friends///=
       %pt,newfriend q1/=
       
       
       The use of the procedures to elevate the status of GHOST is:
       
       LISP    (NEWFRIEND 'GHOST)
       
       SAM76   %newfriend,ghost/=
       
               
                                                                 <Page No.  28>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||   Equality and Comparison Predicate functions in LISP and SAM76    ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
       
       The  syntactic  philosophy  of  predicate  functions  is quite different
       between  those  found  in  LISP  and their functional equivalents in the
       SAM76  language.  In general predicates are functions which perform some
       kind  of test on or between one or more objects. The results of the test
       are  then  returned to the user or program in such a manner that further
       action as appropriate to the test results may be taken.
       
       
       In  LISP a predicate is a function which has no side effects and returns
       a boolean result depending only on its arguments. Thus a predicate tests
       its  arguments  for  having  certain  properties.  The result is usually
       either the letter "t" or "NIL".
       
       
       In SAM76 a predicate is a function which has no side effects and returns
       one from a choice of possibly several values which have been embedded in
       the function expression itself depending on its arguments.
       
       
       The following examples will illustrate this difference:
       
                       LISP                    SAM76
       
       
       Identity test   (EQ 'John 'John)        %ii,John,John,YES,NO/=YES
                       T
       
                       (EQ 'John 'JOHN)        %ii,John,JOHN,Y,NONO/=NONO
                       NIL
       
       
       The  main  philosophical  difference  is  that with the SAM76 syntax the
       value  returned from the test may itself be a call to another procedure.
       For  instance we  will define YES to say "VERY GOOD" and NO to add 5 and
       6:
       
       defining YES    %dt,YES,!%os,VERY GOOD///=
       defining NO     %dt,NO,!%ad,5,6///=
       
       testing ...     %ii,John,John,!%YES//,!%NO///=VERY GOOD
       
       and             %ii,John,JOHN,!%YES//,!%NO///=11
       
       
       Additionally  some  of  the  SAM76  language  predicates  provide for an
       arbitrary  number  of  arguments  and  a  corresponding  number  of user
       stipulated results.
       
               
                                                                 <Page No.  29>
       ------------------------------------------------------------------------
       
       
       
       This  philosophy  permits  functions to be defined in such a manner that
       the  function  will  iterate on itself until a desired condition is met.
       For  instance the function "loop" defined below, requests input from the
       user.  When  the  user  input  is  as  desired,  then the process stops,
       otherwise it repeats the request:
       
       
                       %dt,loop,!%os,
                       Password please ?- /%ii,SECRET,%is/,,!%loop////=
       
       After  the  preliminary query as to the password the user is expected to
       enter some material (terminating entry at this time with an equal sign).
       If that input is the word SECRET, then the value of the test is the null
       string  (note  two commas next to each other) else the value is a recall
       of the function "loop". Execution of "loop" whould appear as follows:
       
       
       starting        %loop/=
       wrong           Password please ?- Tommy=
       wrong           Password please ?- Jim=
       correct         Password please ?- SECRET=
       all done
       
               
                                                                 <Page No.  30>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||   Function Definition, Viewing Defined Functions, and Parameters   ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
       
       Functions  may  be  defined  with  equal ease in both LISP and the SAM76
       language.  There  are  some  differences  in  how  the parameters of the
       functions  are  created  or  provided  for.  These  differences  will be
       highlighted below.
       
       
       LISP - Function definition template
       
       (DEFUN NAME (PARAMETER LIST)
               (FORMS or EXPRESSIONS)
               (MORE FORMS)
               (AS REQUIRED)
               (AND OR CONDITIONS)
                                       )       ;end of definition
       
       
       SAM76 Language - Procedure definition template
       
       %dt,NAME,!forms or expressions with embedded dummy variables
                 such as q1, q2, &c. as well as
                 conditional expressions/
       /=
       
       
       Note  that  the  full scope of the defined function is found between the
       exclamation  point and the next to last slash: ! ...procedure ... /. The
       last slash bounds the full scope of the defining expression which starts
       with %dt,...
       
       
       It  is  then  necessary  to  "parametrize"  the embedded dummy variables
       through use of the "partition text" function thus:
       
               %pt,NAME,q1,q2,q3,.../=
       
       
       Defined   functions  may  be  viewed  using  LISP  with  the  "function"
       primitive, and using SAM76, the "view text" primitive as follows:
       
       LISP    (function NAME)               SAM76    %vt,NAME/=
       
       
       At  this point it will be observed that the parametrized elements of the
       SAM76 language function will be displayed as numerals enfolded by square
       brackets.  The number shown corresponds to the position of the parameter
       in question in the parameter list.
       
               
                                                                 <Page No.  31>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||                  Factorial function - (Recursive)                  ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
       
       SAM76
       
       %dt,f,!%ii,x,1,1,!%mu,x,%f,%su,x,1///////=
       %pt,f,x/=
       
       
       Viewing at this time function named "f" is as follows:
       
       %vt,f/=%ii,[1],1,1,!%mu,[1],%f,%su,[1],1/////
       
       
       Executing or using the SAM76 factorial function is:
       
       %f,5/=120
       
       
       
       LISP - WALTZ
       
       * (defun f (x) (cond ((zerop x) 1) (t (* x (f (- x 1))))))
       
       
       Viewing at this time LISP function "f" results in:
       
       * (FUNCTION f)
       (LAMBDA (X) (COND ((ZEROP X) 1) (T (* X #))))
       
       
       Executing or using the LISP factorial function is:
       
       * (f 5)
       120
       
       
       
       LISP - FRANZ and XLISP
       
       -> (defun f (n) (cond ((= n 1) 1) (t (* n (f (- n 1))))))
       
       viewing this we get:
       
       -> (function f)
       (lambda (n) (cond ((= n 1) 1) (t (* n (f (-n 1))))))
       
               
                                                                 <Page No.  32>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||                   Towers of HANOI - (Recursive)                    ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
       
       SAM76
       
       %dt,HANOI,!%ii,q1,0,,!%HANOI,%su,q1,1/,q2,q4,q3/!
       Move Ring q1 from q2 to q3/%HANOI,%su,q1,1/,q4,q3,q2/////=
       %pt,HANOI,q1,q2,q3,q4/=
       
       Usage format: %HANOI,4,Here,There,Middle/=
       
       
       
       LISP - "Winston - LISP - second edition," page 113
       
       (defun HANOI (n) (transfer 'A 'B 'C n))
       
       (defun move-disk (from to)
       (list (list 'Move 'Ring 'from from 'to to)))
       
       (defun transfer (from to spare n)       ; "n" not "number"
       (cond ((equal n 1) (move-disk from to)) ; "equal" used in WALTZ
               (t (append (transfer from
                               spare
                               to
                               (- n 1))
                       (move-disk from to)
                       (transfer spare
                               to
                               from
                               (- n 1))))))
       
       
       Usage format: (HANOI 4)
       
       
       
       COMMENTS:
       
       This LISP version does not permit user to specify a name for each of the
       three  towers symbolized as 'A, 'B, 'C, nor does the output indicate the
       number of the ring being moved.
       
       Additionally  the  output  is  in  a continuous stream each of the moves
       separated  by a space rather than a New Line. Each move is also enfolded
       by  a  pair  of parentheses which does not enhance the legibility of the
       result.
       
               
                                                                 <Page No.  33>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||        Memory management of "texts," "forms," and variables        ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
        ______________________                                                 
       ||                    ||  User  defined  items  which include strings of
       ||       SAM76        ||  literary   material,   procedures,   scripts, 
       ||                    ||
        ______________________   variables,   relationships,   arrays  &c.  are
                                 placed  in the system memory in a manner which
       is  generally  not  of  concern to the user. That is to say that various
       storage  and  retrieval  means  may be used to enhance the efficiency of
       storage   and   retrieval   as   a  function  of  the  system  hardware.  
       
       
       In  addition  to  creating  items, the user may also delete items at any
       time, the space being released immediately for re-use.
       
       
       The  user  may  also  use  certain  primitives to examine defined items,
       observe  positions  of  internal markers and pointers, and edit existing
       items.
       
       
       Finally  the  user  may  at any time obtain a list of items currently in
       active memmory, and most importantly the order of this list is always in
       a  time sequence, from left to right, in which the items were created or
       subsequently  edited.  It  should be noted that the use of the "tr" trim
       primitive  which eliminates multiple occurrences of selected charactdrs,
       and  the  primitives  which create and erase partitions do not place the
       item so modified to the right hand end of the item list.
       
       
       A  list of resident primitive functions may be obtained independently of
       the list described above. The rationale is that this list is of use only
       for  informational  purposes  since  the  primitives cannot be edited or
       modified  by  the user. If one wants a consolidated list (such as LISP's
       OBLIST)  it  is  obtained merely by concatenating the two lists obtained
       through the use of the two appropriate primitives.
       
               
                                                                 <Page No.  34>
       ------------------------------------------------------------------------
       
       
                                                        ______________________ 
                                                       ||                    ||
                                                       ||        LISP        ||
                                                       ||                    ||
                                                        ______________________ 
                                                                               
       
       
               
                                                                 <Page No.  35>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||                   Interaction with system files                    ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
        ______________________                                                 
       ||                    ||  The  normal  manner  in  which  SAM76 language
       ||       SAM76        ||  scripts  or programs are stored is through use
       ||                    ||
        ______________________   of  the  primitives  "sf" store file, and "bf"
                                 bring  file.  Files  created  using  the  "sf"
       function  contain  all  of  the  data  structures and pointers and other
       artifacts  needed  to facilitate and speed up the operation of the SAM76
       programs.  These  files  are  not  normally legible as would plain ASCII
       files.   
       
       
       The  main  advantage  of using this type of file is that they tend to be
       significantly  smaller  than  equivalent  ASCII  files,  and  that their
       loading  is  very  much faster. In addition one may easily concatenate a
       number  of such files by bringing them in one after the other. The named
       items brought in are placed to the right hand end of any items currently
       in  memory  and  the  individual  groups  coming  from  each file may be
       separated  by  the  user through the definition of items with unique and
       highly visible names such as $$$ or ***.
       
       
       The  SAM76 language also provides primitives to "read" files and execute
       the  texts  encountered during the file reading process. This method may
       be  achieved  either by the "rf" read file primitive, or through the use
       of  the  pipeline  features  of  the language by opening a communication
       channel  to  a desired file and then obtaining matter from the file just
       as one would from the keyboard.
       
       
       %dif,jones.txt/=                opens file jones.txt
       %sic,fil/%id,20/%sic,con/       selects channel file
                                       inputs 20 characters
                                       selects channel console
       
       
       In  like  manner  the  SAM76  language provides primitives to "write" to
       files or a to a variety of communication channels chosen using the "soc"
       select output channel primitive.
       
       
       Available  channels  for  input  or  output  in  the manner described is
       ascertained  through  the use of the "lic" list input channels and "loc"
       list output channels primitives.
       
               
                                                                 <Page No.  36>
       ------------------------------------------------------------------------
       
       
                                                        ______________________ 
                                                       ||                    ||
                                                       ||        LISP        ||
                                                       ||                    ||
                                                        ______________________ 
                                                                               
       
       
               
                                                                 <Page No.  37>
       ------------------------------------------------------------------------
       
       
        ______________________________________________________________________ 
       ||                                                                    ||
       ||        Some Additional Features which may not exist in LISP        ||
       ||                                                                    ||
        ______________________________________________________________________ 
       
       
        ______________________                                                 
       ||                    ||  A  number  of  the  SAM76  language  functions
       ||   SUB-FUNCTIONS    ||  provide  a variety of "sub-functions." This is
       ||                    ||
        ______________________   possible  without  damage  to  the fundamental
                                 structure   of   the   language   and  reduces
       "cluttering",  particularly  when  it  is  necessary to have families of
       functions  unique  to  particular environments. The syntax for accessing
       sub-functions   is:   %function,subfunction,arguments.../   
       
       
       One  subfunction  which  is always available for each function which has
       sub-functions  is  the  "lf"  or  list functions, permitting the user to
       ascertain  what  are  the  subfunctions  of  a  particular function. For
       instance  "pl" the general plotter function has a number of subfunctions
       which may be identified as follows:
       
       	o~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       	o  %pl,lf, /={ CBC COL DEL DIS IBR INV LF MQ NM SU PCC VID VM}
       	o
       	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
                                                        ______________________ 
       The  "rr"  return  to  restart level, and "ri"  ||                    ||
       return  to  idle  primitives provide means for  ||   "rr" and "ri"    ||
       changing the flow of control by wiping out any  ||       Return       ||
       unevaluated   expressions   as   well  as  any  ||                    ||
                                                        ______________________ 
       accumulated  values.  The "rr" function allows                          
       transfer  of  control  to some other procedure thus: %rr,!%procedure///.
       The  "ri"  primitive  essentially  exits from the evaluation process and
       resets  all  options  changed  by  the  user  to  their  initial default
       condition.   
       
               
                                                                 <Page No.  38>
       ------------------------------------------------------------------------
       
       
        ______________________                                                 
       ||                    ||  This primitive may be used in one of two ways.
       || "ex" exit function ||  If  %ex/  is  encountered then a clean exit is
       ||                    ||
        ______________________   made   back   to   the  operating  system.  If
                                 %ex,name.com/   is   encountered   then   an  
       executable   program   is  created  within  the  host  operating  system
       identified  by "name.com" and a clean exit is made back to the operating
       system.  Subsequent  execution  of  "name.com" from the operating system
       will  then reload the SAM76 program and evaluation will proceed from the
       point  at  which  the  %ex,name.com/  was  encountered as if no exit had
       intervened.   
       
       
               ....%ex,hello.com/%os,I see we are back/....
               A>hello
               I see we are back ....
       
                                                        ______________________ 
       A  few  of the available predicates that might  ||                    ||
       be  of interest should be mentioned. "tb" text  ||     Predicates     ||
       branch  is  a  predicate  which may be used to  ||                    ||
                                                        ______________________ 
       test  for  the  presence  of a stipulated user                          
       defined name: %tb,name,true,false/. A similar predicate "fb" file branch
       may be used to test for the existence of a particular file name. "@b" is
       the  predicate  that tests for the availability of a particular resident
       primitive  .  "yt"  is  there  in  a  named  item  some  desired string:
       %yt,item,hello,true,false/.  "gel" greater, equal or less function gives
       the  choice  of  three options %gel,5,2,greater,equal,less/. The "ii" if
       identical  and  "ig" if greater predicates can be used with an arbitrary
       number  of  arguments: %ii,one,xxx,ONE,FALSE,two,TWO,three,THREE,...../= 
       
        ______________________                                                 
       ||                    ||  All  of the resident function mnemonics may be
       || Renaming functions ||  changed  to suit the linguistic mnemonic needs
       ||                    ||
        ______________________   of  the  user. This was provided to facilitate
                                 use  of  the  language  by  the  international
       community.  In order to ensure portability of user defined functions and
       procedures  across  national  boundaries  a  primitive  is provided that
       allows  the  mnemonics  to  be  changed as part of the normal syntax and
       evaluation  process.  It  is  only  incumbent  on  the writer of a given
       program  to  provide  a  list  of  the  mnemonics  used  as  well  as  a
       corresponding   list   of   the   "standard"   mnemonics.   
       
       