From: John Hornbeck
Subject: Not understanding things...........
Date: 
Message-ID: <Wa9Ja.8$9H2.7520@typhoon01.sbc.net>
Ok, so I am teaching myself Lisp. I have been working through a book 
called Essential Lisp, that I picked up at my collage. I have a few 
questions about makeing my own functions. It ask's me to make my own 
(not) (or) and (and) functions. Well I had no clue where to start so I 
looked in the back of the book at the answers and don't really 
understand how it works. They are listed below if anyone could kinda 
walk me through them. Thanks,


(defun my-not (val)
	(cond (val nil)
	      (t t)))

(defun my-or (val1 val2)
	(cond (val1 val1)
	      (val2 val2)
	      (t nil)))

(defun my-and (val1 val2)
	(cond (val1 (cond val2 val2)
		(t nil)))
	(t nil)))

There they are. Please help.
John Hornbeck

From: Damond Walker
Subject: Re: Not understanding things...........
Date: 
Message-ID: <BB1A9D7B.19695%damosan@comcast.net>
On 6/21/03 23:13, in article ················@typhoon01.sbc.net, "John
Hornbeck" <········@freeshell.org> wrote:

> Ok, so I am teaching myself Lisp. I have been working through a book
> called Essential Lisp, that I picked up at my collage. I have a few
> questions about makeing my own functions. It ask's me to make my own
> (not) (or) and (and) functions. Well I had no clue where to start so I
> looked in the back of the book at the answers and don't really
> understand how it works. They are listed below if anyone could kinda
> walk me through them. Thanks,
> 

Is it the COND that throws you?  I see texts do this because I think it's
the LISP way of doing things.  COND is a powerful thing but you can also use
IF (at the expense of making True Lisp Hackers gag).

> 
> (defun my-not (val)
> (cond (val nil)
>      (t t)))
>

(defun my-not (val)
   (if val nil t))
 
> (defun my-or (val1 val2)
> (cond (val1 val1)
>      (val2 val2)
>      (t nil)))
>

(defun my-or (val1 val2)
   (if val1 val1
      (if val2 val2 nil)))
 

> (defun my-and (val1 val2)
> (cond (val1 (cond val2 val2)
> (t nil)))
> (t nil)))
>

(defun my-and (val1 val2)
    (if val1 (if val2 t nil) nil))
 
When I was learning about COND I spent more time looking up the syntax of
the beast than actually using it.  Now it's not a big deal...

Damo
From: John Hornbeck
Subject: Re: Not understanding things...........
Date: 
Message-ID: <j6bJa.9$9H2.6941@typhoon01.sbc.net>
I guess whats really getting me is that I don't really understand what 
it is doing. I don't get how (cond (val nil) (t t) comes out to be a not
function. I guess if I understood what it is doing. When you use 'not' 
it works liks (not (equal 1 5)) well how does my function understand the 
t and nil of it from that little bit. I am very new to this and I though 
t I was understanding it fully until I ran into this. Please help,
John Hornbeck

