BSD 4_1c_2 release
[unix-history] / usr / src / ucb / lisp / doc / ch1.n
CommitLineData
17ce9497
C
1." $Header: /na/franz/doc/RCS/ch1.n,v 1.1 83/01/31 07:07:16 jkf Exp $
2.Lc \s+2F\s-2RANZ\s0\ L\s-2ISP\s0\s-2 1
3.sh 2
4.Fr \*[\(dg\*]
5was created as a tool to further research in symbolic and
6algebraic manipulation,
7artificial intelligence,
8and programming languages at the University of California
9at Berkeley.
10.(f
11\*[\(dg\*]It is rumored that this name has something to do with Franz
12Liszt [F\fIr\fPa\*:nts List] (1811-1886) a Hungarian composer
13and keyboard virtuoso.
14These allegations have never been proven.
15.)f
16Its roots are in the PDP-11 Lisp system which originally came
17from Harvard.
18As it grew it adopted features of Maclisp and Lisp Machine Lisp
19which enables our work to be shared with colleagues at
20the Laboratory for Computer Science at M.I.T.
21Substantial compatibility with other Lisp dialects
22(Interlisp, UCILisp, CMULisp) is achieved by
23means of support packages and compiler switches.
24.Fr
25is written almost entirely in the programming language C.
26A small part is written in the assembler language for the current
27host machine, a VAX 11/780, and part is written in Lisp.
28Because
29.Fr
30is written in C, it is relatively portable and easy to comprehend.
31.pp
32.Fr
33is capable of running large lisp programs in a timesharing environment,
34has facilities for arrays and user defined structures,
35has a user controlled reader with character and word macro capabilities,
36and can interact directly with compiled Lisp, C, Fortran, and Pascal code.
37.pp
38This document is a reference manual for the
39.Fr
40system.
41It is not a Lisp primer or introduction to the language.
42Some parts will be of interest only to those maintaining
43.Fr
44at their computer site.
45This document is divided into four Movements.
46In the first one we will attempt to describe the language of
47.Fr
48precisely and completely as it now stands (Opus 38, April 1982).
49In the second Movement we will look at the reader, function types,
50arrays and exception handling.
51In the third Movement we will look at several large support packages
52written to help the
53.Fr
54user, namely the trace package, compiler, fixit and stepping package.
55Finally the fourth movement contains an index into the other movements.
56In the rest of this chapter we shall examine the data types of
57.Fr .
58The conventions used in the description of the
59.Fr
60functions will be given in section 1.4 -- it is very important that
61these conventions are understood.
62.sh 2 Data\ Types
63.Fr
64has eleven data types.
65In this section we shall look in detail at each type and if a type is
66divisible we shall look inside it.
67There is a Lisp function
68.i type
69which will return the type name of a lisp object.
70This is the official
71.Fr
72name for that type and we will use this name and this name only in
73the manual to avoid confusing the reader.
74The types are listed in terms of importance rather than alphabetically.
75.sh 3 lispval - - 0
76This is the name we use to describe any lisp object.
77The function
78.i type
79will never return `lispval'.
80.sh 3 symbol
81This object corresponds to a variable in most other programming languages.
82It may have a value or may be `unbound'.
83A symbol may be
84.i lambda
85.i bound
86meaning that its current value is stored
87away somewhere and the symbol is given a new value for the duration of a
88certain context.
89When the Lisp processor leaves that context, the
90symbol's current value is thrown
91away and its old value is restored.
92.sp .5v
93A symbol may also have a
94.i function
95.i binding .
96This function binding is static; it cannot be lambda bound.
97Whenever the symbol is used in the functional position of a Lisp expression
98the function binding of the symbol is examined (see Chapter 4 for more
99details on evaluation).
100.sp .5v
101A symbol may also have a
102.i property
103.i list ,
104another static data structure.
105The property list consists of a list of an even number of elements,
106considered to be grouped as pairs.
107The first element of the pair is the
108.i indicator
109the second the
110.i value
111of that indicator.
112.sp .5v
113Each symbol has a print name
114.i (pname)
115which is how this symbol is accessed from input and referred to
116on (printed) output.
117.sp .5v
118A symbol also has a hashlink used to link symbols together in the
119oblist -- this field is inaccessible to the lisp user.
120.sp .5v
121Symbols are created by the reader and by the functions
122.i concat ,
123.i maknam
124and their derivatives.
125Most symbols live on
126.Fr 's
127sole
128.i oblist ,
129and therefore two symbols with the same print name are
130usually the exact same object (they are
131.i eq ).
132Symbols which are not on the oblist are said to be
133.i uninterned.
134The function
135.i maknam
136creates uninterned symbols while
137.i concat
138creates
139.i interned
140ones.
141.sp 1v
142.TS
143box center ;
144c | c | c | c .
145Subpart name Get value Set value Type
146
147=
148value eval set lispval
149 setq
150_
151property plist setplist list or nil
152list get putprop
153_
154function getd putd array, binary, list
155binding def or nil
156_
157print name get_pname string
158_
159hash link
160.TE
161.sh 3 list
162A list cell has two parts, called the car and cdr.
163List cells are created by the function
164.i cons .
165.sp 1v
166.TS
167box center ;
168c | c | c | c .
169Subpart name Get value Set value Type
170
171=
172car car rplaca lispval
173_
174cdr cdr rplacd lispval
175.TE
176.sh 3 binary
177This type acts as a function header for machine coded functions.
178It has two parts, a pointer to the start of the function and a
179symbol whose print name describes the
180argument
181.i discipline .
182The discipline (if
183.i lambda ,
184.i macro
185or
186.i nlambda )
187determines whether the arguments to this function will be evaluated
188by the caller
189before this function is called.
190If the discipline is a string (either
191"\fIsubroutine\fP",
192"\fIfunction\fP",
193"\fIinteger-function\fP",
194or
195"\fIreal-function\fP")
196then this function is
197a foreign subroutine or function (see \(sc8.4 for more details on this).
198Although the type of the
199.i entry
200field of a binary type object is either string or fixnum,
201the object pointed to
202is actually a sequence of machine instructions.
203.br
204Objects of type binary are created by
205.i mfunction .
206.sp 1v
207.TS
208box center ;
209c | c | c | c .
210Subpart name Get value Set value Type
211
212=
213entry getentry string or fixnum
214_
215discipline getdisc putdisc symbol or fixnum
216.TE
217.sh 3 fixnum
218A fixnum is an integer constant in the range \(mi2\*[31\*] to
2192\*[31\*]\(mi1.
220Small fixnums (-1024 to 1023) are stored in a special table so they needn't be
221allocated each time one is needed.
222.sh 3 flonum
223A flonum is a double precision real number in the range
224\(+-2.9\(mu10\*[-37\*] to \(+-1.7\(mu10\*[38\*].
225There are approximately sixteen decimal digits of precision.
226.sh 3 bignum
227A bignum is an integer of potentially unbounded size.
228When integer arithmetic exceeds the limits mentioned above the calculation
229is automatically done with bignums.
230Should calculation with bignums give a result which can be represented
231as a fixnum, then the fixnum representation will be used\*[\(dg\*].
232.(f
233\*[\(dg\*]The current algorithms for integer arithmetic operations will return
234(in certain cases) a result
235between \(+-2\*[30\*] and 2\*[31\*] as a bignum although this
236could be represented as a fixnum.
237.)f
238This contraction is known as
239.i integer
240.i normalization .
241Many Lisp functions assume that integers are normalized.
242Bignums are composed of a sequence of
243.b list
244cells and a cell known as an
245.b sdot.
246The user should consider a
247.b bignum
248structure indivisible and use functions such as
249.i haipart ,
250and
251.i bignum-leftshift
252to extract parts of it.
253.sh 3 string
254A string is a null terminated sequence of characters.
255Most functions of symbols which operate on the symbol's print name will
256also work on strings.
257The default reader syntax is set so that
258a sequence of characters surrounded by double quotes is a string.
259.sh 3 port
260A port is a structure which the system I/O routines can reference to
261transfer data between the Lisp system and external media.
262Unlike other Lisp objects there are a very limited number of ports (20).
263Ports are allocated by
264.i infile
265and
266.i outfile
267and deallocated by
268.i close
269and
270.i resetio .
271The
272.i print
273function prints a port as a percent sign followed by the name of the file it
274is connected to.
275The file names $stdin, $stdout and $stderr refer to the standard input,
276output and error files.
277.sh 3 array
278Arrays are rather complicated types and are fully described in
279Chapter 9.
280An array consists of a block of contiguous data, a function
281to access that data and auxiliary fields for use by the accessing
282function.
283Since an array's accessing function is created by the user, an array can
284have any form the user chooses (e.g. n-dimensional, triangular, or hash
285table).
286.br
287Arrays are created by the function
288.i marray .
289.sp 1v
290.TS
291box center ;
292c | c | c | c .
293Subpart name Get value Set value Type
294
295=
296access function getaccess putaccess binary, list
297 or symbol
298_
299auxiliary getaux putaux lispval
300_
301data arrayref replace block of contiguous
302 set lispval
303_
304length getlength putlength fixnum
305_
306delta getdelta putdelta fixnum
307.TE
308.sh 3 value
309A value cell contains a pointer to a lispval.
310This type is used mainly by arrays of general lisp objects.
311Value cells are created with the
312.i ptr
313function.
314A value cell containing a pointer to the symbol `foo' is printed
315as `(ptr\ to)foo'
316.sh 3 hunk
317A hunk is a vector of from 1 to 128 lispvals.
318Once a hunk is created (by
319.i hunk
320or
321.i makhunk )
322it cannot grow or shrink.
323The access time for an element of a hunk is slower than a list cell element
324but faster than an array.
325Hunks are really only allocated in sizes which are powers of two, but
326can appear to the user to be any size in the 1 to 128 range.
327Users of hunks must realize that \fI(not\ (atom\ 'lispval))\fP
328will return true if
329.i lispval
330is a hunk.
331Most lisp systems do not have a direct test for a list cell and instead use
332the above test and assume that
333a true result means
334.i lispval
335is a list cell.
336In
337.Fr
338you can use
339.i dtpr
340to check for a list cell.
341Although hunks are not list cells, you can still access the first two
342hunk elements with
343.i cdr
344and
345.i car
346and you can access any hunk element with
347.i cxr \*[\(dg\*].
348.(f
349\*[\(dg\*]In a hunk, the function
350.i cdr
351references the first element
352and
353.i car
354the second.
355.)f
356You can set the value of the first two elements of a hunk with
357.i rplacd
358and
359.i rplaca
360and you can set the value of any element of the hunk with
361.i rplacx .
362A hunk is printed by printing its contents surrounded by { and }.
363However a hunk cannot be read in in this way in the standard lisp system.
364It is easy to write a reader macro to do this if desired.
365.sh 2 Documentation Conventions.
366The conventions used in the following chapters were designed to
367give a great deal of information in a brief
368space.
369The first line of a function description contains the function
370name in \fBbold\ face\fP and then lists the arguments, if any.
371The arguments all have names which begin with a letter or letters and
372an underscore.
373The letter(s) gives the allowable type(s) for that argument according to
374this table.
375.sp 1v
376.TS
377box center ;
378c | c
379l | l .
380Letter Allowable type(s)
381
382=
383g any type
384_
385s symbol (although nil may not be allowed)
386_
387t string
388_
389l list (although nil may be allowed)
390_
391n number (fixnum, flonum, bignum)
392_
393i integer (fixnum, bignum)
394_
395x fixnum
396_
397b bignum
398_
399f flonum
400_
401u function type (either binary or lambda body)
402_
403y binary
404_
405a array
406_
407v value
408_
409p port (or nil)
410_
411h hunk
412.TE
413
414In the first line of a function description,
415those arguments preceded by a quote mark are evaluated (usually
416before the function is called).
417The quoting convention is used so that we can give a name to the result of
418evaluating the argument and we can describe the allowable types.
419If an argument is not quoted it does not mean that that argument will
420not be evaluated, but rather that
421if it is evaluated, the time at which it is evaluated
422will be specifically mentioned in the function description.
423Optional arguments are surrounded by square brackets.
424An ellipsis means zero or more occurrences of an argument of the
425directly preceding
426type.