Is there "let binding" in Python?

Rob Hunter rhunter007 at yahoo.com
Sun Sep 14 17:43:40 EDT 2003


Is there an equivalent to Scheme's LET in Python?
 LET creates a new binding in the current
environment.  For example, here's some Scheme
code:

(let ((x 3))
  (let ((f (lambda (arg) (* arg x))))
    (let ((x 4))
      (f 5))))

So, this program, which also tests that Scheme
has correct scoping, returns 15.

And in Python, I can write an equivalent program
that does correctly return 15, but I have to use
what, in Scheme, we call "left-left lambda"--a
way of simulating LET.  Or rather, LET is
syntactic sugar for left-left lambda.

As a simpler example, if I want to write:

(let ((x 3)) (+ x 4))

I can write

((lambda (x) (+ x 4)) 3) in Scheme

or,

(lambda x: x+4)(3) in Python.

I want to know if there's a less syntactically
cumbersome way of getting LET in python.

Thanks!

PS: I'm a newbie, so the answer in fact might be super-easy.

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com





More information about the Python-list mailing list