Contents    Page-10    Prev    Next    Page+10    Index   

Mapping in Lisp

Lisp has several functions that compute mappings from a linked list. The one we have seen is mapcar, which makes a new list whose elements are obtained by applying a specified function to each element ( car or first) of the input list(s).


>(defun square (x) (* x x))

>(mapcar 'square '(1 2 3 17))

(1 4 9 289)

>(mapcar '+ '(1 2 3 17) '(2 4 6 8))

(3 6 9 25)

>(mapcar '> '(1 2 3 17) '(2 4 6 8))

(NIL NIL NIL T)