Damond Walker wrote:
> On 6/21/03 23:13, in article ················@typhoon01.sbc.net, "John
> Hornbeck" <········@freeshell.org> wrote:
> 
> 
>>Ok, so I am teaching myself Lisp. I have been working through a book
>>called Essential Lisp, that I picked up at my collage. I have a few
>>questions about makeing my own functions. It ask's me to make my own
>>(not) (or) and (and) functions. Well I had no clue where to start so I
>>looked in the back of the book at the answers and don't really
>>understand how it works. They are listed below if anyone could kinda
>>walk me through them. Thanks,
>>
> 
> 
> Is it the COND that throws you?  I see texts do this because I think it's
> the LISP way of doing things.  COND is a powerful thing but you can also use
> IF (at the expense of making True Lisp Hackers gag).
> 
> 
>>(defun my-not (val)
>>(cond (val nil)
>>     (t t)))
>>
> 
> 
> (defun my-not (val)
>    (if val nil t))
>  
> 
>>(defun my-or (val1 val2)
>>(cond (val1 val1)
>>     (val2 val2)
>>     (t nil)))
>>
> 
> 
> (defun my-or (val1 val2)
>    (if val1 val1
>       (if val2 val2 nil)))
>  
> 
> 
>>(defun my-and (val1 val2)
>>(cond (val1 (cond val2 val2)
>>(t nil)))
>>(t nil)))
>>
> 
> 
> (defun my-and (val1 val2)
>     (if val1 (if val2 t nil) nil))
>  
> When I was learning about COND I spent more time looking up the syntax of
> the beast than actually using it.  Now it's not a big deal...
> 
> Damo
> 
From: Erann Gat
Subject: Re: Not understanding things...........
Date: 
Message-ID: <gat-2106032241250001@192.168.1.51>
In article <················@typhoon01.sbc.net>, John Hornbeck
<········@freeshell.org> wrote:

> I guess whats really getting me is that I don't really understand what 
> it is doing. I don't get how (cond (val nil) (t t) comes out to be a not
> function.

Do you understand what COND does?

COND is like a bunch of nested IFs.

(cond (condition-1 result-1) (condition-2 result-2) ...)

is the same as:

(if condition-1
  result-1
  (if condition-2
     result-2
     ...))

In Lisp, NIL is false, and anything else (including T) is true.

Does it make sense now?  (And didn't the book you are using tell you all this?)

E.
From: John Hornbeck
Subject: I think I got it....
Date: 
Message-ID: <lmbJa.10$9H2.7544@typhoon01.sbc.net>
Ok so this has really been bothering me that I did not understand this. 
I broke it down and I think I have it.

(cond ((equal 1 4) nil)
	(t t))
=>t
(cond ((equal 1 1) nil)
	(t t))
=>nil

If the equal comes out nil than (nil nil) than it just skips on down to
the (t t) which comes out t. While if it comes out (t nil) on the first 
cond, it than returns nil because they are not the same? Is that right?
John Hornbeck

John Hornbeck wrote:
> I guess whats really getting me is that I don't really understand what 
> it is doing. I don't get how (cond (val nil) (t t) comes out to be a not
> function. I guess if I understood what it is doing. When you use 'not' 
> it works liks (not (equal 1 5)) well how does my function understand the 
> t and nil of it from that little bit. I am very new to this and I though 
> t I was understanding it fully until I ran into this. Please help,
> John Hornbeck
> 
> Damond Walker wrote:
> 
>> On 6/21/03 23:13, in article ················@typhoon01.sbc.net, "John
>> Hornbeck" <········@freeshell.org> wrote:
>>
>>
>>> Ok, so I am teaching myself Lisp. I have been working through a book
>>> called Essential Lisp, that I picked up at my collage. I have a few
>>> questions about makeing my own functions. It ask's me to make my own
>>> (not) (or) and (and) functions. Well I had no clue where to start so I
>>> looked in the back of the book at the answers and don't really
>>> understand how it works. They are listed below if anyone could kinda
>>> walk me through them. Thanks,
>>>
>>
>>
>> Is it the COND that throws you?  I see texts do this because I think it's
>> the LISP way of doing things.  COND is a powerful thing but you can 
>> also use
>> IF (at the expense of making True Lisp Hackers gag).
>>
>>
>>> (defun my-not (val)
>>> (cond (val nil)
>>>     (t t)))
>>>
>>
>>
>> (defun my-not (val)
>>    (if val nil t))
>>  
>>
>>> (defun my-or (val1 val2)
>>> (cond (val1 val1)
>>>     (val2 val2)
>>>     (t nil)))
>>>
>>
>>
>> (defun my-or (val1 val2)
>>    (if val1 val1
>>       (if val2 val2 nil)))
>>  
>>
>>
>>> (defun my-and (val1 val2)
>>> (cond (val1 (cond val2 val2)
>>> (t nil)))
>>> (t nil)))
>>>
>>
>>
>> (defun my-and (val1 val2)
>>     (if val1 (if val2 t nil) nil))
>>  
>> When I was learning about COND I spent more time looking up the syntax of
>> the beast than actually using it.  Now it's not a big deal...
>>
>> Damo
>>
> 
From: Peter Seibel
Subject: Re: I think I got it....
Date: 
Message-ID: <m365myira5.fsf@javamonkey.com>
John Hornbeck <········@freeshell.org> writes:

