home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 224a.lha / Siod / siod.doc < prev    next >
Text File  |  1989-04-12  |  10KB  |  274 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. Updated with more detail for experimenters on 17-MAY-88.
  14.  
  15. [SUBJECT INDEX:]
  16.  [SUBJECT INDEX]
  17.  [FILES]
  18.  [COMPILATION]
  19.  [INVOCATION]
  20.  [SYSTEM]
  21.  [SYNTAX]
  22.  [SPECIAL FORMS]
  23.  [MACRO SPECIAL FORMS]
  24.  [BUILT-IN PROCEDURES]
  25.  [UTILITIES IN SIOD.SCM]
  26.  [A STREAMS IMPLEMENTATION]
  27.  [BENCHMARKS]
  28.  [PORTING]
  29.  [ADDING NEW SUBRS]
  30.  
  31. [Files:]
  32.  
  33.  siod.c   The source in C, approximately 28 thousand bytes.
  34.  siod.doc This file, approximately 8 thousand bytes.
  35.  siod.scm Some utility function written in Scheme.
  36.  
  37. [Compilation:]
  38.  
  39. The code has been compiled and run by the author on Sun III and IV,
  40. Encore Multimax, 4.3BSD VAX, VAX/VMS, and AMIGA 500 using the Lattice C
  41. compiler.
  42.  
  43. On all unix machines use
  44.  
  45.   %cc -o siod siod.c
  46.  
  47. on VAX/VMS:
  48.  
  49.   $ cc siod
  50.   $ link siod,sys$input:/opt
  51.   sys$library:vaxcrtl/share
  52.   $ siod == "$" + F$ENV("DEFAULT") + "SIOD"
  53.  
  54. on AMIGA 500, ignore warning messages about return value mismatches,
  55.   %lc siod.c
  56.   %blink lib:c.o,siod.o to siod lib lib:lcm.lib,lib:lc.lib,lib:amiga.lib
  57.  
  58.  
  59. [Invocation:]
  60.  
  61. siod [-hXXXXX] [-iXXXXX]
  62.  -h where XXXXX is an integer, to specify the heap size, in obj cells,
  63.  -i where XXXXX is a filename to load before going into the repl loop.
  64.  
  65.   Example:
  66.    siod -isiod.scm -h100000
  67.  
  68. [System:]
  69.  
  70. The interrupts called SIGINT and SIGFPE by the C runtime system are
  71. handled by invoking the lisp error procedure. SIGINT is usually caused
  72. by the CONTROL-C character and SIGFPE by floating point overflow or underflow.
  73.  
  74. [Syntax:]
  75.  
  76. The only special characters are the parenthesis and single quote.
  77. Everything else, besides whitespace of course, will make up a regular token.
  78. These tokens are either symbols or numbers depending on what they look like.
  79. Dotted-list notation is not supported on input, only on output.
  80.  
  81. [Special forms:]
  82.  
  83. The CAR of a list is evaluated first, if the value is a SUBR of type 9 or 10
  84. then it is a special form.
  85.  
  86. (define symbol value) is presently like (set! symbol value).
  87.  
  88. (define (f . arglist) . body) ==> (define f (lambda arglist . body))
  89.  
  90. (lambda arglist . body) Returns a closure.
  91.  
  92. (if pred val1 val2) If pred evaluates to () then val2 is evaluated else val1.
  93.  
  94. (begin . body) Each form in body is evaluated with the result of the last
  95. returned.
  96.  
  97. (set! symbol value) Evaluates value and sets the local or global value of
  98. the symbol.
  99.  
  100. (or x1 x2 x3 ...) Returns the first Xn such that Xn evaluated non-().
  101.  
  102. (and x1 x2 x3 ...) Keeps evaluating Xj until one returns (), or Xn.
  103.  
  104. (quote form). Input syntax 'form, returns form without evaluation.
  105.  
  106. (let pairlist . body) Each element in pairlist is (variable value).
  107. Evaluates each value then sets of new bindings for each of the variables,
  108. then evaluates the body like the body of a progn. This is actually
  109. implemented as a macro turning into a let-internal form.
  110.  
  111. (the-environment) Returns the current lexical environment.
  112.  
  113. [Macro Special forms:]
  114.  
  115. If the CAR of a list evaluates to a symbol then the value of that symbol
  116. is called on a single argument, the original form. The result of this
  117. application is a new form which is recursively evaluated.
  118.  
  119. [Built-In functions:]
  120.  
  121. These are all SUBR's of type 4,5,6,7, taking from 0 to 3 arguments
  122. with extra arguments ignored, (not even evaluated!) and arguments not
  123. given defaulting to (). SUBR's of type 8 are lexprs, receiving a list
  124. of arguments. Order of evaluation of arguments will depend on the
  125. implementation choice of your system C compiler.
  126.  
  127. consp cons car cdr setcar setcdr
  128.  
  129. number? + - * / < > eqv?
  130. The arithmetic functions all take two arguments.
  131.  
  132. eq?, pointer objective identity, eqv? also works on numbers.
  133.  
  134. symbol?
  135.  
  136. symbol-bound? takes an optional environment structure.
  137. symbol-value also takes optional env.
  138. set-symbol-value also takes optional env.
  139.  
  140. env-lookup takes a symbol and an environment structure. If it returns
  141. non-nil the CAR will be the value of the symbol.
  142.  
  143. assq
  144.  
  145. read,print
  146.  
  147. eval, takes a second argument, an environment.
  148.  
  149. copy-list. Copies the top level conses in a list.
  150.  
  151. oblist, returns a copy of the list of the symbols that have been interned.
  152.  
  153. gc-status, prints out the status of garbage collection services, the
  154. number of cells allocated and the number of cells free. If given
  155. a () argument turns gc services off, if non-() then turns gc services on.
  156.  
  157. load, given a filename (which must be a symbol, there are no strings)
  158. will read/eval all the forms in that file.
  159.  
  160. quit, will exit back to the operating system.
  161.  
  162. error, takes a symbol as its first argument, prints the pname of this
  163. as an error message. The second argument (optional) is an offensive
  164. object. The global variable errobj gets set to this object for later
  165. observation.
  166.  
  167. null?, not. are the same thing.
  168.  
  169. edit is a VMS specific function that takes a single filename argument
  170. and calls the sharable EDT editor to edit the file.
  171.  
  172. [Utility procedures in siod.scm:]
  173.  
  174. Shows how to define macros.
  175.  
  176. cadr,caddr,cdddr,replace,list.
  177.  
  178. (defvar variable default-value)
  179.  
  180. And for us old maclisp hackers, setq and defun, and progn, etc.
  181.  
  182. [A streams implementation:]
  183.  
  184. The first thing we must do is decide how to represent a stream.
  185. There is only one reasonable data structure available to us, the list.
  186. So we might use (<stream-car> <cache-flag> <cdr-cache> <cdr-procedure>)
  187.  
  188. the-empty-stream is just ().
  189.  
  190. empty-stream?
  191.  
  192. head
  193.  
  194. tail
  195.  
  196. cons-stream is a special form. Wraps a lambda around the second argument.
  197.  
  198. *cons-stream is the low-level constructor used by cons-stream.
  199.  
  200. [Benchmarks:]
  201.  
  202. A standard-fib procedure is included in siod.scm so that everyone will
  203. use the same definition in any reports of speed. Make sure the return
  204. result is correct. use command line argument of
  205.  %siod -h100000 -isiod.scm
  206.  
  207. (standard-fib 10) => 55 ; 795 cons work.
  208. (standard-fib 15) => 610 ; 8877 cons work.
  209. (standard-fib 20) => 6765 ; 98508 cons work.
  210.  
  211. [Porting:]
  212.  
  213. The only code under #ifdef is the definition of myruntime, which
  214. should be defined to return a double float, the number of cpu seconds
  215. used by the process so far. This is currently specific for encore and
  216. sun unix, with a default unix which would work on any 4.2BSD derived
  217. system. The other specific case is vms, and the last default has
  218. myruntime calling the time function, which usually means an integer
  219. number of realtime seconds. Nested ifdef's are very difficult to
  220. read of course. Sorry.
  221.  
  222. There is a bit of type casting in close_open_files and vload. The
  223. pname of an un-interned symbol is used as a pointer to FILE. This
  224. saves the code (a conser, a print case, and two gc cases) of defining
  225. a new data type for keeping track of binary data. Are there any machines
  226. where a pointer to char and a pointer to FILE are different?
  227.  
  228. There should be no problem with integers vs longs on short integer
  229. machines.
  230.  
  231. [Adding new SUBRS:]
  232.  (1) choose a name for it and add a forward declaration to the group
  233.      of various forward declarations near the beginning of the file.
  234.      The arguments must all be of type struct obj *, as is the return value.
  235.  (2) choose a lisp name and add a call to init_subr for it near all the
  236.      other calls in the procedure init_subrs. The first argument to init_subr
  237.      is the lisp name as a string, the second is a subr type code, and the
  238.      third is the name of the C coded procedure.
  239.      Dont bother with special forms without detailed understanding of how
  240.      msubrs in particular work. Use tc_subr_0 to get zero arguments through
  241.      tc_subr_3 for three arguments. Otherwise use tc_lsubr to receive a
  242.      single list of evaluated arguments.
  243.  (3) If you need to use stack lisp variables (you can always use
  244.      calls to cintern to get a handle on a symbol however) these must
  245.      be declared before the procedure scan_registers, always init to NIL,
  246.      and explicitely relocated in the scan_register procedure.
  247.  (4) inside your subr you need not worry about gc relocating since the gc
  248.      wont go off except at toplevel. You must of course be conservative
  249.      about your using of cons and flocons if your procedure will have to 
  250.      run long. Since symbol pnames ARE NOT RELOCATED you do not have to worry
  251.      about passing the pname string of a symbol to a system procedure that will
  252.      keep an unprotected pointer to it, even across toplevel calls to GC.
  253.      However, do not pass pointers to things such as &(FLONM(x)) if the
  254.      called procedure is going to keep that pointer in its internal storage
  255.      after it returns. Never pass pointers to lisp data to system routines
  256.      which may asynchronously go off (such as VMS AST's) at a later time
  257.      and use that pointer data. Instead you may want to cons an uninterned
  258.      symbol, malloc some data, and set the symbol PNAME to that data
  259.      if you want to keep track of it. Example kludge:
  260.       m = "Binary_DATA_"
  261.       x = (char *) malloc(3+strlen(m)+1+data_needed);
  262.       y = symcons(x,NIL);
  263.       sprintf(x,"%s%3d",m,data_needed);
  264.      The print name of the symbol Y will be harmless looking enough,
  265.      because of the zero terminating byte put in by sprintf,
  266.      but the C programmer will know that its pname points to more
  267.      interesting goodies inside. The VCELL part of the symbol should
  268.      come in handy for storing other things, like an alist of object
  269.      properties perhaps. This just goes to show you that you dont need
  270.      to go through a lot of trouble, like definining new primitive lisp
  271.      object types and modifying the printer, to get something useful.
  272.  
  273.  
  274.