From d7215f85cab4f8485b14ac072cc5d1932f045b9c Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Tue, 8 Nov 2022 17:15:13 +0100 Subject: [PATCH] Add Exercise 2.21 --- chapter2.lisp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/chapter2.lisp b/chapter2.lisp index f39c12a..fa14ef6 100644 --- a/chapter2.lisp +++ b/chapter2.lisp @@ -129,3 +129,15 @@ and upper bound." (if (null l) () (append (reverse-user (cdr l)) (list (car l))))) + +;; Exercise 2.21 +(defun square-list (items) + (if (null items) + nil + (cons (* (car items) (car items)) (square-list (cdr items))))) + +(defun square-list-map (items) + (map 'list #'(lambda (x) (* x x)) items)) + +(defun square-list-mapcar (items) + (mapcar #'(lambda (x) (* x x)) items))