dribbling to file "/uc/cscfac/rao/lisp-class-2" NIL USER(2): (defun my-func (x) (+ x 1)) MY-FUNC USER(3): (my-func 1) 2 USER(4): (setq ff #'my-func) # USER(5): (setq car #'my-func) # USER(6): car # USER(7): (car '(1 2 3)) 1 USER(8): (funcall car 1) 2 USER(9): (funcall #'car 1) Error: Attempt to take the car of 1 which is not listp. [condition type: SIMPLE-ERROR] Restart actions (select using :continue): 0: Return to Top Level (an "abort" restart) 1: Abort # [1] USER(10): :res USER(11): (funcall #'car '(1 2 3)) 1 USER(12): (funcall 'car '(1 2 3)) 1 USER(13): ff # USER(14): (funcall ff 5) 6 USER(15): ;;check out the differences between funcall and applly 1 1 USER(16): (mapcar #'my-func '(1 2 3 4)) (2 3 4 5) USER(17): (trace my-func) (MY-FUNC) USER(18): (MY-FUNC) 0: (MY-FUNC) Error: MY-FUNC got 0 args, wanted 1 arg. [condition type: PROGRAM-ERROR] Restart actions (select using :continue): 0: Return to Top Level (an "abort" restart) 1: Abort # [1] USER(19): :res 0: returned-by-throwing NIL USER(20): (mapcar #'my-func '(1 2 3 4)) 0: (MY-FUNC 1) 0: returned 2 0: (MY-FUNC 2) 0: returned 3 0: (MY-FUNC 3) 0: returned 4 0: (MY-FUNC 4) 0: returned 5 (2 3 4 5) USER(21): (reduce #'+ '(1 2 3 4 5)) 15 USER(22): ((lambda (x) (+ x 1)) 5) 6 USER(23): (find '1 '(2 3 4 1 5)) 1 USER(24): (find '(1 2) '((2 3) (4 5) (1 2) (6) 7)) NIL USER(25): (setq j '( 1 2)) (1 2) USER(26): (setq k '( 1 2)) (1 2) USER(27): (setq l j) (1 2) USER(28): (eq j k) NIL USER(29): (eq l j) T USER(30): (equal j k) T USER(31): (find '(1 2) '((2 3) (4 5) (1 2) (6) 7) :test #'equal) (1 2) USER(32): (defstruct person name age nose-color) PERSON USER(33): (setq p-list (list (make-person :name rao :age 50 :nose-color 'green) (make-person :name 'ullas :age 70 :nose-color 'yellow) (make-person :name 'rudolph :age 100000 :nose-color 'red))) Error: Attempt to take the value of the unbound variable `RAO'. [condition type: UNBOUND-VARIABLE] Restart actions (select using :continue): 0: Try evaluating RAO again. 1: Set the symbol-value of RAO and use its value. 2: Use a value without setting RAO. 3: Return to Top Level (an "abort" restart) 4: Abort # [1] USER(34): :res USER(35): (setq rao 'rao) RAO USER(36): (setq p-list (list (make-person :name rao :age 50 :nose-color 'green) (make-person :name 'ullas :age 70 :nose-color 'yellow) (make-person :name 'rudolph :age 100000 :nose-color 'red))) (#S(PERSON :NAME RAO :AGE 50 :NOSE-COLOR GREEN) #S(PERSON :NAME ULLAS :AGE 70 :NOSE-COLOR YELLOW) #S(PERSON :NAME RUDOLPH :AGE 100000 :NOSE-COLOR RED)) USER(37): p-list (#S(PERSON :NAME RAO :AGE 50 :NOSE-COLOR GREEN) #S(PERSON :NAME ULLAS :AGE 70 :NOSE-COLOR YELLOW) #S(PERSON :NAME RUDOLPH :AGE 100000 :NOSE-COLOR RED)) USER(38): (find 'red p-list :key #'person-nose-color) #S(PERSON :NAME RUDOLPH :AGE 100000 :NOSE-COLOR RED) USER(39): (setq m *) #S(PERSON :NAME RUDOLPH :AGE 100000 :NOSE-COLOR RED) USER(40): ;;star is used to access the last returned value 1 1 USER(41): (person-name m) RUDOLPH USER(42): (find 20 p-list :key #'person-age :test #'(lambda (x y) (eq x (- y 50))) ) #S(PERSON :NAME ULLAS :AGE 70 :NOSE-COLOR YELLOW) USER(43): (remove 20 p-list :key #'person-age :test #'(lambda (x y) (eq x (- y 50))) ) (#S(PERSON :NAME RAO :AGE 50 :NOSE-COLOR GREEN) #S(PERSON :NAME RUDOLPH :AGE 100000 :NOSE-COLOR RED)) USER(44): (setq mm *) (#S(PERSON :NAME RAO :AGE 50 :NOSE-COLOR GREEN) #S(PERSON :NAME RUDOLPH :AGE 100000 :NOSE-COLOR RED)) USER(45): p-list (#S(PERSON :NAME RAO :AGE 50 :NOSE-COLOR GREEN) #S(PERSON :NAME ULLAS :AGE 70 :NOSE-COLOR YELLOW) #S(PERSON :NAME RUDOLPH :AGE 100000 :NOSE-COLOR RED)) USER(46): (delete 20 p-list :key #'person-age :test #'(lambda (x y) (eq x (- y 50))) ) (#S(PERSON :NAME RAO :AGE 50 :NOSE-COLOR GREEN) #S(PERSON :NAME RUDOLPH :AGE 100000 :NOSE-COLOR RED)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; The definition of Find that allows this to happen (defun find (elt list &key (key #'identity) (test #'eq)) (if (funcall test elt (funcall key (first list))) (first list) (find elt (rest list) :key key :test test))) ;;notice that the recursive call to find happens with ;;with the key word arguments --so the user supplied ;;key-word arguments are passed on to recursive calls ;;;;I forgot to do this in my class version ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; USER(47): (setq mmm *) (#S(PERSON :NAME RAO :AGE 50 :NOSE-COLOR GREEN) #S(PERSON :NAME RUDOLPH :AGE 100000 :NOSE-COLOR RED)) USER(48): p-list (#S(PERSON :NAME RAO :AGE 50 :NOSE-COLOR GREEN) #S(PERSON :NAME RUDOLPH :AGE 100000 :NOSE-COLOR RED)) USER(49): ;;delete is destructive while ;;remove is non-destructive USER(49): (setq j 'rao) RAO USER(50): i Error: Attempt to take the value of the unbound variable `I'. [condition type: UNBOUND-VARIABLE] Restart actions (select using :continue): 0: Try evaluating I again. 1: Use :I instead. 2: Set the symbol-value of I and use its value. 3: Use a value without setting I. 4: Return to Top Level (an "abort" restart) 5: Abort # [1] USER(51): :res USER(52): (or j i) RAO USER(53): (defun fact (x) (if (zerop x) 1 (* (first x) (fact (rest x))))) FACT USER(54): (fact 5) Error: Attempt to take the car of 5 which is not listp. [condition type: SIMPLE-ERROR] Restart actions (select using :continue): 0: Return to Top Level (an "abort" restart) 1: Abort # [1] USER(55): :res USER(56): (defun fact (x) (if (zerop x) 1 (* x (fact (- x 1))))) FACT USER(57): (fact 5) 120 USER(58): (time (loop for x from 1 to 10 do (fact x))) ; cpu time (non-gc) 10 msec user, 10 msec system ; cpu time (gc) 0 msec user, 0 msec system ; cpu time (total) 10 msec user, 10 msec system ; real time 19 msec ; space allocation: ; 947 cons cells, 0 symbols, 2,960 other bytes, 0 static bytes NIL USER(59): ;;talked about back-quote macro 1 1 USER(60): (dribble)