> Ok so this has really been bothering me that I did not understand
> this. I broke it down and I think I have it.
> 
> 
> (cond ((equal 1 4) nil)
> 	(t t))
> =>t
> (cond ((equal 1 1) nil)
> 	(t t))
> =>nil
> 
> If the equal comes out nil than (nil nil) than it just skips on down to
> the (t t) which comes out t. While if it comes out (t nil) on the
> first cond, it than returns nil because they are not the same? Is that
> right?

Not quite. I don't know how your book explained it but here goes my
attempt. Let's start with the skeleton of COND (stuff in <>'s is
descriptive, not literal):

  (cond 
    (<test-form-1> <expression-1>)
    (<test-form-2> <expression-2>)
    <... more test-form/expression pairs ...>
    (<test-form-N> <expression-N>))

A COND expression is evaluated by walking down the list of
test-form/expression pairs evaluating the test-forms. As soon as it
finds a test-form that evaluates to true (i.e. non-NIL) it then
evaluates the corresponding expression and returns the resulting
value.

In the first COND expression you give above the two test-forms are
'(equal 1 4)' and 't'. The two expressions are 'nil' and 't',
respectively. Thus it evaluates '(equal 1 4)' which is NIL so it
doesn't even look at the corresponding expression (which only
coincidentally happens to also be NIL) and moves on. The next
test-form 't' is, of course, true, and so now it does evaluate the
corresponding expression which happens also (again, coincidentally) to
be 't'. So the result of the COND expression as a whole is that final
't'.

In the second COND expression the first test-form '(equal 1 1)' is
true, so its corresponding expression is evaluated and returned. It
happens to be 'nil' so that's what the COND returns.

(Once you've got this down, you can note that what I've been calling
"expression" is really plural: after the test-form you can have any
number of expression which will be evaluated in order if the test-form
evaluates to true.)


-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp
From: John Hornbeck
Subject: Re: I think I got it....
Date: 
Message-ID: <JhiJa.12$9H2.7636@typhoon01.sbc.net>
Thanks alot. That helped add on to what I figured out. I am very glad I 
found this group and have people around to help me out. :)
John Hornbeck


