473,385 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Is there "let binding" in Python?

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

Jul 18 '05 #1
1 3843
Rob Hunter <rh********@yahoo.com> writes:
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.
Sorry, never heard of "correct" scoping[*]. I've heard of lexical and
dynamic scoping though, and, to me, your code shows that Scheme has
lexical scoping.
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.


A long, time ago (Python 2.0), Python only had 3 scopes: local, global
and builtin. Now it has nested scopes of arbitrary depth (still
wrapped inside global and builtin), but I'm not expecting "let" to
appear anytime soon.
[*] But given that you are formulating your question from a Scheme
perspective, it's not really surprising that you call it
"correct". :-)
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: pieter.breed | last post by:
Hi All, It seems as if whenever you rebuild a .net class library you have to rebuild /everything/ which references it. Is this so? I am wondering what happens when you are only doing a minor...
2
by: Boniek | last post by:
Hi, How I can create property to binding with other objects. I want to create a data object which work as a DataTable. DataTable contains columns and dataTable is used to binding with a textBox...
3
by: Coldman | last post by:
which was saying this: "i have an asp:repeater - its values r initialezed w/ a .DataBind() call does it mean any changes user makes on the page will automaticly go to the database? quite...
0
by: brian.mills | last post by:
I'm having trouble with a web service I've been using since I've change computers. The project was in source safe, and i've pulled it out, but I can now not change beetween static and dynamic on a...
11
by: Alexander Vasilevsky | last post by:
Linq "into" and "let" equally??? http://www.alvas.net - Audio tools for C# and VB.Net developers
2
by: barcrofter | last post by:
Im still confused with interfaces for COM objects. I have a Lotus word processor that I'm trying to automate via vb.net. The exe comes with an interface that I can add as a reference .. but.. I...
1
by: nelsonivan | last post by:
Hi, i'm trying to reference some objects using reflection and Late Binding accessing. The Object API to his methods it's easy to understand, and it's as "Object.Method" - aka....
0
by: Ronald S. Cook | last post by:
Hi, I'm wanting to iterate over a generic IList, but the code won't compile because the blue sqiggle line under: _DataRow("SecurityFunctionName") = _IList(i).SecurityFunctionName; sez...
0
by: Armin Zingler | last post by:
<Just_a_fan@home.netschrieb After having longer discussions about a similar issue, I ask you to provide an example of the source and destination value(s) and their data types. Thanks. Example...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.