[plt-scheme] to define, or to let

From: Joe Marshall (jrm at ccs.neu.edu)
Date: Fri Mar 19 09:17:28 EST 2004

Richard Cleis <rcleis at mac.com> writes:

> 1) Do these two generate the same code?

They might.  Or not.  They do the same thing.

> 2) Which one best contains the spirit of scheme?
>
> (define a-function-using-defines
>    (lambda ()
>      (define one-variable 3)
>      (define another-variable 4)
>      (list 3 4))) ; just checking
>
> (define a-function-using-let-list
>    (lambda ()
>      (let ((one-variable 3)
>            (another-variable 4) )
>        (list 3 4)))) ; just checking

I have a strong preference for the latter for a couple of reasons.

The LET expression cannot have mutually recursive bindings, so I know
without further inspection that no variable being bound in the LET
depends on any of the others.

The internal DEFINE is equivalent to a LETREC, and LETREC exists
to facilitate defining mutually recursive functions and data
structures.  When I see one, I tend to expect that earlier definitions
may depend on later ones.

But that's just my opinion.



Posted on the users mailing list.