From: Aaron C. Christy
Subject: <gulp> HELP...new LISP user
Date: 
Message-ID: <5f026a$6dn$1@charm.magnus.acs.ohio-state.edu>
I am a new user of LISP and I'm trying to figure something out for a class I 
am currently taking.

Given the following function :

(DEFUN membership (item j)
                (cond   ((NULL j) NIL)
                        ((EQUAL item (CAR j)) (print 'true))
                        (T (membership item (cdr j)))))

I need to evaluate this :

(membership apple '(pear apple kiwi))

I did it by hand and checked it against the interpreter and we are 
disagreeing.  It seems to me that it should return TRUE only once since 
'apple' can only equal 'apple' at one instance.

However, the interpreter is telling me the result is TRUE TRUE.  How can this 
be?

..please help me to straighten this matter out!

                                You can e-mail me at : ··········@osu.edu
From: Mike McDonald
Subject: Re: <gulp> HELP...new LISP user
Date: 
Message-ID: <5f03iv$f2s@fido.asd.sgi.com>
In article <············@charm.magnus.acs.ohio-state.edu>,
	··········@osu.edu (Aaron C. Christy) writes:
> I am a new user of LISP and I'm trying to figure something out for a class I 
> am currently taking.
> 
> Given the following function :
> 
> (DEFUN membership (item j)
>                 (cond   ((NULL j) NIL)
>                         ((EQUAL item (CAR j)) (print 'true))
>                         (T (membership item (cdr j)))))
> 
> I need to evaluate this :
> 
> (membership apple '(pear apple kiwi))
> 
> I did it by hand and checked it against the interpreter and we are 
> disagreeing.  It seems to me that it should return TRUE only once since 
> 'apple' can only equal 'apple' at one instance.
> 
> However, the interpreter is telling me the result is TRUE TRUE.  How can this 
> be?
> 
> ..please help me to straighten this matter out!
> 
>                                 You can e-mail me at : ··········@osu.edu

  Well, print returns the object being printed. So the line

  ((equal item (car j)) (print 'true)) 

both prints out true and returns true as the result. Normally, the toplevel
loop also prints out the result of any forms it evaluates. So, one true is from
your print and the second is from the toplevel loop. 

  Mike McDonald
  ·······@engr.sgi.com