newLISP Fan Club

Forum => newLISP in the real world => Topic started by: eddier on October 29, 2004, 06:24:10 PM

Title: let
Post by: eddier on October 29, 2004, 06:24:10 PM
Would it be difficult to fix let so that I could reference other local variables like

(let (x (car L) y (car x) ...)

This would reduce the amount of nested lets like

(let (x (car L))
  (let (y (car x))
  ...


What do you think about this one?



Eddie
Title:
Post by: Lutz on October 30, 2004, 08:26:48 AM
do you mean let* (or letrec) ?



(set 'x 10)



(let ((x 3) (y (+ x 4)) (print y)) => 14



versus:



(letrec ((x 3) (y (+ x 4)) (print y))  => 7



Lutz
Title:
Post by: eddier on November 01, 2004, 05:47:16 AM
I would use the (letrec more.  What is the difference between let* and let?



Eddie
Title:
Post by: Lutz on November 01, 2004, 05:52:05 AM
'let*' and 'letrec' are the same thing, they are just differently named in different LISPs. I implemented is yesterday as 'letr', I thought 'letrec' is too long to type for a function which will be used by some people quite often so 'letr' it will be in version  8.2.6



Lutz
Title:
Post by: eddier on November 01, 2004, 05:55:15 AM
Thanks Lutz :)



Eddie
Title:
Post by: Qrczak on November 02, 2004, 02:48:19 AM
Quote from: "Lutz"'let*' and 'letrec' are the same thing, they are just differently named in different LISPs.

Scheme has both let* and letrec, and they are not the same thing.



let* allows each expression to refer to variables defined above it. It guarantees that expressions will be evaluated in order. Common Lisp has the same let*.



letrec allows each expression to refer to any variable in the group, but all references must be made inside function closures - it must be possible to evaluate all expressions to values before binding any variable. Expressions may be evaluated in arbitrary order.
Title:
Post by: Lutz on November 02, 2004, 04:58:36 AM
thanks for the clarification



Lutz