Peter Seibel wrote:
> John Hornbeck <········@freeshell.org> writes:
> 
> 
>>Ok so this has really been bothering me that I did not understand
>>this. I broke it down and I think I have it.
>>
>>
>>(cond ((equal 1 4) nil)
>>	(t t))
>>=>t
>>(cond ((equal 1 1) nil)
>>	(t t))
>>=>nil
>>
>>If the equal comes out nil than (nil nil) than it just skips on down to
>>the (t t) which comes out t. While if it comes out (t nil) on the
>>first cond, it than returns nil because they are not the same? Is that
>>right?
> 
> 
> Not quite. I don't know how your book explained it but here goes my
> attempt. Let's start with the skeleton of COND (stuff in <>'s is
> descriptive, not literal):
> 
>   (cond 
>     (<test-form-1> <expression-1>)
>     (<test-form-2> <expression-2>)
>     <... more test-form/expression pairs ...>
>     (<test-form-N> <expression-N>))
> 
> A COND expression is evaluated by walking down the list of
> test-form/expression pairs evaluating the test-forms. As soon as it
> finds a test-form that evaluates to true (i.e. non-NIL) it then
> evaluates the corresponding expression and returns the resulting
> value.
> 
> In the first COND expression you give above the two test-forms are
> '(equal 1 4)' and 't'. The two expressions are 'nil' and 't',
> respectively. Thus it evaluates '(equal 1 4)' which is NIL so it
> doesn't even look at the corresponding expression (which only
> coincidentally happens to also be NIL) and moves on. The next
> test-form 't' is, of course, true, and so now it does evaluate the
> corresponding expression which happens also (again, coincidentally) to
> be 't'. So the result of the COND expression as a whole is that final
> 't'.
> 
> In the second COND expression the first test-form '(equal 1 1)' is
> true, so its corresponding expression is evaluated and returned. It
> happens to be 'nil' so that's what the COND returns.
> 
> (Once you've got this down, you can note that what I've been calling
> "expression" is really plural: after the test-form you can have any
> number of expression which will be evaluated in order if the test-form
> evaluates to true.)
> 
> 
> -Peter
> 
From: Damond Walker
Subject: Re: Not understanding things...........
Date: 
Message-ID: <BB1B100B.197D5%damosan@comcast.net>
On 6/22/03 1:24, in article ················@typhoon01.sbc.net, "John
Hornbeck" <········@freeshell.org> wrote:

> I guess whats really getting me is that I don't really understand what
> it is doing. I don't get how (cond (val nil) (t t) comes out to be a not
> function. I guess if I understood what it is doing. When you use 'not'
> it works liks (not (equal 1 5)) well how does my function understand the
> t and nil of it from that little bit. I am very new to this and I though
> t I was understanding it fully until I ran into this. Please help,

It might help if you view the above COND as...

(cond
  (val nil) ;; evaluate VAL and if it's non-nil, return nil
  (t t))    ;; otherwise return t

I'll leave it to someone else to describe the full workings of COND as
they'll probabaly do a better job than I.

Damond
From: Marco Baringer
Subject: Re: Not understanding things...........
Date: 
Message-ID: <m24r2iux71.fsf@bese.it>
John Hornbeck <········@freeshell.org> writes:

> I guess whats really getting me is that I don't really understand what
> it is doing. I don't get how (cond (val nil) (t t) comes out to be a
> not
> function. I guess if I understood what it is doing. When you use 'not'
> it works liks (not (equal 1 5)) well how does my function understand
> the t and nil of it from that little bit. I am very new to this and I
> though t I was understanding it fully until I ran into this. Please
> help,
> John Hornbeck

1) the hyperspec is your friend: http://www.lispworks.com/reference/HyperSpec/Body/m_cond.htm

2) macroexpand-1 is your friend:

