;; Dribble of # started 2009-02-05 12:13:48 # [13]> (defun c-a (x) (cond ((null x) 0) ((not (listp x)) 1) (t (+ (if (atom (first x)) 1 (c-a (first x))) (c-a (rest x)))))) WARNING: DEFUN/DEFMACRO: redefining C-A; it was traced! C-A [14]> (trace c-a) ;; Tracing function C-A. (C-A) [15]> (c-a '(1 2 3)) 1. Trace: (C-A '(1 2 3)) 2. Trace: (C-A '(2 3)) 3. Trace: (C-A '(3)) 4. Trace: (C-A 'NIL) 4. Trace: C-A ==> 0 3. Trace: C-A ==> 1 2. Trace: C-A ==> 2 1. Trace: C-A ==> 3 3 [16]> (c-a t) 1. Trace: (C-A 'T) 1. Trace: C-A ==> 1 1 [17]> (c-a '(1 2 3 (4 5 6 (7 8 9)) (()))) 1. Trace: (C-A '(1 2 3 (4 5 6 (7 8 9)) (NIL))) 2. Trace: (C-A '(2 3 (4 5 6 (7 8 9)) (NIL))) 3. Trace: (C-A '(3 (4 5 6 (7 8 9)) (NIL))) 4. Trace: (C-A '((4 5 6 (7 8 9)) (NIL))) 5. Trace: (C-A '(4 5 6 (7 8 9))) 6. Trace: (C-A '(5 6 (7 8 9))) 7. Trace: (C-A '(6 (7 8 9))) 8. Trace: (C-A '((7 8 9))) 9. Trace: (C-A '(7 8 9)) 10. Trace: (C-A '(8 9)) 11. Trace: (C-A '(9)) 12. Trace: (C-A 'NIL) 12. Trace: C-A ==> 0 11. Trace: C-A ==> 1 10. Trace: C-A ==> 2 9. Trace: C-A ==> 3 9. Trace: (C-A 'NIL) 9. Trace: C-A ==> 0 8. Trace: C-A ==> 3 7. Trace: C-A ==> 4 6. Trace: C-A ==> 5 5. Trace: C-A ==> 6 5. Trace: (C-A '((NIL))) 6. Trace: (C-A '(NIL)) 7. Trace: (C-A 'NIL) 7. Trace: C-A ==> 0 6. Trace: C-A ==> 1 6. Trace: (C-A 'NIL) 6. Trace: C-A ==> 0 5. Trace: C-A ==> 1 4. Trace: C-A ==> 7 3. Trace: C-A ==> 8 2. Trace: C-A ==> 9 1. Trace: C-A ==> 10 10 [18]> (defun last5 (x) (cond ((null (rest (rest (rest (rest (rest x)))))) x) (t (last5 (rest x))))) LAST5 [19]> (last5 '(1 2 3 4 5 6 7 8 9 10 11)) (7 8 9 10 11) [20]> (trace last5) ;; Tracing function LAST5. (LAST5) [21]> (last5 '(1 2 3 4 5 6 7 8 9 10 11)) 1. Trace: (LAST5 '(1 2 3 4 5 6 7 8 9 10 11)) 2. Trace: (LAST5 '(2 3 4 5 6 7 8 9 10 11)) 3. Trace: (LAST5 '(3 4 5 6 7 8 9 10 11)) 4. Trace: (LAST5 '(4 5 6 7 8 9 10 11)) 5. Trace: (LAST5 '(5 6 7 8 9 10 11)) 6. Trace: (LAST5 '(6 7 8 9 10 11)) 7. Trace: (LAST5 '(7 8 9 10 11)) 7. Trace: LAST5 ==> (7 8 9 10 11) 6. Trace: LAST5 ==> (7 8 9 10 11) 5. Trace: LAST5 ==> (7 8 9 10 11) 4. Trace: LAST5 ==> (7 8 9 10 11) 3. Trace: LAST5 ==> (7 8 9 10 11) 2. Trace: LAST5 ==> (7 8 9 10 11) 1. Trace: LAST5 ==> (7 8 9 10 11) (7 8 9 10 11) [22]> (last5 '(1` 2 3)) 1. Trace: (LAST5 '(1 `2 3)) 1. Trace: LAST5 ==> (1 `2 3) (1 `2 3) [23]> (defun flip (x) (list (first x) (if (atom (third x)) (third x) (flip (third x))) (if (atom (second x)) (second x) (flip (second x))))) FLIP [24]> (trace flip) ;; Tracing function FLIP. (FLIP) [25]> (flip '(1 (2 3 4) ())) 1. Trace: (FLIP '(1 (2 3 4) NIL)) 2. Trace: (FLIP '(2 3 4)) 2. Trace: FLIP ==> (2 4 3) 1. Trace: FLIP ==> (1 NIL (2 4 3)) (1 NIL (2 4 3)) [26]> (flip '(1 (2 (3 4 5) (10 11 12)) (6 () (7 () 8)))) 1. Trace: (FLIP '(1 (2 (3 4 5) (10 11 12)) (6 NIL (7 NIL 8)))) 2. Trace: (FLIP '(6 NIL (7 NIL 8))) 3. Trace: (FLIP '(7 NIL 8)) 3. Trace: FLIP ==> (7 8 NIL) 2. Trace: FLIP ==> (6 (7 8 NIL) NIL) 2. Trace: (FLIP '(2 (3 4 5) (10 11 12))) 3. Trace: (FLIP '(10 11 12)) 3. Trace: FLIP ==> (10 12 11) 3. Trace: (FLIP '(3 4 5)) 3. Trace: FLIP ==> (3 5 4) 2. Trace: FLIP ==> (2 (10 12 11) (3 5 4)) 1. Trace: FLIP ==> (1 (6 (7 8 NIL) NIL) (2 (10 12 11) (3 5 4))) (1 (6 (7 8 NIL) NIL) (2 (10 12 11) (3 5 4))) [27]> (defun f-f (x) (let ((res nil)) (dolist (el x) (setf res (cons (first el)) res)) (reverse res))) *** - SETF called with an odd number of arguments: (SETF RES (CONS (FIRST EL)) RES) Break 1 [28]> :a [29]> (defun f-f (x) (let ((res nil)) (dolist (el x) (setf res (cons (first el) res))) (reverse res))) F-F [30]> (f-f '((1 2) (A B) (3 4))) (1 A 3) [31]> (trace f-f) ;; Tracing function F-F. (F-F) [32]> (f-f '((1 2) (A B) (3 4))) 1. Trace: (F-F '((1 2) (A B) (3 4))) 1. Trace: F-F ==> (1 A 3) (1 A 3) [33]> (defun funny_last (x) (mapcar #'(lambda (y) (first (last y))) x)) FUNNY_LAST [34]> (defun f-l (x) (mapcar #'(lambda (y) (last y)) x)) F-L [35]> (f-l '((1 2) (A B) (3 4))) ((2) (B) (4)) [36]> (defun f-l (x) (mapca #'(lambda (y) (last y)) x)) F-L [37]> (defun f-l (x) (mapcan #'(lambda (y) (last y)) x)) F-L [38]> (f-l '((1 2) (A B) (3 4))) (2 B 4) [39]> (defun funny_len (x) (apply #'+ (mapcar #'(lambda (y) (length y)) x))) FUNNY_LEN [40]> (defun f_l (x) (reduce #'+ (mapcar #'(lambda (y) (length y)) x))) F_L [41]> (F_L '((1) (2 2) (3 3 3) (4 4 4 4))) 10 [42]> (defun f_l_wrong (x) (mapcar #'(lambda (y) (length y)) x)) F_L_WRONG [43]> (F_L_WRONG '((1) (2 2) (3 3 3) (4 4 4 4))) (1 2 3 4) [44]> (defun a-n (x) ;; add numbers recursively in a nested structure (cond ((atom x) (if (numberp x) x 0)) (t (+ (a-n (first x)) (a-n (rest x)))))) A-N [45]> (a-n 1) 1 [46]> (a-n '(1 2 3)) 6 [47]> (a-n '(1 2 (3 4 5 6))) 21 [48]> (a-n '((7 8) 1 2 (3 4 5 6))) 36 [49]> (a-n '((7 8) 1 2 (3 4 5 6) nil)) 36 [50]> (a-n '((7 8) 1 2 (3 4 5 6) nil 'HELLO)) 36 [51]> (trace a-n) ;; Tracing function A-N. (A-N) [52]> (a-n '((7 8) 1 2 (3 4 5 6) nil 'HELLO)) 1. Trace: (A-N '((7 8) 1 2 (3 4 5 6) NIL 'HELLO)) 2. Trace: (A-N '(7 8)) 3. Trace: (A-N '7) 3. Trace: A-N ==> 7 3. Trace: (A-N '(8)) 4. Trace: (A-N '8) 4. Trace: A-N ==> 8 4. Trace: (A-N 'NIL) 4. Trace: A-N ==> 0 3. Trace: A-N ==> 8 2. Trace: A-N ==> 15 2. Trace: (A-N '(1 2 (3 4 5 6) NIL 'HELLO)) 3. Trace: (A-N '1) 3. Trace: A-N ==> 1 3. Trace: (A-N '(2 (3 4 5 6) NIL 'HELLO)) 4. Trace: (A-N '2) 4. Trace: A-N ==> 2 4. Trace: (A-N '((3 4 5 6) NIL 'HELLO)) 5. Trace: (A-N '(3 4 5 6)) 6. Trace: (A-N '3) 6. Trace: A-N ==> 3 6. Trace: (A-N '(4 5 6)) 7. Trace: (A-N '4) 7. Trace: A-N ==> 4 7. Trace: (A-N '(5 6)) 8. Trace: (A-N '5) 8. Trace: A-N ==> 5 8. Trace: (A-N '(6)) 9. Trace: (A-N '6) 9. Trace: A-N ==> 6 9. Trace: (A-N 'NIL) 9. Trace: A-N ==> 0 8. Trace: A-N ==> 6 7. Trace: A-N ==> 11 6. Trace: A-N ==> 15 5. Trace: A-N ==> 18 5. Trace: (A-N '(NIL 'HELLO)) 6. Trace: (A-N 'NIL) 6. Trace: A-N ==> 0 6. Trace: (A-N '('HELLO)) 7. Trace: (A-N ''HELLO) 8. Trace: (A-N 'QUOTE) 8. Trace: A-N ==> 0 8. Trace: (A-N '(HELLO)) 9. Trace: (A-N 'HELLO) 9. Trace: A-N ==> 0 9. Trace: (A-N 'NIL) 9. Trace: A-N ==> 0 8. Trace: A-N ==> 0 7. Trace: A-N ==> 0 7. Trace: (A-N 'NIL) 7. Trace: A-N ==> 0 6. Trace: A-N ==> 0 5. Trace: A-N ==> 0 4. Trace: A-N ==> 18 3. Trace: A-N ==> 20 2. Trace: A-N ==> 21 1. Trace: A-N ==> 36 36 [53]> (dribble) ;; Dribble of # finished 2009-02-05 13:12:03