"Ted Lilley" <[EMAIL PROTECTED]> writes:
> What I want to do is pre-load functions with arguments by iterating
> through a list like so:
>
> >>>class myclass:
> ...pass
> >>>def func(self, arg):
> ...print arg
> >>>mylist = ["my", "sample", "list"]
> >>>for item in mylist:
> ...setatt
Antoon Pardon wrote:
def F():
... l = []
... def pop():
... return l.pop()
... def push(e):
... l.append(e)
... return pop, push
...
Just a side note to point out that another way of writing this is:
py> def F():
... l = []
... return l.pop, l.append
...
You'll get the same
Carl Banks wrote:
transformations gets rebound, so you'd need a reference to it.
That certainly is an application. I guess it depends on one's
programming background.
I'd only use nested (function, class) definition to accomplish
such a feature:
def genclass(x,y):
clas
> I have the impression that you misunderstood me. I'm not after a
> side-effect free language. I just think python could be nicer in
> allowing some side-effects.
Yeah, seems as if I somehow added an inadvertent "not" somewhere in my train
of thoughts while reading (and hopfully comprehending...)
Paul Rubin wrote:
> "Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
>> It's not only that way in python, but in java too. So it seems that there
>> is a fundamental principle behind it: In a language that allows
>> sideeffects, these will actually happen.
>
> Can you even have nested functions in
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
> It's not only that way in python, but in java too. So it seems that there is
> a fundamental principle behind it: In a language that allows sideeffects,
> these will actually happen.
Can you even have nested functions in Java? Algol-60 did things t
Op 2005-02-21, Diez B. Roggisch schreef <[EMAIL PROTECTED]>:
>> But I'll get back at what seems you actually wanted to say:
>> That there is no way to rebind 'x' or in my case 'l' and
>> with that I have to agree although I personnaly find that
>> a lack in python
>
> It's not only that way in pyth
Antoon Pardon wrote:
> But I'll get back at what seems you actually wanted to say:
> That there is no way to rebind 'x' or in my case 'l' and
> with that I have to agree although I personnaly find that
> a lack in python
'no way' is a bit strong. You can use hacks such as the one I posted a
coup
> But I'll get back at what seems you actually wanted to say:
> That there is no way to rebind 'x' or in my case 'l' and
> with that I have to agree although I personnaly find that
> a lack in python
It's not only that way in python, but in java too. So it seems that there is
a fundamental princip
Op 2005-02-21, jfj schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>> Op 2005-02-19, jfj schreef <[EMAIL PROTECTED]>:
>>
>>>once foo() returns there is no way to modify 'x'!
>>>It becomes a kind of constant.
>>
>>
>> In this particular case yes. But not in general, what about
>> this:
>>
>>
Antoon Pardon wrote:
Op 2005-02-19, jfj schreef <[EMAIL PROTECTED]>:
once foo() returns there is no way to modify 'x'!
It becomes a kind of constant.
In this particular case yes. But not in general, what about
this:
def F():
... l = []
... def pop():
... return l.pop()
... def push(e):
Op 2005-02-19, jfj schreef <[EMAIL PROTECTED]>:
> Carl Banks wrote:
>> Ted Lilley wrote:
>>
>>
>>>Unfortunately, it doesn't work. It seems the closure keeps track of
>>>the variable fed to it dynamically - if the variable changes after
>> [...]
>>>
>>>At least, that's the explanation I'm deduci
jfj wrote:
> The costly extra feature is this:
> ###
> def foo():
> def f():
> print x
> x=1
> f()
> x=2
> f()
> return f
> foo()()
> #
> which prints '1 2 2'
>
> The fractal code runs a little _slower_ because of this ability.
> Alth
Mike Meyer wrote:
> "Carl Banks" <[EMAIL PROTECTED]> writes:
>
> > Say you have a suite of functions, all of which are called by some
main
> > function and each other, and all of which need to access a lot of
the
> > same data. The best, most straightforward way to do it is to have
the
> > common
"Carl Banks" <[EMAIL PROTECTED]> writes:
> Say you have a suite of functions, all of which are called by some main
> function and each other, and all of which need to access a lot of the
> same data. The best, most straightforward way to do it is to have the
> common data be a local variable of t
Ted Lilley <[EMAIL PROTECTED]> wrote:
> As a side note, I'm familiar with the term currying from a friend who
> learned ML and Scheme quite some time ago. Not sure if that's the true
> origin, but it was a sufficiently different context from Python (or at
> least I thought) that I didn't want to r
Carl Banks wrote:
Say you want to calculate a list of points of an iterated fractal.
Here's the idea: you have a set of linear transformations. You take
the origin (0,0) as the first point, and then apply each transformation
in turn to get a new point. You recursively apply each transformation
at
Carl Banks wrote:
> Say you have a suite of functions, all of which are called by some
main
> function and each other, and all of which need to access a lot of the
> same data. The best, most straightforward way to do it is to have
the
> common data be a local variable of the main function, and n
jfj wrote:
> Yes, but according to the python philosophy one could pass locals()
> to the nested function and grab the values from there. Seems
practical
> for the rareness of this...
First of all, I really don't agree that it's a rare need. I use it
pretty often.
Second of all, the whole point
I replied a few minutes ago thanking everyone for their pointers. Very
interesting reading. I don't see my post yet, so I do hope it comes
through. I'm using a new newsreading service and don't yet have
confidence in it.
In any case, the addition of the default-setting argument in the lambda
wo
Wow, a lot of great discussion. Almost a bit too much for me to
grasp...I do see two or more nuggets that really address my issue.
As a side note, I'm familiar with the term currying from a friend who
learned ML and Scheme quite some time ago. Not sure if that's the true
origin, but it was a suf
Carl Banks wrote:
You may not be aware of it, but what you're trying to do is called
"currying"; you might want to search the Python Cookbook for recipes on
it.
Or look for "partial function application" which has been argued to be
the correct term for this use... Also see PEP 309:
http://www.py
Ted Lilley wrote:
What I want to do is pre-load functions with arguments by iterating
through a list like so:
class myclass:
...pass
def func(self, arg):
...print arg
mylist = ["my", "sample", "list"]
for item in mylist:
...setattr(myclass, item, lamdba self: func(self, item))
This att
Carl Banks wrote:
jfj wrote:
Carl Banks wrote:
Ted Lilley wrote:
Unfortunately, it doesn't work. It seems the closure keeps track
of
the variable fed to it dynamically - if the variable changes after
[...]
At least, that's the explanation I'm deducing from this behavior.
And that's the correct ex
jfj wrote:
> Carl Banks wrote:
> > Ted Lilley wrote:
> >
> >
> >>Unfortunately, it doesn't work. It seems the closure keeps track
of
> >>the variable fed to it dynamically - if the variable changes after
> > [...]
> >>
> >>At least, that's the explanation I'm deducing from this behavior.
> >
> >
Carl Banks wrote:
Ted Lilley wrote:
Unfortunately, it doesn't work. It seems the closure keeps track of
the variable fed to it dynamically - if the variable changes after
[...]
At least, that's the explanation I'm deducing from this behavior.
And that's the correct explanation, chief.
It is in
Ted Lilley wrote:
> What I want to do is pre-load functions with arguments by iterating
> through a list like so:
>
> >>>class myclass:
> ...pass
> >>>def func(self, arg):
> ...print arg
> >>>mylist = ["my", "sample", "list"]
> >>>for item in mylist:
> ...setattr(myclass, item, lamdba s
What I want to do is pre-load functions with arguments by iterating
through a list like so:
>>>class myclass:
...pass
>>>def func(self, arg):
...print arg
>>>mylist = ["my", "sample", "list"]
>>>for item in mylist:
...setattr(myclass, item, lamdba self: func(self, item))
This attaches
28 matches
Mail list logo