From: Sungwoo Lim
Subject: [Q] LET binding.
Date: 
Message-ID: <100920011242278732%sungwoo@cad.strath.ac.uk>
Hi, I am trying to get a original value from a new value binded by LET
or LET*, but following code doesn't work.

(let* ((ax 1) (ay 3)
           (bx 7) (by 3)
           (cx 4) (cy 3)
           (temp1 (if (/= ay by) 
                              (max ay by) 
                              (if (>= ax bx) ay by)))
           (temp2 (if (/= temp1 cy)
                              (max temp1 cy)
                              (let ((t1 (if (eql temp1 ay) ax bx)))
                                  (if (>= t1 cx) temp1 cy)))))
   (case temp2 <- problem here?
       (ay (print 'ay))
       (by (print 'by))
       (cy (print 'cy))))

I also tried below code, but still no luck.

(case (if (eql temp2 temp1) temp1 temp2)

It seems the 'temp2' can't indicate the original name of value...
Does BINDING makes another address for the name of value?
Does 'temp1' and 'by' are not identical object?
Plz let me know why the above code doesn't give me a proper output.
Thanks,

Sungwoo

From: Steven M. Haflich
Subject: Re: [Q] LET binding.
Date: 
Message-ID: <3B9CB28B.92BBE350@pacbell.net>
Sungwoo Lim wrote:
> 
> Hi, I am trying to get a original value from a new value binded by LET
> or LET*, but following code doesn't work.

>    (case temp2 <- problem here?
>        (ay (print 'ay))
>        (by (print 'by))
>        (cy (print 'cy))))

> (case (if (eql temp2 temp1) temp1 temp2)
 
> It seems the 'temp2' can't indicate the original name of value...
> Does BINDING makes another address for the name of value?

Your confusion is suggested by your use of phrases like "get a value"
or "name of a value".  You need to consider the evaluation model of
Lisp.  In Lisp execution, everything is a form or a subform of a form.
A function call form always evaluates all its subforms.  A macro or
special form evaluates some but not others.  CASE is a macro, and the
keys subforms are _not_ evaluated.  It is as if your first CASE form
above macroexpands into the following:

 (let ((#:temp2 temp2))  ; prevent multiple evaluation of temp2
   (cond ((eql #:temp2 'ay) (print 'ay))
         ((eql #:temp2 'by) (print 'by))
         ...))

This is clearly not what you want, but you should be able to figure
out what you want by studying and latering my code fragment.
From: Coby Beck
Subject: Re: [Q] LET binding.
Date: 
Message-ID: <CA3n7.107389$8c3.16865708@typhoon.tampabay.rr.com>
"Sungwoo Lim" <·······@cad.strath.ac.uk> wrote in message
·······························@cad.strath.ac.uk...
> Hi, I am trying to get a original value from a new value binded by LET
> or LET*, but following code doesn't work.
>
> (let* ((ax 1) (ay 3)
>            (bx 7) (by 3)
>            (cx 4) (cy 3)
>            (temp1 (if (/= ay by)
>                               (max ay by)
>                               (if (>= ax bx) ay by)))
>            (temp2 (if (/= temp1 cy)
>                               (max temp1 cy)
>                               (let ((t1 (if (eql temp1 ay) ax bx)))
>                                   (if (>= t1 cx) temp1 cy)))))
>    (case temp2 <- problem here?
>        (ay (print 'ay))
>        (by (print 'by))
>        (cy (print 'cy))))
>

Try cond instead.  Case does not evaluate the key forms so you were really
looking at the symbols ay, by and cy not the values bound to them.

(let* ((ax 1) (ay 3)
           (bx 7) (by 3)
           (cx 4) (cy 3)
           (temp1 (if (/= ay by)
                              (max ay by)
                              (if (>= ax bx) ay by)))
           (temp2 (if (/= temp1 cy)
                              (max temp1 cy)
                              (let ((t1 (if (eql temp1 ay) ax bx)))
                                  (if (>= t1 cx) temp1 cy)))))
   (cond
       ((= temp2 ay) (print 'ay))
       ((= temp2 by) (print 'by))
       ((= temp2 cy) (print 'cy))))

ay
=> ay


Coby

--
(remove #\space "coby . beck @ opentechgroup . com")