gengyangcai
11/5/2015 3:59:00 PM
Right, got it .. I keep forgetting that in Lisp, the division sign always comes at the beginning
CL-USER 1 > (let ((x 5) (y 6) (z 2))
(/ (* x y) z))
15
On Thursday, November 5, 2015 at 11:53:32 PM UTC+8, Barry Margolin wrote:
> In article <a3cba1aa-8922-4e21-b0b9-62e470b19c86@googlegroups.com>,
> CAI GENGYANG <gengyangcai@gmail.com> wrote:
>
> > I know how to use the let operator to introduce 2 variables , add them and
> > print out the result :
> >
> > > (let ((x 1) (y 2))
> > (+ x y))
> >
> > 3
> >
> > How do you use the let operator to create a function that takes 3 inputs (x ,
> > y , z), multiple x and y, then divides the result by z , ie --- [ (x+y) / z ]
> > ?
> >
> > I tried this :
> >
> > > (let ((x 5) (y 6) (z 2))
> > (* x y) / z)
> >
> > expecting the result to be 5 * 6 / 2 = 15, but the result I got instead was
> >
> > 2
>
> Your problem isn't with the let operator, it's that you're confused
> about how to do division. Just like every other function call in Lisp,
> you put the operator *first* and wrap it in a list:
>
> (/ (* x y) z)
>
> --
> Barry Margolin, barmar@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***