? (macroexpand-1 '(cond (a b) (c d)))
(IF A (PROGN B) (COND (C D)))
T
? (macroexpand-1 '(cond (c d)))
(IF C (PROGN D) (COND))
T
? (macroexpand-1 '(cond))
NIL
T
? 

-- 
-Marco
Ring the bells that still can ring.
Forget your perfect offering.
There is a crack in everything.
That's how the light gets in.
     -Leonard Cohen
From: John Hornbeck
Subject: Ok,
Date: 
Message-ID: <QeiJa.11$9H2.7601@typhoon01.sbc.net>
I actually figured this out in bed last night. I broke it down to many 
if statements and remembered that in a cond, that it will go until 
something returns true. So if both of the first return nil than it will 
be true because it will go on down to the next which is (t t) while if 
the expression comes out (t nil) it will than return nil because that is
the way the cond is written. If that does not sound right than I can't 
explain what I mean very well. Thank you all for helping.
John Hornbeck

Marco Baringer wrote:
> John Hornbeck <········@freeshell.org> writes:
> 
> 
>>I guess whats really getting me is that I don't really understand what
>>it is doing. I don't get how (cond (val nil) (t t) comes out to be a
>>not
>>function. I guess if I understood what it is doing. When you use 'not'
>>it works liks (not (equal 1 5)) well how does my function understand
>>the t and nil of it from that little bit. I am very new to this and I
>>though t I was understanding it fully until I ran into this. Please
>>help,
>>John Hornbeck
> 
> 
> 1) the hyperspec is your friend: http://www.lispworks.com/reference/HyperSpec/Body/m_cond.htm
> 
> 2) macroexpand-1 is your friend:
> 
> ? (macroexpand-1 '(cond (a b) (c d)))
> (IF A (PROGN B) (COND (C D)))
> T
> ? (macroexpand-1 '(cond (c d)))
> (IF C (PROGN D) (COND))
> T
> ? (macroexpand-1 '(cond))
> NIL
> T
> ? 
> 
From: Kaz Kylheku
Subject: Re: Not understanding things...........
Date: 
Message-ID: <cf333042.0306221327.21c6308f@posting.google.com>
John Hornbeck <········@freeshell.org> wrote in message news:<················@typhoon01.sbc.net>...
> Ok, so I am teaching myself Lisp. I have been working through a book 
> called Essential Lisp, that I picked up at my collage. I have a few 
> questions about makeing my own functions. It ask's me to make my own 
> (not) (or) and (and) functions.

They are operators, not functions. They control the evaluation of
their argument expressions. For instance (and nil (print 42)) does not
print anything; the AND operator stops evaluating the expressions when
it encounters NIL.

> Well I had no clue where to start so I 
> looked in the back of the book at the answers and don't really 
> understand how it works. They are listed below if anyone could kinda 
> walk me through them. Thanks,
> 
> 
> (defun my-not (val)
> 	(cond (val nil)
> 	      (t t)))
> 
> (defun my-or (val1 val2)
> 	(cond (val1 val1)
> 	      (val2 val2)
> 	      (t nil)))
> 
> (defun my-and (val1 val2)
> 	(cond (val1 (cond val2 val2)
> 		(t nil)))
> 	(t nil)))

I would throw this book in the garbage. The correct solution, since
these are operators, is to write them as macros. Moreover, OR and AND
take zero or more arguments; they are not binary:

 ;; here we ``cheat'' by just translating
 ;; (my-and ...) calls to (and ...) calls.

 (defmacro my-and (&rest args)
   `(and ,@args))

If the code generated by the macro must not use AND, then you have
more work to do. Regardless of what you do, the emitted code will have
to use some kind of evaluation-controlling operator as its basis. For
example, if we choose the IF operator, we can write the macro based on
the following recursive definition:

  1. The value of an AND expression with 0 arguments is true.
  2. The value of an AND expression with 1 arguments is the value of
the
     first and only argument.
  3. The value of an AND expression with N arguments is the value of
the
     last argument if the value of AND over the first N-1 arguments is
NIL,
     otherwise it is the value of an AND over the first N-1 arguments.

Note: The Common Lisp standard function BUTLAST can help us extract
the N-1 element prefix from an N element list.

 (defmacro my-and (&rest args)
   (case (length args)
     (0 t)
     (1 (first args))
     (otherwise
       (let ((temp-var (gensym)))
         `(let ((,temp-var (my-and ,@(butlast args))))
            (if ,temp-var 
              ,(first (last args))
              nil))))))

