LISP I Programmer's Manual - Software Preservation Group
LISP I Programmer's Manual - Software Preservation Group
LISP I Programmer's Manual - Software Preservation Group
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
7 Example Exercises----Four exercises together with their solutions are given inthis section. The first two exercises involve formulatingLISE functions to treat list structures. In case the readershou::: like to try his hand at these before looking at the solution,the first two problems to be solved are:II(1) Formulate a function which will collapse" a liststructure, i,e. which will make a one-level list out of amultilevel list, so that, for example,(2) Formulate a function which will reverse a list, sothat, for example,(A,B,c,D) becomes (D,c,B,A)The third example shows how to define a length functionwhich w i l l operate more efficiently than the one defined inSection 4.4.The fourth example involves applying a function to itsarguments when the function is specified only at the time theAPPLY operator is in control.(1) Function to Collapse a List of ElementsThe function formulated below uses the function append,which is described in Chapter 9 and also in Chapter 2. Roughlyspeaking append makes one list out of two, so that, forexample,