==> mytest.out * ; Lisp test file ; Don Hopkins ; (function fn) returns a funarg pair, of the form (fn . env), where ; fn is a lisp function that can be applied, and env is the ; environment in which (function fn) was evaluated. When the funarg ; pair is given as a function to apply or eval, the function will be ; evaluated in the environment env. ; Initialize foo and bar. (setq foo 'godzilla bar 'moon-moth) ==> moon-moth * ; Define a function that references the free variable foo. (defun with-foo (x) (list foo 'is 'with x)) ==> > * ; Create an environment in which foo and bar are rebound, and with-foo ; is rebound to another function that also references the free ; variable foo. (let ((foo '(turkey lurkey)) (bar '(the banana bunch)) (with-foo (lambda (other-x) <* Garbage collection *> <* Freed 5528 *> <* Grew cons space by 2048 to 8192. (7576 free.) *> (list foo 'is 'in 'this 'case 'actually 'with other-x)))) ; In this environment, bind bletch to functions that will be evaluated ; in this environment when applied. (setq bletch (function (lambda (fn) (fn bar))))) ==> > * ; Call bletch, giving it the atom with-foo. The atom with-foo is ; evaluated in bletch's environment, so the local definition of ; with-foo is called. The bar in bletch and the foo in the local ; with-foo are all gotten from bletch's environment, (bletch 'with-foo) ==> ((turkey lurkey) is in this case actually with (the banana bunch)) * ; Call bletch, giving it the funarg with-foo. The atom with-foo is ; evaluated in the environment (function with-foo) was evaluated in, ; so the global definition of with-foo is called. The bar in bletch is ; gotten from bletch's environment, because bletch is a funarg. The ; foo in the global with-foo is gotten from the environment that ; (function with-foo) was evaluated in. (bletch (function with-foo)) ==> (godzilla is with (the banana bunch)) * ; The argument field (the car) of a user function, user special, or ; macro consists of either a list of atoms that the arguments are ; bound to, or an atom that the entire argument list is bound to. If ; the arg it is a list ending with a dotted atom, then all the rest of ; the arguments at that point are bound to the atom. (defspecial atom-arg foo (printcr foo)) ==> > * (atom-arg can take any number of arguments, the list of which is bound to the atom.) (can take any number of arguments, the list of which is bound to the atom.) ==> (can take any number of arguments, the list of which is bound to the atom.) * (defspecial list-arg (foo bar baz) (printcr foo) (printcr bar) (printcr baz)) ==> > * (list-arg takes three parameters.) takes three parameters. ==> parameters. * (defspecial list-dot-arg (foo bar baz . bletch) (printcr foo) (printcr bar) (printcr baz) (printcr bletch)) ==> > * (list-dot-arg takes three args and as many more as you care to give it.) takes three args (and as many more as you care to give it.) ==> (and as many more as you care to give it.) * (list-dot-arg also takes three) also takes three nil ==> nil * ; Demonstrations of various lisp functions. (plus 1000 200 30 4 .5) ==> 1234.5 * (times 2 3 4 .5) ==> 12 * (quotient 1 2) ==> 0.5 * (remainder 10 4) ==> 2 * (minus 20) ==> -20 * (floor 4.4) ==> 4 * (floor -4.3) ==> -5 * (numberp t) ==> nil * (numberp -54.5) ==> t * (greaterp -23 332) ==> nil * (zerop 0) ==> t * (zerop -2) ==> nil * (difference 3 90) ==> -87 * (lessp 3 .032) ==> nil * (into minus '(1000 200 30 4)) ==> (-1000 -200 -30 -4) * (onto printcr '(1000 200 30 4)) (1000 200 30 4) (200 30 4) (30 4) (4) ==> ((1000 200 30 4) (200 30 4) (30 4) (4)) * (set 'foo 'bar) ==> bar * (set foo 'baz) ==> baz * bar ==> baz * (null '(foo bar)) ==> nil * (null 12) ==> nil * (null nil) ==> t * (not (null t)) ==> t * (not (null nil)) ==> nil * (consp 'foo) ==> nil * (consp list) ==> nil * (consp consp) ==> nil * (consp '(foo bar baz)) ==> t * (consp '(1 . 3)) ==> t * (eq '(foo (bar (baz))()((()))) '(foo (bar (baz))()((())))) ==> nil * (equal '(foo (bar (baz))()((()))) '(foo (bar (baz))()((())))) ==> t * (memq 'is '(what is the meaning of life?)) ==> (is the meaning of life?) * (memq '(grape jam) '(toast (orange juice) (grape jam))) <* Garbage collection *> <* Freed 7401 *> <* Grew cons space by 2048 to 10240. (9449 free.) *> ==> nil * (member 'is '(what is the meaning of life?)) ==> (is the meaning of life?) * (member '(grape jam) '(toast (orange juice) (grape jam))) ==> ((grape jam)) * (append '(a b c) '(1 2 3)) ==> (a b c 1 2 3) * (reverse '(10000 1000 100 10 1)) ==> (1 10 100 1000 10000) * (reverse '(m a d a m i m a d a m)) <* Garbage collection *> <* Freed 9281 *> <* Grew cons space by 2048 to 12288. (11329 free.) *> ==> (m a d a m i m a d a m) * (setq red '(seems that red was evaluated) green '(looks like green was evaluated) blue '(i would say blue was evaluated)) ==> (i would say blue was evaluated) * (body (bind (lambda (green) (cons red (list (cons -32 green) blue))))) ==> (lambda (green) (cons (seems that red was evaluated) (list (cons -32 green) (i would say blue was evaluated)))) * (let ((green 'bright) (red 'dull) blue) (print (list red green blue))) (dull bright nil) ==> (dull bright nil) * (pop-output) ==> mytest.out * ; Lisp test file ; Don Hopkins ; (function fn) returns a funarg pair, of the form (fn . env), where ; fn is a lisp function that can be applied, and env is the ; environment in which (function fn) was evaluated. When the funarg ; pair is given as a function to apply or eval, the function will be ; evaluated in the environment env. ; Initialize foo and bar. (setq foo 'godzilla bar 'moon-moth) ==> moon-moth * ; Define a function that references the free variable foo. (defun with-foo (x) (list foo 'is 'with x)) ==> > * ; Create an environment in which foo and bar are rebound, and with-foo ; is rebound to another function that also references the free ; variable foo. (let ((foo '(turkey lurkey)) (bar '(the banana bunch)) (with-foo (lambda (other-x) (list foo 'is 'in 'this 'case 'actually 'with other-x)))) ; In this environment, bind bletch to functions that will be evaluated ; in this environment when applied. (setq bletch (function (lambda (fn) (fn bar))))) ==> > * ; Call bletch, giving it the atom with-foo. The atom with-foo is ; evaluated in bletch's environment, so the local definition of ; with-foo is called. The bar in bletch and the foo in the local ; with-foo are all gotten from bletch's environment, (bletch 'with-foo) ==> ((turkey lurkey) is in this case actually with (the banana bunch)) * ; Call bletch, giving it the funarg with-foo. The atom with-foo is ; evaluated in the environment (function with-foo) was evaluated in, ; so the global definition of with-foo is called. The bar in bletch is ; gotten from bletch's environment, because bletch is a funarg. The ; foo in the global with-foo is gotten from the environment that ; (function with-foo) was evaluated in. (bletch (function with-foo)) ==> (godzilla is with (the banana bunch)) * ; The argument field (the car) of a user function, user special, or ; macro consists of either a list of atoms that the arguments are ; bound to, or an atom that the entire argument list is bound to. If ; the arg it is a list ending with a dotted atom, then all the rest of ; the arguments at that point are bound to the atom. (defspecial atom-arg foo (printcr foo)) ==> > * (atom-arg can take any number of arguments, the list of which is bound to the atom.) (can take any number of arguments, the list of which is bound to the atom.) ==> (can take any number of arguments, the list of which is bound to the atom.) * (defspecial list-arg (foo bar baz) (printcr foo) (printcr bar) (printcr baz)) ==> > * (list-arg takes three parameters.) takes three parameters. ==> parameters. * (defspecial list-dot-arg (foo bar baz . bletch) (printcr foo) (printcr bar) (printcr baz) (printcr bletch)) ==> > * (list-dot-arg takes three args and as many more as you care to give it.) takes three args (and as many more as you care to give it.) ==> (and as many more as you care to give it.) * (list-dot-arg also takes three) also takes three nil ==> nil * ; Demonstrations of various lisp functions. (plus 1000 200 30 4 .5) ==> 1234.5 * (times 2 3 4 .5) ==> 12 * (quotient 1 2) ==> 0.5 * (remainder 10 4) ==> 2 * (minus 20) ==> -20 * (floor 4.4) ==> 4 * (floor -4.3) ==> -5 * (numberp t) ==> nil * (numberp -54.5) ==> t * (greaterp -23 332) ==> nil * (zerop 0) ==> t * (zerop -2) ==> nil * (difference 3 90) ==> -87 * (lessp 3 .032) ==> nil * (into minus '(1000 200 30 4)) ==> (-1000 -200 -30 -4) * (onto printcr '(1000 200 30 4)) (1000 200 30 4) (200 30 4) (30 4) (4) ==> ((1000 200 30 4) (200 30 4) (30 4) (4)) * (set 'foo 'bar) ==> bar * (set foo 'baz) ==> baz * bar ==> baz * (null '(foo bar)) ==> nil * (null 12) ==> nil * (null nil) ==> t * (not (null t)) ==> t * (not (null nil)) ==> nil * (consp 'foo) ==> nil * (consp list) ==> nil * (consp consp) ==> nil * (consp '(foo bar baz)) ==> t * (consp '(1 . 3)) ==> t * (eq '(foo (bar (baz))()((()))) '(foo (bar (baz))()((())))) ==> nil * (equal '(foo (bar (baz))()((()))) '(foo (bar (baz))()((())))) <* Garbage collection *> <* Freed 11407 *> <* Grew cons space by 2048 to 14336. (13455 free.) *> ==> t * (memq 'is '(what is the meaning of life?)) ==> (is the meaning of life?) * (memq '(grape jam) '(toast (orange juice) (grape jam))) ==> nil * (member 'is '(what is the meaning of life?)) ==> (is the meaning of life?) * (member '(grape jam) '(toast (orange juice) (grape jam))) ==> ((grape jam)) * (append '(a b c) '(1 2 3)) ==> (a b c 1 2 3) * (reverse '(10000 1000 100 10 1)) ==> (1 10 100 1000 10000) * (reverse '(m a d a m i m a d a m)) ==> (m a d a m i m a d a m) * (setq red '(seems that red was evaluated) green '(looks like green was evaluated) blue '(i would say blue was evaluated)) ==> (i would say blue was evaluated) * (body (bind (lambda (green) (cons red (list (cons -32 green) blue))))) <* Garbage collection *> <* Freed 13417 *> <* Grew cons space by 2048 to 16384. (15465 free.) *> ==> (lambda (green) (cons (seems that red was evaluated) (list (cons -32 green) (i would say blue was evaluated)))) * (let ((green 'bright) (red 'dull) blue) (print (list red green blue))) (dull bright nil) ==> (dull bright nil) * (pop-output)