; SLIME 2006-11-26 CL-USER> (load "make.lisp")(demo :all) ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/demos.lisp" (written 01 FEB 2008 09:03:29 AM): ; compiling (EGS :ALL ...) ; compiling (DEFUN SHOW-OF ...) ; /home/ctobrey/opt/lisp/proj1/ch3/demos.fasl written ; compilation finished in 0:00:00 ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-1.lisp" (written 01 FEB 2008 09:01:25 AM): ; compiling (EGS :|3.1| ...) ; /home/ctobrey/opt/lisp/proj1/ch3/3-1.fasl written ; compilation finished in 0:00:00 ;;;; 1) using lisp to define a simple grammer ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAMES) (CADDAR NAMES)) ;GOT: LAST-NAME ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok 0 CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN STYLE-WARNING: redefining SHOW-OF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-1.lisp" (written 01 FEB 2008 09:08:22 AM): ; compiling (EGS :|3.1| ...) ; /home/ctobrey/opt/lisp/proj1/ch3/3-1.fasl written ; compilation finished in 0:00:01 ;;;; 1) using lisp to define a simple grammer ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAMES) (CADDAR NAMES)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last name function ;IN: (LAST-NAME (FIRST *NAMES*)) ; Evaluation aborted CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN STYLE-WARNING: redefining SHOW-OF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-1.lisp" (written 01 FEB 2008 09:09:59 AM): ; compiling (EGS :|3.1| ...) ; /home/ctobrey/opt/lisp/proj1/ch3/3-1.fasl written ; compilation finished in 0:00:00 ;;;; 1) using lisp to define a simple grammer ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAMES) (CADDAR NAMES)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last name function ;IN: (LAST-NAME *NAMES*) ;GOT: LEE ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok 0 CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN STYLE-WARNING: redefining SHOW-OF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-1.lisp" (written 01 FEB 2008 09:13:00 AM): ; ; compilation unit aborted ; caught 1 fatal ERROR condition compilation aborted because of fatal error: READ failure in COMPILE-FILE at character 0: end of file on # ; /home/ctobrey/opt/lisp/proj1/ch3/3-1.fasl written ; compilation finished in 0:00:00 ;;;; 1) using lisp to define a simple grammer ;IN: (DEMO 3.1) ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok 0 CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN STYLE-WARNING: redefining SHOW-OF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-1.lisp" (written 01 FEB 2008 09:15:13 AM): ; compiling (EGS :|3.1| ...) ; /home/ctobrey/opt/lisp/proj1/ch3/3-1.fasl written ; compilation finished in 0:00:00 ;;;; 1) using lisp to define a simple grammer ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok 0 CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN STYLE-WARNING: redefining SHOW-OF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-1.lisp" (written 01 FEB 2008 09:16:54 AM): ; compiling (EGS :|3.1| ...) ; /home/ctobrey/opt/lisp/proj1/ch3/3-1.fasl written ; compilation finished in 0:00:00 ;;;; 1) using lisp to define a simple grammer ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last-name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;;;; 4) last-name again ;IN: (LAST-NAME (SECOND *NAMES*)) ;GOT: (GRANT) ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok 0 CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN STYLE-WARNING: redefining SHOW-OF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-1.lisp" (written 01 FEB 2008 09:22:18 AM): ; compiling (EGS :|3.1| ...) ; /home/ctobrey/opt/lisp/proj1/ch3/3-1.fasl written ; compilation finished in 0:00:00 ;;;; 1) using lisp to define a simple grammer ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last-name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;;;; 4) last-name again ;IN: (LAST-NAME (SECOND *NAMES*)) ;GOT: (GRANT) ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok 0 CL-USER> (push (cons key val) a-list) ; in: LAMBDA NIL ; (SETQ A-LIST #:G1655) ; ; caught WARNING: ; undefined variable: A-LIST ; (CONS KEY VAL) ; ; caught WARNING: ; undefined variable: KEY ; ; caught WARNING: ; undefined variable: VAL ; ; caught WARNING: ; These variables are undefined: ; A-LIST KEY VAL ; ; compilation unit finished ; caught 4 WARNING conditions ; Evaluation aborted CL-USER> (defvar *list*) *LIST* CL-USER> (push (cons key val) *list*) ; in: LAMBDA NIL ; (CONS KEY VAL) ; ; caught WARNING: ; undefined variable: KEY ; ; caught WARNING: ; undefined variable: VAL ; ; caught WARNING: ; These variables are undefined: ; KEY VAL ; ; compilation unit finished ; caught 3 WARNING conditions ; Evaluation aborted CL-USER> (push (cons :key :val) *list*) ; Evaluation aborted CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/demos.lisp" (written 01 FEB 2008 09:27:08 AM): ; compiling (EGS :ALL ...) ; compiling (DEFUN SHOW-OF ...) ; /home/ctobrey/opt/lisp/proj1/ch3/demos.fasl written ; compilation finished in 0:00:01 STYLE-WARNING: redefining SHOW-OF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-1.lisp" (written 01 FEB 2008 09:33:40 AM): ; compiling (EGS :|3.1| ...) ; /home/ctobrey/opt/lisp/proj1/ch3/3-1.fasl written ; compilation finished in 0:00:00 ;;;; 1) A Guide to Lisp Style ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last-name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;;;; 4) last-name again ;IN: (LAST-NAME (SECOND *NAMES*)) ;GOT: (GRANT) ;ok ;;;; 5) be specific when setting a variable to a value ;IN: (SETQ X 1) ; in: LAMBDA NIL ; (SETQ X 1) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: 1 ;ok ;;;; 6) others prefer the consistency of using a single form ;IN: (SETF X 1) ; in: LAMBDA NIL ; (SETF X 1) ; ==> ; (SETQ X 1) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: 1 ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok 0 CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WAR(load "make.lisp")(demo :all)(push (cons :key :val) *list*)(load "make.lisp")(demo :all)NING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN STYLE-WARNING: redefining SHOW-OF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-1.lisp" (written 01 FEB 2008 09:35:56 AM): ; compiling (EGS :|3.1| ...) ; /home/ctobrey/opt/lisp/proj1/ch3/3-1.fasl written ; compilation finished in 0:00:00 ;;;; 1) A Guide to Lisp Style ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last-name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;;;; 4) last-name again ;IN: (LAST-NAME (SECOND *NAMES*)) ;GOT: (GRANT) ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok 0 CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/demos.lisp" (written 01 FEB 2008 10:05:28 AM): ; compiling (EGS :ALL ...); ; compilation unit aborted ; caught 1 fatal ERROR condition compilation aborted because of fatal error: READ failure in COMPILE-FILE: READER-ERROR at 776 (line 25, column 27) on #: unmatched close parenthesis ; /home/ctobrey/opt/lisp/proj1/ch3/demos.fasl written ; compilation finished in 0:00:00 ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-5.lisp" (written 01 FEB 2008 10:02:19 AM): ; compiling (DEFVAR *LI* ...) ; compiling (EGS :|3.5| ...) ; /home/ctobrey/opt/lisp/proj1/ch3/3-5.fasl written ; compilation finished in 0:00:00 ;;;; 1) A Guide to Lisp Style ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last-name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;;;; 4) last-name again ;IN: (LAST-NAME (SECOND *NAMES*)) ;GOT: (GRANT) ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok ;;;; 3) Functions on Sequences ;IN: (DEMO 3.5) ;;;; 1) Our test list ;IN: (*LI*) ; Evaluation aborted CL-USER> (setf li '(t d h)) ; in: LAMBDA NIL ; (SETF LI '(T D H)) ; ==> ; (SETQ LI '(T D H)) ; ; caught WARNING: ; undefined variable: LI ; ; caught WARNING: ; This variable is undefined: ; LI ; ; compilation unit finished ; caught 2 WARNING conditions (T D H) CL-USER> (li) ; Evaluation aborted CL-USER> (defvar *li* '(t d h)) *LI* CL-USER> (*li*) ; Evaluation aborted CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-5.lisp" (written 01 FEB 2008 10:11:10 AM): ; ; compilation unit aborted ; caught 1 fatal ERROR condition compilation aborted because of fatal error: READ failure in COMPILE-FILE at character 0: end of file on # ; /home/ctobrey/opt/lisp/proj1/ch3/3-5.fasl written ; compilation finished in 0:00:00 ;;;; 1) A Guide to Lisp Style ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last-name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;;;; 4) last-name again ;IN: (LAST-NAME (SECOND *NAMES*)) ;GOT: (GRANT) ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok ;ok 0 CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-5.lisp" (written 01 FEB 2008 10:12:37 AM): ; compiling (EGS :|3.5| ...) ; /home/ctobrey/opt/lisp/proj1/ch3/3-5.fasl written ; compilation finished in 0:00:00 ;;;; 1) A Guide to Lisp Style ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last-name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;;;; 4) last-name again ;IN: (LAST-NAME (SECOND *NAMES*)) ;GOT: (GRANT) ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok ;;;; 3) Functions on Sequences ;IN: (DEMO 3.5) ;;;; 1) our test list ;IN: (*NAMES*) ; Evaluation aborted CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-5.lisp" (written 01 FEB 2008 10:13:13 AM): ; compiling (EGS :|3.5| ...) ; /home/ctobrey/opt/lisp/proj1/ch3/3-5.fasl written ; compilation finished in 0:00:00 ;;;; 1) A Guide to Lisp Style ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last-name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;;;; 4) last-name again ;IN: (LAST-NAME (SECOND *NAMES*)) ;GOT: (GRANT) ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok ;;;; 3) Functions on Sequences ;IN: (DEMO 3.5) ;;;; 1) using nth to get the nth element in a list ;IN: (NTH 1 *NAMES*) ;GOT: (ULYSSES S. GRANT) ;ok ;;;; 2) using elt on a list ;IN: (ELT *LI* 1) ;GOT: RICHARD ;ok ;GOT: 0 ;ok 0 CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-5.lisp" (written 01 FEB 2008 10:15:09 AM): ; compiling (EGS :|3.5| ...) ; /home/ctobrey/opt/lisp/proj1/ch3/3-5.fasl written ; compilation finished in 0:00:00 ;;;; 1) A Guide to Lisp Style ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last-name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;;;; 4) last-name again ;IN: (LAST-NAME (SECOND *NAMES*)) ;GOT: (GRANT) ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok ;;;; 3) Functions on Sequences ;IN: (DEMO 3.5) ;;;; 1) using nth to get the nth element in a list ;IN: (NTH 1 *NAMES*) ;GOT: (ULYSSES S. GRANT) ;ok ;;;; 2) using elt on a list ;IN: (ELT *NAMES* 1) ;GOT: (ULYSSES S. GRANT) ;WANT: (ROBERT E. LEE) ;BAD !!!!!!!!!!!!!!!!!!! ;GOT: 1 ;ok 0 CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-5.lisp" (written 01 FEB 2008 10:16:15 AM): ; compiling (EGS :|3.5| ...) ; /home/ctobrey/opt/lisp/proj1/ch3/3-5.fasl written ; compilation finished in 0:00:00 ;;;; 1) A Guide to Lisp Style ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last-name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;;;; 4) last-name again ;IN: (LAST-NAME (SECOND *NAMES*)) ;GOT: (GRANT) ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok ;;;; 3) Functions on Sequences ;IN: (DEMO 3.5) ;;;; 1) using nth to get the nth element in a list ;IN: (NTH 1 *NAMES*) ;GOT: (ULYSSES S. GRANT) ;ok ;;;; 2) using elt on a list ;IN: (ELT *NAMES* 0) ;GOT: (ROBERT E. LEE) ;ok ;GOT: 0 ;ok 0 CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/demos.lisp" (written 01 FEB 2008 10:23:00 AM): ; compiling (EGS :ALL ...) ; compiling (EG (QUOTE #) ...); ; compilation unit aborted ; caught 1 fatal ERROR condition compilation aborted because of fatal error: READ failure in COMPILE-FILE: READER-ERROR at 769 (line 25, column 27) on #: unmatched close parenthesis ; /home/ctobrey/opt/lisp/proj1/ch3/demos.fasl written ; compilation finished in 0:00:00 ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-5.lisp" (written 01 FEB 2008 10:17:34 AM): ; compiling (EGS :|3.5| ...) ; /home/ctobrey/opt/lisp/proj1/ch3/3-5.fasl written ; compilation finished in 0:00:00 ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-6.lisp" (written 01 FEB 2008 10:22:18 AM): ; compiling (EGS :|3.6| ...) ; /home/ctobrey/opt/lisp/proj1/ch3/3-6.fasl written ; compilation finished in 0:00:01 ;;;; 1) A Guide to Lisp Style ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last-name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;;;; 4) last-name again ;IN: (LAST-NAME (SECOND *NAMES*)) ;GOT: (GRANT) ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok ;;;; 3) Functions on Sequences ;IN: (DEMO 3.5) ;;;; 1) using nth to get the nth element in a list ;IN: (NTH 1 *NAMES*) ;GOT: (ULYSSES S. GRANT) ;ok ;;;; 2) using elt on a list. gets the element at the specified zero-based ;IN: (ELT *NAMES* 0) ;GOT: (ROBERT E. LEE) ;ok ;GOT: 0 ;ok 0 CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN ;;;; 1) A Guide to Lisp Style ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last-name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;;;; 4) last-name again ;IN: (LAST-NAME (SECOND *NAMES*)) ;GOT: (GRANT) ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok ;;;; 3) Functions on Sequences ;IN: (DEMO 3.5) ;;;; 1) using nth to get the nth element in a list ;IN: (NTH 1 *NAMES*) ;GOT: (ULYSSES S. GRANT) ;ok ;;;; 2) using elt on a list. gets the element at the specified zero-based ;IN: (ELT *NAMES* 0) ;GOT: (ROBERT E. LEE) ;ok ;GOT: 0 ;ok 0 CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-6.lisp" (written 01 FEB 2008 10:24:13 AM): ; compiling (EGS :|3.6| ...) ; /home/ctobrey/opt/lisp/proj1/ch3/3-6.fasl written ; compilation finished in 0:00:00 ;;;; 1) A Guide to Lisp Style ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last-name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;;;; 4) last-name again ;IN: (LAST-NAME (SECOND *NAMES*)) ;GOT: (GRANT) ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok ;;;; 3) Functions on Sequences ;IN: (DEMO 3.5) ;;;; 1) using nth to get the nth element in a list ;IN: (NTH 1 *NAMES*) ;GOT: (ULYSSES S. GRANT) ;ok ;;;; 2) using elt on a list. gets the element at the specified zero-based ;IN: (ELT *NAMES* 0) ;GOT: (ROBERT E. LEE) ;ok ;GOT: 0 ;ok 0 ;;;; (egs :3.6 (eg '(setf state-table '((AL . Ala ... ;;;; '(setf state-table '((AL . Alabama)(AK . Alaska)( ... CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-6.lisp" (written 01 FEB 2008 10:27:10 AM): ; compiling (SETF STATE-TABLE ...) ; compiling (EGS :|3.6| ...) ; file: /home/ctobrey/opt/lisp/proj1/ch3/3-6.lisp ; in: SETF STATE-TABLE ; (SETF STATE-TABLE ; '((AL . ALABAMA) (AK . ALASKA) (AZ . ARIZONA) (AR . ARKANSAS))) ; --> SETQ ; ==> ; (SETQ STATE-TABLE ; '((AL . ALABAMA) (AK . ALASKA) (AZ . ARIZONA) (AR . ARKANSAS))) ; ; caught WARNING: ; undefined variable: STATE-TABLE ; ; caught WARNING: ; This variable is undefined: ; STATE-TABLE ; ; compilation unit finished ; caught 2 WARNING conditions ; /home/ctobrey/opt/lisp/proj1/ch3/3-6.fasl written ; compilation finished in 0:00:00 ;;;; 1) A Guide to Lisp Style ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last-name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;;;; 4) last-name again ;IN: (LAST-NAME (SECOND *NAMES*)) ;GOT: (GRANT) ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok ;;;; 3) Functions on Sequences ;IN: (DEMO 3.5) ;;;; 1) using nth to get the nth element in a list ;IN: (NTH 1 *NAMES*) ;GOT: (ULYSSES S. GRANT) ;ok ;;;; 2) using elt on a list. gets the element at the specified zero-based ;IN: (ELT *NAMES* 0) ;GOT: (ROBERT E. LEE) ;ok ;GOT: 0 ;ok 0 CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/demos.lisp" (written 01 FEB 2008 10:28:02 AM): ; compiling (EGS :ALL ...); ; compilation unit aborted ; caught 1 fatal ERROR condition compilation aborted because of fatal error: READ failure in COMPILE-FILE: READER-ERROR at 769 (line 25, column 27) on #: unmatched close parenthesis ; /home/ctobrey/opt/lisp/proj1/ch3/demos.fasl written ; compilation finished in 0:00:00 ;;;; 1) A Guide to Lisp Style ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last-name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;;;; 4) last-name again ;IN: (LAST-NAME (SECOND *NAMES*)) ;GOT: (GRANT) ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok ;;;; 3) Functions on Sequences ;IN: (DEMO 3.5) ;;;; 1) using nth to get the nth element in a list ;IN: (NTH 1 *NAMES*) ;GOT: (ULYSSES S. GRANT) ;ok ;;;; 2) using elt on a list. gets the element at the specified zero-based ;IN: (ELT *NAMES* 0) ;GOT: (ROBERT E. LEE) ;ok ;GOT: 0 ;ok ;;;; 4) Functions for Maintaining Tables ;IN: (DEMO 3.6) ;;;; 1) example ;IN: (ASSOC 'AK STATE-TABLE) ;GOT: (AK . ALASKA) ;ok ;GOT: 0 ;ok 0 CL-USER> (state-table) ; Evaluation aborted CL-USER> (print *names*) ((ROBERT E. LEE) (ULYSSES S. GRANT)) ((ROBERT E. LEE) (ULYSSES S. GRANT)) CL-USER> (print state-table) ((AL . ALABAMA) (AK . ALASKA) (AZ . ARIZONA) (AR . ARKANSAS)) CL-USER> (print state-table) ((AL . ALABAMA) (AK . ALASKA) (AZ . ARIZONA) (AR . ARKANSAS)) ((AL . ALABAMA) (AK . ALASKA) (AZ . ARIZONA) (AR . ARKANSAS)) CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-6.lisp" (written 01 FEB 2008 10:37:44 AM): ; compiling (SETF STATE-TABLE ...); ; compilation unit aborted ; caught 1 fatal ERROR condition compilation aborted because of fatal error: READ failure in COMPILE-FILE at character 154: end of file on # ; /home/ctobrey/opt/lisp/proj1/ch3/3-6.fasl written ; compilation finished in 0:00:00 ;;;; 1) A Guide to Lisp Style ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last-name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;;;; 4) last-name again ;IN: (LAST-NAME (SECOND *NAMES*)) ;GOT: (GRANT) ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok ;;;; 3) Functions on Sequences ;IN: (DEMO 3.5) ;;;; 1) using nth to get the nth element in a list ;IN: (NTH 1 *NAMES*) ;GOT: (ULYSSES S. GRANT) ;ok ;;;; 2) using elt on a list. gets the element at the specified zero-based ;IN: (ELT *NAMES* 0) ;GOT: (ROBERT E. LEE) ;ok ;GOT: 0 ;ok ;;;; 4) Functions for Maintaining Tables ;IN: (DEMO 3.6) ;GOT: 0 ;ok 0 CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-6.lisp" (written 01 FEB 2008 10:38:19 AM): ; compiling (SETF STATE-TABLE ...) ; compiling (EGS :|3.6| ...) ; file: /home/ctobrey/opt/lisp/proj1/ch3/3-6.lisp ; in: SETF STATE-TABLE ; (SETF STATE-TABLE ; '((AL . ALABAMA) (AK . ALASKA) (AZ . ARIZONA) (AR . ARKANSAS))) ; --> SETQ ; ==> ; (SETQ STATE-TABLE ; '((AL . ALABAMA) (AK . ALASKA) (AZ . ARIZONA) (AR . ARKANSAS))) ; ; caught WARNING: ; undefined variable: STATE-TABLE ; ; caught WARNING: ; This variable is undefined: ; STATE-TABLE ; ; compilation unit finished ; caught 2 WARNING conditions ; /home/ctobrey/opt/lisp/proj1/ch3/3-6.fasl written ; compilation finished in 0:00:03 ;;;; 1) A Guide to Lisp Style ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last-name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;;;; 4) last-name again ;IN: (LAST-NAME (SECOND *NAMES*)) ;GOT: (GRANT) ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok ;;;; 3) Functions on Sequences ;IN: (DEMO 3.5) ;;;; 1) using nth to get the nth element in a list ;IN: (NTH 1 *NAMES*) ;GOT: (ULYSSES S. GRANT) ;ok ;;;; 2) using elt on a list. gets the element at the specified zero-based ;IN: (ELT *NAMES* 0) ;GOT: (ROBERT E. LEE) ;ok ;GOT: 0 ;ok ;;;; 4) Functions for Maintaining Tables ;IN: (DEMO 3.6) ;;;; 1) here is the table we are working with. It is a list of dotted pairs where each pair has a key and a value ;IN: (PRINT STATE-TABLE) ((AL . ALABAMA) (AK . ALASKA) (AZ . ARIZONA) (AR . ARKANSAS)) ;GOT: ((AL . ALABAMA) (AK . ALASKA) (AZ . ARIZONA) (AR . ARKANSAS)) ;ok ;;;; 2) using assoc to look up a state by it two letter abbreviation. ;IN: (ASSOC 'AK STATE-TABLE) ;GOT: (AK . ALASKA) ;ok ;;;; 3) using cdr and assoc to return only the state name given its two letter abbreviation. ;IN: (CDR (ASSOC 'AK STATE-TABLE)) ;GOT: ALASKA ;ok ;;;; 4) looking up a pair that is not in the table ;IN: (ASSOC 'TX STATE-TABLE) ;GOT: NIL ;WANT: TEXAS ;BAD !!!!!!!!!!!!!!!!!!! ;;;; 5) Using rassoc to search the table by value rather than by key ;IN: (RASSOC 'ARIZONA TABLE) ; Evaluation aborted CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-6.lisp" (written 01 FEB 2008 10:38:52 AM): ; compiling (SETF STATE-TABLE ...) ; compiling (EGS :|3.6| ...) ; file: /home/ctobrey/opt/lisp/proj1/ch3/3-6.lisp ; in: SETF STATE-TABLE ; (SETF STATE-TABLE ; '((AL . ALABAMA) (AK . ALASKA) (AZ . ARIZONA) (AR . ARKANSAS))) ; --> SETQ ; ==> ; (SETQ STATE-TABLE ; '((AL . ALABAMA) (AK . ALASKA) (AZ . ARIZONA) (AR . ARKANSAS))) ; ; caught WARNING: ; undefined variable: STATE-TABLE ; ; caught WARNING: ; This variable is undefined: ; STATE-TABLE ; ; compilation unit finished ; caught 2 WARNING conditions ; /home/ctobrey/opt/lisp/proj1/ch3/3-6.fasl written ; compilation finished in 0:00:00 ;;;; 1) A Guide to Lisp Style ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last-name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;;;; 4) last-name again ;IN: (LAST-NAME (SECOND *NAMES*)) ;GOT: (GRANT) ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok ;;;; 3) Functions on Sequences ;IN: (DEMO 3.5) ;;;; 1) using nth to get the nth element in a list ;IN: (NTH 1 *NAMES*) ;GOT: (ULYSSES S. GRANT) ;ok ;;;; 2) using elt on a list. gets the element at the specified zero-based ;IN: (ELT *NAMES* 0) ;GOT: (ROBERT E. LEE) ;ok ;GOT: 0 ;ok ;;;; 4) Functions for Maintaining Tables ;IN: (DEMO 3.6) ;;;; 1) here is the table we are working with. It is a list of dotted pairs where each pair has a key and a value ;IN: (PRINT STATE-TABLE) ((AL . ALABAMA) (AK . ALASKA) (AZ . ARIZONA) (AR . ARKANSAS)) ;GOT: ((AL . ALABAMA) (AK . ALASKA) (AZ . ARIZONA) (AR . ARKANSAS)) ;ok ;;;; 2) using assoc to look up a state by it two letter abbreviation. ;IN: (ASSOC 'AK STATE-TABLE) ;GOT: (AK . ALASKA) ;ok ;;;; 3) using cdr and assoc to return only the state name given its two letter abbreviation. ;IN: (CDR (ASSOC 'AK STATE-TABLE)) ;GOT: ALASKA ;ok ;;;; 4) looking up a pair that is not in the table ;IN: (ASSOC 'TX STATE-TABLE) ;GOT: NIL ;WANT: TEXAS ;BAD !!!!!!!!!!!!!!!!!!! ;;;; 5) Using rassoc to search the table by value rather than by key ;IN: (RASSOC 'ARIZONA STATE-TABLE) ;GOT: (AZ . ARIZONA) ;ok ;GOT: 1 ;ok 0 CL-USER> (setf table(make-hash-table)) ; in: LAMBDA NIL ; (SETF TABLE (MAKE-HASH-TABLE)) ; ==> ; (SETQ TABLE (MAKE-HASH-TABLE)) ; ; caught WARNING: ; undefined variable: TABLE ; ; caught WARNING: ; This variable is undefined: ; TABLE ; ; compilation unit finished ; caught 2 WARNING conditions # CL-USER> ; in: LAMBDA NIL ; (LET* ((#:G1661 'AL) (#:G1662 TABLE)) ; (MULTIPLE-VALUE-BIND ; (#:G1664) ; 'ALABAMA ; (SB-KERNEL:%PUTHASH #:G1661 #:G1662 #:G1664))) ; ; caught WARNING: ; undefined variable: TABLE ; ; caught WARNING: ; This variable is undefined: ; TABLE ; ; compilation unit finished ; caught 2 WARNING conditions ALABAMA ;;;; CL-USER> ... CL-USER> (print table) # # CL-USER> (load "make.lisp")(demo :all) STYLE-WARNING: redefining MAKER in DEFUN STYLE-WARNING: redefining MAKE in DEFUN STYLE-WARNING: redefining MAKE-EXAMPLE in DEFUN STYLE-WARNING: redefining EG in DEFUN STYLE-WARNING: redefining EGS in DEFUN STYLE-WARNING: redefining EG0 in DEFUN STYLE-WARNING: redefining DEMO in DEFUN STYLE-WARNING: redefining DEMOF in DEFUN ; compiling file "/home/ctobrey/opt/lisp/proj1/ch3/3-6.lisp" (written 01 FEB 2008 10:51:24 AM): ; compiling (SETF STATE-TABLE ...) ; compiling (SETF TABLE ...) ; compiling (SETF (GETHASH # ...) ...) ; compiling (SETF (GETHASH # ...) ...) ; compiling (SETF (GETHASH # ...) ...) ; compiling (SETF (GETHASH # ...) ...) ; compiling (EGS :|3.6| ...) ; file: /home/ctobrey/opt/lisp/proj1/ch3/3-6.lisp ; in: SETF STATE-TABLE ; (SETF STATE-TABLE ; '((AL . ALABAMA) (AK . ALASKA) (AZ . ARIZONA) (AR . ARKANSAS))) ; --> SETQ ; ==> ; (SETQ STATE-TABLE ; '((AL . ALABAMA) (AK . ALASKA) (AZ . ARIZONA) (AR . ARKANSAS))) ; ; caught WARNING: ; undefined variable: STATE-TABLE ; in: SETF (GETHASH 'AK TABLE) ; (SETF (GETHASH 'AK TABLE) 'ALASKA) ; --> LET* ; ==> ; (LET* ((#:G4 'AK) (#:G5 TABLE)) ; (MULTIPLE-VALUE-BIND (#:G7) 'ALASKA (SB-KERNEL:%PUTHASH #:G4 #:G5 #:G7))) ; ; caught WARNING: ; undefined variable: TABLE ; in: SETF (GETHASH 'AL TABLE) ; (SETF (GETHASH 'AL TABLE) 'ALABAMA) ; --> LET* ; ==> ; (LET* ((#:G0 'AL) (#:G1 TABLE)) ; (MULTIPLE-VALUE-BIND (#:G3) 'ALABAMA (SB-KERNEL:%PUTHASH #:G0 #:G1 #:G3))) ; ; caught WARNING: ; undefined variable: TABLE ; in: SETF TABLE ; (SETF TABLE (MAKE-HASH-TABLE)) ; --> SETQ ; ==> ; (SETQ TABLE (MAKE-HASH-TABLE)) ; ; caught WARNING: ; undefined variable: TABLE ; ; caught WARNING: ; 2 more uses of undefined variable TABLE ; ; caught WARNING: ; These variables are undefined: ; STATE-TABLE TABLE ; ; compilation unit finished ; caught 6 WARNING conditions ; /home/ctobrey/opt/lisp/proj1/ch3/3-6.fasl written ; compilation finished in 0:00:00 ;;;; 1) A Guide to Lisp Style ;IN: (DEMO 3.1) ;;;; 1) being specific when naming variables ;IN: (DEFVAR *NAMES* '((ROBERT E. LEE) (ULYSSES S. GRANT))) ;GOT: *NAMES* ;ok ;;;; 2) creating a specific function to access names rather than evaluating caddar *names* ;IN: (DEFUN LAST-NAME (NAME) (LAST NAME)) STYLE-WARNING: redefining LAST-NAME in DEFUN ;GOT: LAST-NAME ;ok ;;;; 3) using the last-name function ;IN: (LAST-NAME (FIRST *NAMES*)) ;GOT: (LEE) ;ok ;;;; 4) last-name again ;IN: (LAST-NAME (SECOND *NAMES*)) ;GOT: (GRANT) ;ok ;GOT: 0 ;ok ;;;; 2) list functions ;IN: (DEMO 3.3) ;;;; 1) defining a list ;IN: (SETF X '(A B C)) ; in: LAMBDA NIL ; (SETF X '(A B C)) ; ==> ; (SETQ X '(A B C)) ; ; caught WARNING: ; undefined variable: X ; ; caught WARNING: ; This variable is undefined: ; X ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (A B C) ;ok ;;;; 2) another list ;IN: (SETF Y '(1 2 3)) ; in: LAMBDA NIL ; (SETF Y '(1 2 3)) ; ==> ; (SETQ Y '(1 2 3)) ; ; caught WARNING: ; undefined variable: Y ; ; caught WARNING: ; This variable is undefined: ; Y ; ; compilation unit finished ; caught 2 WARNING conditions ;GOT: (1 2 3) ;ok ;;;; 3) using first on a list evaluates to the first element ;IN: (FIRST X) ;GOT: A ;ok ;;;; 4) using second on a list evaluates to the second element ;IN: (SECOND X) ;GOT: B ;ok ;;;; 5) using third on a list evaluates to the third element ;IN: (THIRD X) ;GOT: C ;ok ;;;; 6) using nth 0 on a list evaluates to the nth element and is zero based ;IN: (NTH 0 X) ;GOT: A ;ok ;;;; 7) rest evaluates to all but the first element ;IN: (REST X) ;GOT: (B C) ;ok ;;;; 8) another name for first -- Contents of Address Register ;IN: (CAR X) ;GOT: A ;ok ;;;; 9) another name for rest -- Contents of data register ;IN: (CDR X) ;GOT: (B C) ;ok ;;;; 10) last cons cell in a list ;IN: (LAST X) ;GOT: (C) ;ok ;;;; 11) length evaluates to the number of elements in a list ;IN: (LENGTH X) ;GOT: 3 ;ok ;;;; 12) puts the list in reverse order ;IN: (REVERSE X) ;GOT: (C B A) ;ok ;;;; 13) add to the front of the list ;IN: (CONS 0 Y) ;GOT: (0 1 2 3) ;ok ;;;; 14) appends list elements together ;IN: (APPEND X Y) ;GOT: (A B C 1 2 3) ;ok ;;;; 15) makes a new list ;IN: (LIST X Y) ;GOT: ((A B C) (1 2 3)) ;ok ;;;; 16) append last argument to others ;IN: (LIST* 1 2 X) ;GOT: (1 2 A B C) ;ok ;;;; 17) predicate is true of the empty list ;IN: (NULL NIL) ;GOT: T ;ok ;;;; 18) and false for everythinf else ;IN: (NULL X) ;GOT: NIL ;ok ;;;; 19) predicate is true for any list, including nil ;IN: (LISTP X) ;GOT: T ;ok ;;;; 20) and false for non-lists ;IN: (LISTP 3) ;GOT: NIL ;ok ;;;; 21) predicate is true of non-nil lists ;IN: (CONSP X) ;GOT: T ;ok ;;;; 22) and false for atoms, including nil. ;IN: (CONSP NIL) ;GOT: NIL ;ok ;;;; 23) true for lists that look the same ;IN: (EQUAL X X) ;GOT: T ;ok ;;;; 24) and false for lists that look different ;IN: (EQUAL X Y) ;GOT: NIL ;ok ;;;; 25) sort y with a comparison function ;IN: (SORT Y #'>) ;GOT: (3 2 1) ;ok ;;;; 26) subsequence of a list with start and end points ;IN: (SUBSEQ X 1 2) ;GOT: (B) ;ok ;GOT: 0 ;ok ;;;; 3) Functions on Sequences ;IN: (DEMO 3.5) ;;;; 1) using nth to get the nth element in a list ;IN: (NTH 1 *NAMES*) ;GOT: (ULYSSES S. GRANT) ;ok ;;;; 2) using elt on a list. gets the element at the specified zero-based ;IN: (ELT *NAMES* 0) ;GOT: (ROBERT E. LEE) ;ok ;GOT: 0 ;ok ;;;; 4) Functions for Maintaining Tables ;IN: (DEMO 3.6) ;;;; 1) here is the table we are working with. It is a list of dotted pairs where each pair has a key and a value ;IN: (PRINT STATE-TABLE) ((AL . ALABAMA) (AK . ALASKA) (AZ . ARIZONA) (AR . ARKANSAS)) ;GOT: ((AL . ALABAMA) (AK . ALASKA) (AZ . ARIZONA) (AR . ARKANSAS)) ;ok ;;;; 2) using assoc to look up a state by it two letter abbreviation. ;IN: (ASSOC 'AK STATE-TABLE) ;GOT: (AK . ALASKA) ;ok ;;;; 3) using cdr and assoc to return only the state name given its two letter abbreviation. ;IN: (CDR (ASSOC 'AK STATE-TABLE)) ;GOT: ALASKA ;ok ;;;; 4) looking up a pair that is not in the table ;IN: (ASSOC 'TX STATE-TABLE) ;GOT: NIL ;WANT: TEXAS ;BAD !!!!!!!!!!!!!!!!!!! ;;;; 5) Using rassoc to search the table by value rather than by key ;IN: (RASSOC 'ARIZONA STATE-TABLE) ;GOT: (AZ . ARIZONA) ;ok ;;;; 6) using car on the previous function to return only the two letter abbrev. when given the value of the pair ;IN: (CAR (RASSOC 'ARIZONA STATE-TABLE)) ;GOT: AZ ;ok ;;;; 7) using gethash to access the hash-table ;IN: (GETHASH 'AK TABLE) ;GOT: ALASKA ;ok ;;;; 8) if only there was a texas ;IN: (GETHASH 'TX TABLE) ;GOT: NIL ;WANT: TEXAS ;BAD !!!!!!!!!!!!!!!!!!! ;GOT: 2 ;ok 0 CL-USER>