In article <········································@unix4.andrew.cmu.edu>,
Hyunchul Kim <········@andrew.cmu.edu> wrote:
>Anyone? Thanks.
Reformatted so that it's readable and doesn't take up an entire screen of
my response....
>(defun calc (first)
> (let ((op (read)))
> (when (not (eq op '=))
> (let ((next (read)))
> (setf first (funcall op first next))
> (calc first)))
> (when (eq op '=)
> (print first)
> t)))
If the result is printed by the a recursive call to CALC, the T that it
returns ends up being thrown away. This is because the outer call then
performs the (when (eq op '=) ...) form. In that outer call, OP isn't EQ
to =, so the T is never returned.
If you use IF rather than a pair of WHENs the right thing will happen:
(defun calc (first)
(let ((op (read)))
(if (not (eq op '=))
(let ((next (read)))
(setf first (funcall op first next))
(calc first))
(progn
(print first)
t))))
--
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Don't bother cc'ing followups to me.
nil is the evaluation of (calc 0)
because let returns the last item
and the last item is (when (eq op ...
and op as your first read input.
Use trace to see calc work through the frames.
You may want to simplify the function like this,
(defun calc2 (input1)
(let ((op (read)))
(if (eq op '=)
(print input1)
(calc2 (funcall op input1 (read))))))
As a point of style, don't use lisp function names
as your input parameters (unless your using lisp on
an extremely small machine)
Thanks,
Jeff Sandys
Hyunchul Kim wrote:
>
> Anyone? Thanks.
>
> (defun calc (first)
> (let ( (op (read)))
> (when (not (eq op '=))
> (let ( (next (read)) )
> (setf first (funcall op first next))
> (calc first)
> )
> )
> (when (eq op '=) (print first) t)
> )
> )
>
> (calc 0)