10.07.2015 Views

LISP I Programmer's Manual - Software Preservation Group

LISP I Programmer's Manual - Software Preservation Group

LISP I Programmer's Manual - Software Preservation Group

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

y;T~adar[~]';hCompositions of - car and - cdr arise so frequently that manyexpressions can be written more concisely if we abbreviatecadr[x] for car[cdr[x]],caddr[xf for car[cdr[cdr[x]]],etc.Another useful abbreviation is to write list[el;e2; ...; e ]nfor cons[el; cons[ep; ...; cons[e,;~~~]. .. I]. This functiongives the list, (el,. ..,en), as a function of its elements.The following functions are useful when S-expressions areregarded as lists.1. append[x;y]append[x;y] = [null[x] @ @ cons[car[x];append[cdr[x];y~An example isappend[ (A$); (c,D,~)l = (A,B,c,D,E)1)2. among[x;ylThis predicate is true if the S-expression x occurs amongthe elements of the list y. We haveamong[x;y] = -null[y] h[equal[x; car[y] ]vamong[x; cdr[y] 1 13. pair[x;ylThis function gives the list of pairs of corresponding ele-ments of the lists x and y. We havepair[x;y] = [null[x] hnull[y] -+ ~~b;~atom[x]An example isA-atom[y] -+list[car[x];car[y]];pair[cdr[x];cdr[y] 1 ]]pair[ (A,B,c>; (x, (y,z),u)I = ((~3x1, (B, (Y,z)), (C,U))4. assoc[x;y]-one of the uts then assoc[x;y] is the corresponding v.assoc[x;y] = [caar[y] = x @ assoc[x;cdr[y]If y is a list of the form ( (u1,vl), . . . , (un, vn) ) and x iscons[We have1 ]-An example isassoc[x; ( (w, (A,B> 1, (x, (c,D) ) , (Y, (E,F) 1 11 = (0)5.. sublis[x;y]Here x is assumed to have the form of a list of pairs

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!