TST M948-371-P. FOX-EXERCISE 1 DEFINE (((COLLAPSE,(LAMBDA,(L),(COND, ((ATOM,L), (CONS,L,NIL)) ((NULL,(CDR,L)), (COND,((ATOM,(CAR,L)),L),(T,(COLLAPSE,(CAR,L))))) (T,(APPEND,(COLLAPSE,(CAR,L)),(COLLAPSE,(CDR,L)))) ))))) () COLLAPSE ((((A,B),((C))),((D,(E,F)),(G),((H))))) () COLLAPSE ((A,(B,(C,(D,(E))),F,(G,(H,J))))) () COLLAPSE ((((((A),B),C),D),E)) () STOP))))))))))STOP FIN M948-371-P. FOX-EXERCISE 1Notes:
- This example and the quotes below were taken from the LISP I manual by Phyllis Fox. The output from the program contains these two lines:
APPLY OPERATOR AS OF SEPTEMBER 1, 1959
THE TIME IS NOW 2/16 1139.5
so we can date the sample run.
- Each line above was punched on a separate card.
SET) card indicates the beginning of the program. The
FINcard indicates the end.
- This is followed by triplets of the form <function>, <argument-list>, <environment>. Instead of
STOPcard has lots of extra close parens in order to keep the reader from consuming the entire card deck if the programmer didn't correctly close all the parens.
— “The read program reads until it finds the correct number of final parenthesis.”
- S-expressions were originally supposed to have commas between the elements. The LISP I manual explains: “The commas in writing S-expressions may be omitted. This is an accident.” The author of the reader took a shortcut and treated whitespace as commas. “The current version of the read program interprets a blank (space) as a comma, so that no blanks are allowed within atomic symbols.”
- “LISP II will be able to handle both integers and floating point numbers, but in LISP I integers are not allowed. ... Numbers are brought into a LISP program by being defined within S-expressions, and they must always be quoted. For example, the following expression is correct,
- “Values of compiled functions are computed about 60 times faster than the S-expressions for the functions could be interpreted... After a function has been compiled, it can be used as if it had been defined, but of course it will run much faster than it would have as an interpreted expression.”