home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume15 / siod / siod.doc < prev    next >
Text File  |  1988-06-06  |  7KB  |  213 lines

  1. SIOD: Scheme In One Defun
  2. (c) Copyright 1988 George Carrette, gjc@bu-it.bu.edu
  3. For demonstration purposes only.
  4.  
  5. If your interests run to practical applications of symbolic programming
  6. techniques, in LISP, Macsyma, C, or other language:
  7.  
  8.    Paradigm Associates Inc          Phone: 617-492-6079
  9.    29 Putnam Ave, Suite 6
  10.    Cambridge, MA 02138
  11.  
  12. Documentation for Release 1.3 1-MAY-88
  13.  
  14. [Files:]
  15.  
  16.  siod.c   The source in C, approximately 28 thousand bytes.
  17.  siod.doc This file, approximately 8 thousand bytes.
  18.  siod.scm Some utility function written in Scheme.
  19.  
  20. [Compilation:]
  21.  
  22. The code has been compiled and run by the author on Sun III and IV,
  23. Encore Multimax, 4.3BSD VAX, VAX/VMS, and AMIGA 500 using the Lattice C
  24. compiler.
  25.  
  26. On all unix machines use
  27.  
  28.   %cc -o siod siod.c
  29.  
  30. on VAX/VMS:
  31.  
  32.   $ cc siod
  33.   $ link siod,sys$input:/opt
  34.   sys$library:vaxcrtl/share
  35.   $ siod == "$" + F$ENV("DEFAULT") + "SIOD"
  36.  
  37. on AMIGA 500, ignore warning messages about return value mismatches,
  38.   %lc siod.c
  39.   %blink lib:c.o,siod.o to siod lib lib:lcm.lib,lib:lc.lib,lib:amiga.lib
  40.  
  41.  
  42. [Invocation:]
  43.  
  44. siod [-hXXXXX] [-iXXXXX]
  45.  -h where XXXXX is an integer, to specify the heap size, in obj cells,
  46.  -i where XXXXX is a filename to load before going into the repl loop.
  47.  
  48.   Example:
  49.    siod -isiod.scm -h100000
  50.  
  51. [System:]
  52.  
  53. The interrupts called SIGINT and SIGFPE by the C runtime system are
  54. handled by invoking the lisp error procedure. SIGINT is usually caused
  55. by the CONTROL-C character and SIGFPE by floating point overflow or underflow.
  56.  
  57. [Syntax:]
  58.  
  59. The only special characters are the parenthesis and single quote.
  60. Everything else, besides whitespace of course, will make up a regular token.
  61. These tokens are either symbols or numbers depending on what they look like.
  62. Dotted-list notation is not supported on input, only on output.
  63.  
  64. [Special forms:]
  65.  
  66. The CAR of a list is evaluated first, if the value is a SUBR of type 9 or 10
  67. then it is a special form.
  68.  
  69. (define symbol value) is presently like (set! symbol value).
  70.  
  71. (define (f . arglist) . body) ==> (define f (lambda arglist . body))
  72.  
  73. (lambda arglist . body) Returns a closure.
  74.  
  75. (if pred val1 val2) If pred evaluates to () then val2 is evaluated else val1.
  76.  
  77. (begin . body) Each form in body is evaluated with the result of the last
  78. returned.
  79.  
  80. (set! symbol value) Evaluates value and sets the local or global value of
  81. the symbol.
  82.  
  83. (or x1 x2 x3 ...) Returns the first Xn such that Xn evaluated non-().
  84.  
  85. (and x1 x2 x3 ...) Keeps evaluating Xj until one returns (), or Xn.
  86.  
  87. (quote form). Input syntax 'form, returns form without evaluation.
  88.  
  89. (let pairlist . body) Each element in pairlist is (variable value).
  90. Evaluates each value then sets of new bindings for each of the variables,
  91. then evaluates the body like the body of a progn. This is actually
  92. implemented as a macro turning into a let-internal form.
  93.  
  94. (the-environment) Returns the current lexical environment.
  95.  
  96. [Macro Special forms:]
  97.  
  98. If the CAR of a list evaluates to a symbol then the value of that symbol
  99. is called on a single argument, the original form. The result of this
  100. application is a new form which is recursively evaluated.
  101.  
  102. [Built-In functions:]
  103.  
  104. These are all SUBR's of type 4,5,6,7, taking from 0 to 3 arguments
  105. with extra arguments ignored, (not even evaluated!) and arguments not
  106. given defaulting to (). SUBR's of type 8 are lexprs, receiving a list
  107. of arguments. Order of evaluation of arguments will depend on the
  108. implementation choice of your system C compiler.
  109.  
  110. consp cons car cdr setcar setcdr
  111.  
  112. number? + - * / < > eqv?
  113. The arithmetic functions all take two arguments.
  114.  
  115. eq?, pointer objective identity, eqv? also works on numbers.
  116.  
  117. symbol?
  118.  
  119. symbol-bound? takes an optional environment structure.
  120. symbol-value also takes optional env.
  121. set-symbol-value also takes optional env.
  122.  
  123. env-lookup takes a symbol and an environment structure. If it returns
  124. non-nil the CAR will be the value of the symbol.
  125.  
  126. assq
  127.  
  128. read,print
  129.  
  130. eval, takes a second argument, an environment.
  131.  
  132. copy-list. Copies the top level conses in a list.
  133.  
  134. oblist, returns a copy of the list of the symbols that have been interned.
  135.  
  136. gc-status, prints out the status of garbage collection services, the
  137. number of cells allocated and the number of cells free. If given
  138. a () argument turns gc services off, if non-() then turns gc services on.
  139.  
  140. load, given a filename (which must be a symbol, there are no strings)
  141. will read/eval all the forms in that file.
  142.  
  143. quit, will exit back to the operating system.
  144.  
  145. error, takes a symbol as its first argument, prints the pname of this
  146. as an error message. The second argument (optional) is an offensive
  147. object. The global variable errobj gets set to this object for later
  148. observation.
  149.  
  150. null?, not. are the same thing.
  151.  
  152. edit is a VMS specific function that takes a single filename argument
  153. and calls the sharable EDT editor to edit the file.
  154.  
  155. [Utility procedures in siod.scm:]
  156.  
  157. Shows how to define macros.
  158.  
  159. cadr,caddr,cdddr,replace,list.
  160.  
  161. (defvar variable default-value)
  162.  
  163. And for us old maclisp hackers, setq and defun, and progn, etc.
  164.  
  165. [A streams implementation:]
  166.  
  167. The first thing we must do is decide how to represent a stream.
  168. There is only one reasonable data structure available to us, the list.
  169. So we might use (<stream-car> <cache-flag> <cdr-cache> <cdr-procedure>)
  170.  
  171. the-empty-stream is just ().
  172.  
  173. empty-stream?
  174.  
  175. head
  176.  
  177. tail
  178.  
  179. cons-stream is a special form. Wraps a lambda around the second argument.
  180.  
  181. *cons-stream is the low-level constructor used by cons-stream.
  182.  
  183. [Benchmarks:]
  184.  
  185. A standard-fib procedure is included in siod.scm so that everyone will
  186. use the same definition in any reports of speed. Make sure the return
  187. result is correct. use command line argument of
  188.  %siod -h100000 -isiod.scm
  189.  
  190. (standard-fib 10) => 55 ; 795 cons work.
  191. (standard-fib 15) => 610 ; 8877 cons work.
  192. (standard-fib 20) => 6765 ; 98508 cons work.
  193.  
  194. [Porting:]
  195.  
  196. The only code under #ifdef is the definition of myruntime, which
  197. should be defined to return a double float, the number of cpu seconds
  198. used by the process so far. This is currently specific for encore and
  199. sun unix, with a default unix which would work on any 4.2BSD derived
  200. system. The other specific case is vms, and the last default has
  201. myruntime calling the time function, which usually means an integer
  202. number of realtime seconds. Nested ifdef's are very difficult to
  203. read of course. Sorry.
  204.  
  205. There is a bit of type casting in close_open_files and vload. The
  206. pname of an un-interned symbol is used as a pointer to FILE. This
  207. saves the code (a conser, a print case, and two gc cases) of defining
  208. a new data type for keeping track of binary data. Are there any machines
  209. where a pointer to char and a pointer to FILE are different?
  210.  
  211. There should be no problem with integers vs longs on short integer
  212. machines.
  213.