Aaron C. Christy (··········@osu.edu) wrote:
[Snip]
: (DEFUN membership (item j)
: (cond ((NULL j) NIL)
: ((EQUAL item (CAR j)) (print 'true))
: (T (membership item (cdr j)))))
[Snip]
: However, the interpreter is telling me the result is TRUE TRUE. How can this
: be?
Simple. (print 'true) displays 'true since that's its job, and
it also returns 'true. Lisp systems display the value of
the last expression they evaluate*, and since (print 'true) is
the last one, you see the 'true, printed by the function
and the 'true displayed by the interpreter which is the
value returned from the function.
I believe there was a way to suppress this, but I can't recall
it. You can however put another expression, like 'Finished
right after the (print 'true) and what you'll see is:
true
finished
This is because (print 'true) prints true, and then 'finished
is the last expression evaluated, and its value is finished
so that's what you see.
: ..please help me to straighten this matter out!
: You can e-mail me at : ··········@osu.edu
Don't worry, your code is fine, this is the way the Lisp interactive
system works, nothing to worry about.
* Some functions like prog1 and prog2 which are sequencing functions
don't return the last form evaluated but rather the first, or
second, so in some cases the code may not behave like you expect.
For example:
(prog1
(print 'true)
(print 'false)
(print 'maybe))
Will return 'true instead of the value of the last form evaluated
which is 'maybe. So what I said about returning the last form
evaluated is generally true but not always (there might be a case
for prog1 and prog2 doing funny things so that this is still true).
--
Cya,
Ahmed
In article <··········@masala.cc.uh.edu>,
········@Bayou.UH.EDU (········@bayou.uh.edu) writes:
> I believe there was a way to suppress this, but I can't recall
> it. You can however put another expression, like 'Finished
> right after the (print 'true) and what you'll see is:
>
> true
> finished
>
> This is because (print 'true) prints true, and then 'finished
> is the last expression evaluated, and its value is finished
> so that's what you see.
The "normal" way is to return (values), ie no return values.
Mike McDonald
·······@engr.sgi.com