Docsity

Forms, Functions and Functionals in Lisp - Lecture Slides | CSE 891, Study notes of Computer Science

Toggle sidebar
bg1

 
 



!"
#
$%

! 
 
#&λ' 

( 
λ

λ

 !

)'


(lambda lambda-list body)
lambda-list 
body *+ 
,
-
!"

./ 
 *
0!
 
!.
(11
"
2 3
!
–#’name name

1
#.
funcall 
 
( 
(funcall #’= 2 2)
T
.

(funcall = 2 2)
pf3
pf4

Partial preview of the text

Download Forms, Functions and Functionals in Lisp - Lecture Slides | CSE 891 and more Study notes Computer Science in PDF only on Docsity!

            !      "

#     $^ %

               !      

  λ          λ   

(lambda lambda-list body )

 lambda-list    

body *   +

  • #’name       name          1

   funcall    

(funcall #’= 2 2)  T

(funcall = 2 2)

(setf square #’(lambda (x) ( x x)))*

(funcall square 3)  9

(defun mapcar (f l) (cond ((null l) nil) (t (cons (funcall f (car l)) (mapcar f (cdr l))))))

(mapcar #’oddp ’(1 2 3 4 5))  (T NIL T NIL T)

; !         !  .      1

(11 (mapcar #’= ’(1 2 3) ’(3 2 1))  (NIL T NIL)

(defun f (g) #’(lambda (x y) (funcall g y x)))

(funcall (f #’-) (2 3))  1

    !          4        !  !  

  &    <   !       4 <   ! 7  8 !                 ,      =# 

D

(defun p () (p)) ;; infinite loop (defun test (x y) (cond ((= x 0) 0) (t y))) (test 0 (p))

: ! (test 0 (p))  (test 0 (p)) (^)  (test 0 (p))  …

5 (test 0 (p))  (cond ((= 0 0) 0) (t (p)))  0

(defun add (x y) (+ x y))

(add (add 3 4) (car (cons 20 nil)))

 2      add

!       defun