10.07.2015 Views

An Introduction to Functional Programming Through Lambda Calculus

An Introduction to Functional Programming Through Lambda Calculus

An Introduction to Functional Programming Through Lambda Calculus

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.

- 196 -Lists may be constructed directly in form notation and this is the most common approach. Note, however, that listforms must be explicitly quoted <strong>to</strong> prevent function call evaluation. For example:(1 2 3)looks like a call <strong>to</strong> the function 1 with arguments 2 and 3, whereas:is the list:’(1 2 3)1 . (2 . (3 . nil))The primitive:listis a multi-argument version of cons but constructs a list ending with the empty list. For example:(list 1 2) ->(1 2)(list 1 2 3) ->(1 2 3)(list (list 1 2) (list 3 4)) ->((1 2) (3 4))(list (list 1 2) (list 3 4) (list 5 6)) ->((1 2) (3 4) (5 6))The primitive:listpreturns true if its argument is a list.For example:(listp ’(1 2 3 4)) ->t10.11. List selectionThe head of a LISP list is known as the car and the tail as the cdr. This is from the original IBM 704 implementationwhere a list head was processed as the ‘Contents of the Address Register’ and the tail as the ‘Contents of theDecrement Register’. Thus:caris the head selection primitive and:cdris the tail selection primitive. For example:

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

Saved successfully!

Ooh no, something went wrong!