MY-AND is not a function, but a macro; it works by generating code
that is substituted in its place. You can see this in action by
typing:

  (macroexpand '(my-and))      ;; test zero argument case
  (macroexpand '(my-and 42))   ;; try one-argument case
  (macroexpand '(my-and x y))) ;; and so on ...

For example, the output of (macroexpand '(my-and 1 2 3 4)) might look
like this:

  (LET ((#:G594 (MY-AND 1 2 3))) (IF #:G594 4 NIL))

Note that the code contains another occurence of MY-AND which will be
recursively expanded. You can see how this expansion implements case
(3) of the recursion: it evaluates MY-AND over the first three
arguments, and then based on that result it either yields NIL or
evaluates the last argument. See? Control of evaluation. If that last
argument has side effects, they will or will not happen depending on
the outcome from the previous arguments.
From: John Hornbeck
Subject: Re: Not understanding things...........
Date: 
Message-ID: <UStJa.14$9H2.7673@typhoon01.sbc.net>
Kaz Kylheku wrote:
> John Hornbeck <········@freeshell.org> wrote in message news:<················@typhoon01.sbc.net>...
> 
>>Ok, so I am teaching myself Lisp. I have been working through a book 
>>called Essential Lisp, that I picked up at my collage. I have a few 
>>questions about makeing my own functions. It ask's me to make my own 
>>(not) (or) and (and) functions.
> 
> 
> They are operators, not functions. They control the evaluation of
> their argument expressions. For instance (and nil (print 42)) does not
> print anything; the AND operator stops evaluating the expressions when
> it encounters NIL.
> 
> 
>>Well I had no clue where to start so I 
>>looked in the back of the book at the answers and don't really 
>>understand how it works. They are listed below if anyone could kinda 
>>walk me through them. Thanks,
>>
>>
>>(defun my-not (val)
>>	(cond (val nil)
>>	      (t t)))
>>
>>(defun my-or (val1 val2)
>>	(cond (val1 val1)
>>	      (val2 val2)
>>	      (t nil)))
>>
>>(defun my-and (val1 val2)
>>	(cond (val1 (cond val2 val2)
>>		(t nil)))
>>	(t nil)))
> 
> 
> I would throw this book in the garbage. The correct solution, since
> these are operators, is to write them as macros. Moreover, OR and AND
> take zero or more arguments; they are not binary:
> 
>  ;; here we ``cheat'' by just translating
>  ;; (my-and ...) calls to (and ...) calls.
> 
>  (defmacro my-and (&rest args)
>    `(and ,@args))
> 
> If the code generated by the macro must not use AND, then you have
> more work to do. Regardless of what you do, the emitted code will have
> to use some kind of evaluation-controlling operator as its basis. For
> example, if we choose the IF operator, we can write the macro based on
> the following recursive definition:
> 
>   1. The value of an AND expression with 0 arguments is true.
>   2. The value of an AND expression with 1 arguments is the value of
> the
>      first and only argument.
>   3. The value of an AND expression with N arguments is the value of
> the
>      last argument if the value of AND over the first N-1 arguments is
> NIL,
>      otherwise it is the value of an AND over the first N-1 arguments.
> 
> Note: The Common Lisp standard function BUTLAST can help us extract
> the N-1 element prefix from an N element list.
> 
>  (defmacro my-and (&rest args)
>    (case (length args)
>      (0 t)
>      (1 (first args))
>      (otherwise
>        (let ((temp-var (gensym)))
>          `(let ((,temp-var (my-and ,@(butlast args))))
>             (if ,temp-var 
>               ,(first (last args))
>               nil))))))
> 
> MY-AND is not a function, but a macro; it works by generating code
> that is substituted in its place. You can see this in action by
> typing:
> 
>   (macroexpand '(my-and))      ;; test zero argument case
>   (macroexpand '(my-and 42))   ;; try one-argument case
>   (macroexpand '(my-and x y))) ;; and so on ...
> 
> For example, the output of (macroexpand '(my-and 1 2 3 4)) might look
> like this:
> 
>   (LET ((#:G594 (MY-AND 1 2 3))) (IF #:G594 4 NIL))
> 
> Note that the code contains another occurence of MY-AND which will be
> recursively expanded. You can see how this expansion implements case
> (3) of the recursion: it evaluates MY-AND over the first three
> arguments, and then based on that result it either yields NIL or
> evaluates the last argument. See? Control of evaluation. If that last
> argument has side effects, they will or will not happen depending on
> the outcome from the previous arguments.
I am only in the third chapter of the book, and it seems to be making me 
understand more than most other books I have read. Also I am so sorry 
that I used the wrong syntax of function when it is really a operator.
The stuff you printed out is fine if I was at a level of useing it, but 
I just started lisp and have no clue what any of it really does. It was 
a exercise that I did not understand and that is what the post was 
about. I am sorry if I did not give enough information. Thanks for your 
help, but I understand it now.
John Hornbeck
From: Michael Sullivan
Subject: Re: Not understanding things...........
Date: 
Message-ID: <1fx0kkh.1veazs011gzwdnN%michael@bcect.com>
John Hornbeck <········@freeshell.org> wrote:


> (defun my-and (val1 val2)
>   (cond (val1 (cond val2 val2)
                     ^ need open paren here, I think.
>       (t nil)))
>   (t nil)))

Note:  I'm pretty sure there's a typographical error in this last
"my-and".  

It would also make a great deal more sense formatted thus (paren added):

  (defun my-and (val1 val2)
    (cond (val1 (cond (val2 val2)
                      (t nil)))
          (t nil)))

Now your cond clauses are lined up, making the structure more apparent
to the eye (assuming you view this in a monospaced font). It looks like
the missing paren threw your formatting off.  

Michael
From: John Hornbeck
Subject: Re: Not understanding things...........
Date: 
Message-ID: <6sQJa.15$9H2.7811@typhoon01.sbc.net>
Michael Sullivan wrote:
> John Hornbeck <········@freeshell.org> wrote:
> 
> 
> 
>>(defun my-and (val1 val2)
>>  (cond (val1 (cond val2 val2)
> 
>                      ^ need open paren here, I think.
> 
>>      (t nil)))
>>  (t nil)))
> 
> 
> Note:  I'm pretty sure there's a typographical error in this last
> "my-and".  
> 
> It would also make a great deal more sense formatted thus (paren added):
> 
>   (defun my-and (val1 val2)
>     (cond (val1 (cond (val2 val2)
>                       (t nil)))
>           (t nil)))
> 
> Now your cond clauses are lined up, making the structure more apparent
> to the eye (assuming you view this in a monospaced font). It looks like
> the missing paren threw your formatting off.  
> 
> Michael
Thanks, I caught that also after I posted.
John Hornbek
From: Steven M. Haflich
Subject: Re: Not understanding things...........
Date: 
Message-ID: <3EF900D2.9010704@alum.mit.edu>
John Hornbeck wrote:
> Ok, so I am teaching myself Lisp. ...
 > They are listed below if anyone could kinda
> walk me through them. Thanks,

I'm glad all the wise masters have finally beaten poor NOT and
COND into submission.  However, everyone seems to have missed the
obvious problems in your definitions of MY-OR and MY-AND.  They are
in no way equivalent to the standard operators AND and OR.

The reason is important, so please think about it.  I'll post the
answer immediately in a following message, but I suggest you think
about the question and reread the ANS about AND and OR before
reading ahead.

> (defun my-or (val1 val2)
>     (cond (val1 val1)
>           (val2 val2)
>           (t nil)))
> 
> (defun my-and (val1 val2)
>     (cond (val1 (cond val2 val2)
>         (t nil)))
>     (t nil)))
From: Steven M. Haflich
Subject: Re: Not understanding things...........
Date: 
Message-ID: <3EF901FE.9080909@alum.mit.edu>
Steven M. Haflich wrote:

> The reason is important, so please think about it.  I'll post the
> answer immediately in a following message, but I suggest you think
> about the question and reread the ANS about AND and OR before
> reading ahead.

Here's a strong hint:

(let ((x 1))
   (or (zerop (print (decf x)))
       (zerop (print (decf x)))

Compare how the above form behaves compared to using your MY-OR
instead of OR.