From: Jian-Yun
Subject: Binding
Date: 
Message-ID: <1273ac49.0206230144.6f375c0c@posting.google.com>
Could someone explain to me how to dictate order the variable
bindings?  I'm going to let x be 300 and y be 500.  I just want to set
the order in which they happen.

What other functions does LISP have other than "let" to bind values to
variables?
thanks

From: Dvd Avins
Subject: Re: Binding
Date: 
Message-ID: <20020623065144.11052.00000115@mb-fk.aol.com>
In article <····························@posting.google.com>,
············@hotmail.com (Jian-Yun) writes:

>Could someone explain to me how to dictate order the variable
>bindings?  I'm going to let x be 300 and y be 500.  I just want to set
>the order in which they happen.
>
>What other functions does LISP have other than "let" to bind values to
>variables?
>thanks

Several. Look up Let*, which is probably what you want.


-- Attaining and helping others attain "Aha!" experiences, as satisfying as
attaining and helping others attain orgasms.
From: Vladimir Zolotykh
Subject: Re: Binding
Date: 
Message-ID: <3D15A810.66DC2BF@eurocom.od.ua>
Consider inner LET and LET* in the following:

(let ((a 1)) (let ((a 2) (b a)) (list a b))) ==> (2 1)
(let ((a 1)) (let* ((a 2) (b a)) (list a b))) ==> (2 2)

Jian-Yun wrote:
> 
> Could someone explain to me how to dictate order the variable
> bindings?  I'm going to let x be 300 and y be 500.  I just want to set
> the order in which they happen.
> 
> What other functions does LISP have other than "let" to bind values to
> variables?

LET*, DO* for example.

> thanks

-- 
Vladimir Zolotykh
From: Kalle Olavi Niemitalo
Subject: Re: Binding
Date: 
Message-ID: <87u1nutg0v.fsf@Astalo.y2000.kon.iki.fi>
············@hotmail.com (Jian-Yun) writes:

> Could someone explain to me how to dictate order the variable
> bindings?  I'm going to let x be 300 and y be 500.  I just want to set
> the order in which they happen.

If a LET form binds multiple variables, it first computes the new
values in the order you specify and then binds all the variables
in parallel.  So the following form will always print first 300
and then 500, and finally return the list (300 500).

  (let ((x (print 300))
        (y (print 500)))
    (list x y))
  >> 300
  >> 500
  => (300 500)

If you try to use X in the form that computes the new value of Y,
that fails because LET has not yet bound X when it is computing
the value for Y.

  (let ((x 300)
        (y (+ x 200)))
    (list x y))
  error--> the variable X is unbound.

If you bind Y in a nested LET form instead, then X has the proper
value.

  (let ((x 300))
    (let ((y (+ x 200)))
      (list x y)))
  => (300 500)

This can also be written with LET*, which binds each variable
before computing a value for the next.

  (let* ((x 300)
         (y (+ x 200)))
    (list x y))
  => (300 500)

> What other functions does LISP have other than "let" to bind values to
> variables?

- DEFVAR, DEFPARAMETER, DEFCONSTANT

- MULTIPLE-VALUE-BIND

- LAMBDA, DESTRUCTURING-BIND and numerous other macros that take
  lambda lists

- iteration macros: LOOP, DO, DO*, DOLIST, DOTIMES, DO-SYMBOLS,
  DO-EXTERNAL-SYMBOLS, DO-ALL-SYMBOLS

- various WITH- macros

- probably more I forget

These are special operators or macros though, not functions.