Apply a callback to an array: Difference between revisions

Line 124:
[[Category:Common Lisp]]
 
;;Imperative: print 1, 2, 3, 4 and 5.
 
(map nil #'print #(1 2 3 4 5))
 
;;Functional: collect squares into new vector that is returned:
 
(defun square (x) (* x x))
(map 'vector #'square #(1 2 3 4 5))
 
;; destructiveDestructive, like the Java example; add 1 to every slot of vector *a*:
 
;; add 1 to every slot of vector *a*
(defvar *a* (vector 1 2 3))
(map-into *a* #'1+ *a*)
Anonymous user