Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Difference between (let...) and nested (define...)

1,001 views
Skip to first unread message

5lvq...@sneakemail.com

unread,
Dec 22, 2008, 2:12:05 PM12/22/08
to
What is the difference between defining a procedure and binding your
local variables with let, vs. just using define for each variable?
They seem to work the same.

(define (bla1 x y)
(define bla-var1 (+ 15 x y))
(define bla-var2 (+ 19 x y))
(+ bla-var1 bla-var2))
> (bla1 10 20)
94

> (define (bla1 x y)
(let ((bla-var1 (+ 15 x y))
(bla-var2 (+ 19 x y)))
(+ bla-var1 bla-var2)))
> (bla1 10 20)

is this syntactic sugar?
94
>

Tom

unread,
Dec 22, 2008, 6:45:01 PM12/22/08
to
5lvq...@sneakemail.com writes:

To a first approximation, the answer to the final question is "yes" ...
if you substitute "letrec" for "let", in the general case. That
is, you can use internal defines to create local procedures which can
call each other recursively. That can also be done with "letrec", but
not with plain "let".

--
---------------------------------------------------------------------
Tom Edelson Poltergeists are the
http://www.well.com/user/edelsont/ principal type
"tom0613" at "mindspring.com" of material manifestation.
---------------------------------------------------------------------

5lvq...@sneakemail.com

unread,
Dec 22, 2008, 11:46:09 PM12/22/08
to
I see, thanks.

Grant Rettke

unread,
Dec 23, 2008, 4:36:19 PM12/23/08
to
Put more simply, you can't even define a single recursive procedure
with let:

(import (rnrs))

(letrec
((fun (lambda (n)
(if (= n 0)
(begin (display "Done"))
(begin (display n) (newline)
(fun (- n 1)))))))
(fun 10))

Try changing it to a 'let' and 'fun' won't be in scope of the value-
body (which in this chase is the lambda function).

0 new messages