On Jun 3, 11:17 am, Jussi Piitulainen jpiit...@ling.helsinki.fi
wrote:
rusi writes:
So I tried:
Recast the comprehension as a map
Rewrite the map into a fmap (functionalmap) to create new bindings
def fmap(f,lst):
if not lst: return []
return [f(lst[0])] + fmap(f, lst[1:])
rusi writes:
On Jun 3, 11:17 am, Jussi Piitulainen wrote:
rusi writes:
So I tried:
Recast the comprehension as a map
Rewrite the map into a fmap (functionalmap) to create new bindings
def fmap(f,lst):
if not lst: return []
return [f(lst[0])] + fmap(f, lst[1:])
On Jun 5, 5:03 pm, Jussi Piitulainen jpiit...@ling.helsinki.fi
wrote:
rusi writes:
On Jun 3, 11:17 am, Jussi Piitulainen wrote:
rusi writes:
So I tried:
Recast the comprehension as a map
Rewrite the map into a fmap (functionalmap) to create new bindings
def fmap(f,lst):
rusi writes:
On Jun 5, 5:03 pm, Jussi Piitulainen wrote:
rusi writes:
On Jun 3, 11:17 am, Jussi Piitulainen wrote:
rusi writes:
So I tried:
Recast the comprehension as a map
Rewrite the map into a fmap (functionalmap) to create new bindings
def fmap(f,lst):
rusi writes:
So I tried:
Recast the comprehension as a map
Rewrite the map into a fmap (functionalmap) to create new bindings
def fmap(f,lst):
if not lst: return []
return [f(lst[0])] + fmap(f, lst[1:])
Still the same effects.
Obviously I am changing it at the wrong place...
Am 03.06.2011 01:43 schrieb Gregory Ewing:
It's not the lambda that's different from other languages,
it's the for-loop. In languages that encourage a functional
style of programming, the moral equivalent of a for-loop is
usually some construct that results in a new binding of the
control
Gregory Ewing greg.ew...@canterbury.ac.nz writes:
Alain Ketterlin wrote:
But going against generally accepted semantics should at least
be clearly indicated. Lambda is one of the oldest computing abstraction,
and they are at the core of any functional programming language.
Yes, and Python's
Alain Ketterlin writes:
Gregory Ewing writes:
Alain Ketterlin wrote:
But going against generally accepted semantics should at least be
clearly indicated. Lambda is one of the oldest computing
abstraction, and they are at the core of any functional
programming language.
Yes, and
On Fri, 03 Jun 2011 11:43:54 +1200, Gregory Ewing wrote:
But going against generally accepted semantics should at least
be clearly indicated. Lambda is one of the oldest computing abstraction,
and they are at the core of any functional programming language.
Yes, and Python's lambdas behave
On Fri, Jun 3, 2011 at 2:30 AM, Thomas Rachel
nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa...@spamschutz.glglgl.de
wrote:
So there should be a way to replace the closure of a function with a
snapshot of it at a certain time. If there was an internal function with
access to the readonly attribute
Alain Ketterlin wrote:
The reason why we have the kind of lambdas we have in python (and
scheme, and javascript, etc.) is just that it is way easier to
implement. That's all I've said. And people have gotten used to it,
without ever realizing they are using something completely different
from
Alain Ketterlin wrote:
You must be kidding. Like many others, you seem to think that Scheme is
a typical functional language, which it is not.
I never said that Scheme is a functional language -- I'd be
the first to acknowledge that it's not. I do know what real
functional languages are like.
On 6/1/2011 8:40 PM, harrismh777 wrote:
The part that I don't see much about in the docs (some books, that is)
is that the lambda lookups occur late (the lambda is evaluated at the
time it is called). The Python docs on-line *do say* this (I found too
late) but its one quick phrase that can be
On Thu, Jun 2, 2011 at 3:14 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
The problem with Do What I Mean is that it so rarely Does What You Mean.
At best it Does What Some Other Guy Imagined I'd Probably Mean In This
Situation. Let's not go there.
+1
One of my biggest
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:
The part that I don't see much about in the docs (some books, that is)
is that the lambda lookups occur late (the lambda is evaluated at the
time it is called). The Python docs on-line *do say* this (I found too
late) but its one
Alain Ketterlin writes:
Steven D'Aprano writes:
I agree it's not intuitive. But where does it say that programming
language semantics must always be intuitive?
Nowhere. But going against generally accepted semantics should at
least be clearly indicated. Lambda is one of the oldest
Steven D'Aprano wrote:
funcs = [(lambda x, i=j: x+i) for j in range(10)]
Now the reader is no longer distracted by the i=i ugliness.
That's a good idea, in fact, change made!
The problem with Do What I Mean is that it so rarely Does What You Mean.
At best it Does What Some Other Guy
Steven D'Aprano wrote:
What do you expect this code to do?
a = 42
funcs = [(lambda x: x+a) for i in range(10)]
funcs[0](1)
I do see your point with this... truly... but it did get me to think
about what I *do* expect... and that is that 'a' (for the lambda) will
be whatever 'a' is (now)
Terry Reedy wrote:
Oh the irony of this proposal. You scolded us for breaking code with 2
to 3 changes, and here you propose a change more radical than anything
done in Python 3, and certain to break code, introduce bugs, complicate
the language, and reduce its functionality. Most of Guido's
On Thu, 02 Jun 2011 10:55:49 -0500, harrismh777 wrote:
Steven D'Aprano wrote:
What do you expect this code to do?
a = 42
funcs = [(lambda x: x+a) for i in range(10)] funcs[0](1)
I do see your point with this... truly... but it did get me to think
about what I *do* expect... and that
On Thu, Jun 2, 2011 at 11:22 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
It seems to me that early binding is less flexible than late, because
with late binding you have a chance to simulate early binding by saving a
reference of the variable elsewhere, such as in a default
On 6/2/2011 7:00 AM, Alain Ketterlin wrote:
Nowhere. But going against generally accepted semantics should at least
be clearly indicated. Lambda is one of the oldest computing abstraction,
and they are at the core of any functional programming language. Adding
a quick hack to python and call it
Alain Ketterlin wrote:
But going against generally accepted semantics should at least
be clearly indicated. Lambda is one of the oldest computing abstraction,
and they are at the core of any functional programming language.
Yes, and Python's lambdas behave exactly the *same* way as
every other
On Jun 3, 4:43 am, Gregory Ewing greg.ew...@canterbury.ac.nz wrote:
Alain Ketterlin wrote:
But going against generally accepted semantics should at least
be clearly indicated. Lambda is one of the oldest computing abstraction,
and they are at the core of any functional programming language.
On 5/31/2011 8:09 PM, harrismh777 wrote:
At the moment I'm only speaking about my OP and that particular list
comprehension... the thing that happened (at least for me) is that the
intuitive sense that each 'i' somehow becomes a part of the anonymous
function (I know, not so) is built-in. There
Terry Reedy wrote:
function (I know, not so) is built-in. There is little to nothing
indicating in the docs that this is not so
On the contrary, the docs very explicitly say that a lambda expression
is equivalent to a def statement.
Allow me to clarify... I'm not speaking about whether the
harrismh777 wrote:
Allow me to clarify... I'm not speaking about whether the lambda is
short-hand for def, ... that part of the docs I understand well!... no
problems there.
Allow me to clarify a little further... the docs are misleading in
that they state that the lambda can be coded (as
On Wed, 01 Jun 2011 19:50:14 -0500, harrismh777 wrote:
harrismh777 wrote:
Allow me to clarify... I'm not speaking about whether the lambda is
short-hand for def, ... that part of the docs I understand well!... no
problems there.
Allow me to clarify a little further... the docs are
On Wed, 01 Jun 2011 19:40:30 -0500, harrismh777 wrote:
The part that I don't see much about in the docs (some books, that is)
is that the lambda lookups occur late (the lambda is evaluated at the
time it is called). The Python docs on-line *do say* this (I found too
late) but its one quick
fs=[]
fs = [(lambda n: i + n) for i in range(10)]
[fs[i](1) for i in range(10)]
[10, 10, 10, 10, 10, 10, 10, 10, 10, 10] === not good
( that was a big surprise! . . . )
( let's try it another way . . . )
fs =[]
def g(i): return (lambda n: i + n)
fs = [g(i) for i in range(10)]
On Mon, May 30, 2011 at 11:48 PM, harrismh777 harrismh...@charter.net wrote:
fs=[]
fs = [(lambda n: i + n) for i in range(10)]
[fs[i](1) for i in range(10)]
[10, 10, 10, 10, 10, 10, 10, 10, 10, 10] === not good
( that was a big surprise! . . . )
snip
lambda? closure?
On Tue, May 31, 2011 at 12:48 AM, harrismh777 harrismh...@charter.net wrote:
What is going on with the binding in the first construct... this seems
to reduce the usefulness of lambda to a considerable extent?
I don't see why; as you've shown there are a couple of simple ways to
avoid this
harrismh777 writes:
fs=[]
fs = [(lambda n: i + n) for i in range(10)]
[fs[i](1) for i in range(10)]
[10, 10, 10, 10, 10, 10, 10, 10, 10, 10] === not good
( that was a big surprise! . . . )
( let's try it another way . . . )
The ten functions share the same i. The
Am 31.05.2011 12:08 schrieb Jussi Piitulainen:
The same sharing-an-i thing happens here:
fs = []
for i in range(4):
...fs.append(lambda n : i + n)
...
fs[0](0)
3
And the different private-j thing happens here:
gs = []
for i in range(4):
...gs.append((lambda j : lambda n : j +
Thomas Rachel writes:
Am 31.05.2011 12:08 schrieb Jussi Piitulainen:
The same sharing-an-i thing happens here:
fs = []
for i in range(4):
...fs.append(lambda n : i + n)
...
fs[0](0)
3
And the different private-j thing happens here:
gs = []
for i in range(4):
...
On 5/31/2011 2:48 AM, harrismh777 wrote:
fs=[]
Irrelevant here since you immediately rebind 'fs'.
fs = [(lambda n: i + n) for i in range(10)]
[fs[i](1) for i in range(10)]
Same as [f(1) for f in fs]
[10, 10, 10, 10, 10, 10, 10, 10, 10, 10] === not good
( that was a big surprise! . . . )
Terry Reedy wrote:
You have been hypnotizeed by lambda. (lambda n: i+n) is a *constant
expression*, so you get 10 'equal' functions.
'hypnotized' indeed! ... ok, so let me see if I get this... the lambda
defers lookup|bind of its references until such time as the lambda is
'called' and not
On Tue, 31 May 2011 01:48:05 -0500
harrismh777 harrismh...@charter.net wrote:
fs=[]
fs = [(lambda n: i + n) for i in range(10)]
[fs[i](1) for i in range(10)]
[10, 10, 10, 10, 10, 10, 10, 10, 10, 10] === not good
( that was a big surprise! . . . )
( let's try it
On Tue, May 31, 2011 at 3:14 PM, Martin Manns mma...@gmx.net wrote:
$ python
Python 2.6.6 (r266:84292, Apr 20 2011, 11:58:30)
[GCC 4.5.2] on linux2
Type help, copyright, credits or license for more information.
fs=[]
fs = [(lambda n: i + n) for i in range(10)]
[fs[i](1) for i in range(10)]
Martin Manns wrote:
After being confused I figured out it is a 3.x example:
Actually, it is a compatibility example between 2.x and 3.x, compare
below for different behavior from two seemingly identical compatible
constructs, one from 3.2, and the other from 2.6.4:
Python 3.2 (r32:88445,
harrismh777 wrote:
PS Ian calls the second construct working by mistake...
oops, actually he called it, working by accident...
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, May 31, 2011 at 2:18 PM, harrismh777 harrismh...@charter.net wrote:
If I'm understanding that correctly, then that means lambda is working as
designed, and that there are very subtle nuances to be aware of. In my
little case
(lambda n: i + n)
... if the i goes out of scope
On Wed, Jun 1, 2011 at 7:53 AM, harrismh777 harrismh...@charter.net wrote:
Having compared the two, someone please tell me whether the two are
incompatible, mostly compatible, completely incompatible, or different
languages...
By implication, every version of Python is incompatible with
On Wed, Jun 1, 2011 at 8:39 AM, Chris Angelico ros...@gmail.com wrote:
- Issue #1713: Fix os.path.ismount(), which returned true for symbolic links
across devices.
PS. I know nothing about this particular issue, I just skimmed down
the release notes and stopped when something caught my eye.
On 5/31/2011 4:18 PM, harrismh777 wrote:
Terry Reedy wrote:
You have been hypnotizeed by lambda. (lambda n: i+n) is a *constant
expression*, so you get 10 'equal' functions.
'hypnotized' indeed!
I say 'hypnotized' ;-) because people have posted examples almost
exactly like the one you
Terry Reedy wrote:
This is early-binding versus late-binding. Python is a late-binding
language.
ok ...
Are you asking about changing all function compilation or only when
functions are defined with lambda expressions?
At least lambda expressions, but (see below) any other built-in
On Tue, 31 May 2011 15:47:33 -0600
Ian Kelly ian.g.ke...@gmail.com wrote:
The i variable is part of the global scope, and as you iterate over
range(10) again it coincidentally takes on the same values as in the
original list comprehension. You don't see this in Python 3 because
the scope of
47 matches
Mail list logo