Re: How to create functors?

2009-08-22 Thread Paul Rubin
Steven D'Aprano ste...@remove.this.cybersource.com.au writes: According to Wikipedia, functor can be used as a synonym for function object: ... http://en.wikipedia.org/wiki/Function_object Hmm, I hadn't seen that usage before. I guess there's no law against it, but it seems a bit bogus to me.

Re: How to create functors?

2009-08-20 Thread Rami Chowdhury
As near as I can tell, a functor is just an object which is callable like a function I believe that's how they're defined in the C++ world, in which, of course, functions aren't first-class objects... - Rami Chowdhury Never assume malice when stupidity will suffice. -- Hanlon's

Re: How to create functors?

2009-08-20 Thread Paul Rubin
Steven D'Aprano ste...@remove.this.cybersource.com.au writes: As near as I can tell, a functor is just an object which is callable like a function without actually being implemented as a function, e.g.: No it's not anything like that either, at least as I'm used to the term in programming or

Re: How to create functors?

2009-08-20 Thread Steven D'Aprano
On Thu, 20 Aug 2009 01:36:14 -0700, Paul Rubin wrote: Steven D'Aprano ste...@remove.this.cybersource.com.au writes: As near as I can tell, a functor is just an object which is callable like a function without actually being implemented as a function, e.g.: No it's not anything like that

Re: How to create functors?

2009-08-20 Thread Charles Yeomans
On Aug 20, 2009, at 5:25 AM, Steven D'Aprano wrote: On Thu, 20 Aug 2009 01:36:14 -0700, Paul Rubin wrote: Steven D'Aprano ste...@remove.this.cybersource.com.au writes: As near as I can tell, a functor is just an object which is callable like a function without actually being implemented as

Re: How to create functors?

2009-08-19 Thread Bruno Desthuilliers
Terry Reedy a écrit : Robert Dailey wrote: I'm using Python 2.6. And using the legacy syntax in the lambda does not work either. I want to avoid using a def if possible. Thanks. In Python, writing name = lambda arg: expr instead of def name(arg): return expr is all negative and no

Re: How to create functors?

2009-08-19 Thread J. Cliff Dyer
On Wed, 2009-08-19 at 15:56 +0200, Bruno Desthuilliers wrote: Terry Reedy a écrit : Robert Dailey wrote: I'm using Python 2.6. And using the legacy syntax in the lambda does not work either. I want to avoid using a def if possible. Thanks. In Python, writing name = lambda arg:

Re: How to create functors?

2009-08-19 Thread Paul Rubin
Robert Dailey rcdai...@gmail.com writes: I want to simply wrap a function up into an object so it can be called with no parameters. Nitpick: what you are asking for is called a closure. Functor means something completely different. As a few other people have explained, print in python 2.x is

Re: How to create functors?

2009-08-19 Thread Steven D'Aprano
On Wed, 19 Aug 2009 18:42:32 -0700, Paul Rubin wrote: Robert Dailey rcdai...@gmail.com writes: I want to simply wrap a function up into an object so it can be called with no parameters. Nitpick: what you are asking for is called a closure. Functor means something completely different.

Re: How to create functors?

2009-08-19 Thread Terry Reedy
Robert Dailey wrote: I'm using Python 2.6. And using the legacy syntax in the lambda does not work either. I want to avoid using a def if possible. Thanks. In Python, writing name = lambda arg: expr instead of def name(arg): return expr is all negative and no positive and should be

Re: How to create functors?

2009-08-18 Thread Duncan Booth
Robert Dailey rcdai...@gmail.com wrote: Hello, I want to simply wrap a function up into an object so it can be called with no parameters. The parameters that it would otherwise have taken are already filled in. Like so: print1 = lambda: print( Foobar ) print1() However,

Re: How to create functors?

2009-08-18 Thread Robert Dailey
On Aug 18, 3:31 pm, Duncan Booth duncan.bo...@invalid.invalid wrote: Robert Dailey rcdai...@gmail.com wrote: Hello, I want to simply wrap a function up into an object so it can be called with no parameters. The parameters that it would otherwise have taken are already filled in. Like so:

Re: How to create functors?

2009-08-18 Thread Robert Dailey
On Aug 18, 3:31 pm, Duncan Booth duncan.bo...@invalid.invalid wrote: Robert Dailey rcdai...@gmail.com wrote: Hello, I want to simply wrap a function up into an object so it can be called with no parameters. The parameters that it would otherwise have taken are already filled in. Like so:

Re: How to create functors?

2009-08-18 Thread Chris Rebert
On Tue, Aug 18, 2009 at 1:32 PM, Robert Daileyrcdai...@gmail.com wrote: On Aug 18, 3:31 pm, Duncan Booth duncan.bo...@invalid.invalid wrote: Robert Dailey rcdai...@gmail.com wrote: Hello, I want to simply wrap a function up into an object so it can be called with no parameters. The

Re: How to create functors?

2009-08-18 Thread Robert Dailey
On Aug 18, 3:40 pm, Chris Rebert c...@rebertia.com wrote: On Tue, Aug 18, 2009 at 1:32 PM, Robert Daileyrcdai...@gmail.com wrote: On Aug 18, 3:31 pm, Duncan Booth duncan.bo...@invalid.invalid wrote: Robert Dailey rcdai...@gmail.com wrote: Hello, I want to simply wrap a function up into

Re: How to create functors?

2009-08-18 Thread Rami Chowdhury
Lambda expressions are, I believe, syntactically limited to a single expression -- no statements, like 'print' is in Python 2.x. If you are strongly against just defining a function, you might have to use a trick to get around it -- this page

Re: How to create functors?

2009-08-18 Thread Ned Deily
In article c217c4a4-b891-469e-af4f-4e44e2c95...@z24g2000yqb.googlegroups.com, Robert Dailey rcdai...@gmail.com wrote: On Aug 18, 3:31 pm, Duncan Booth duncan.bo...@invalid.invalid wrote: Robert Dailey rcdai...@gmail.com wrote: Hello, I want to simply wrap a function up into an object

Re: How to create functors?

2009-08-18 Thread Jan Kaliszewski
18-08-2009 o 22:32:55 Robert Dailey rcdai...@gmail.com wrote: On Aug 18, 3:31 pm, Duncan Booth duncan.bo...@invalid.invalid wrote: Robert Dailey rcdai...@gmail.com wrote: Hello, I want to simply wrap a function up into an object so it can be called with no parameters. The parameters that

Re: How to create functors?

2009-08-18 Thread Robert Dailey
On Aug 18, 3:45 pm, Rami Chowdhury rami.chowdh...@gmail.com wrote: Lambda expressions are, I believe, syntactically limited to a single   expression -- no statements, like 'print' is in Python 2.x. If you are strongly against just defining a function, you might have to   use a trick to get

Re: How to create functors?

2009-08-18 Thread Robert Dailey
On Aug 18, 3:51 pm, Jan Kaliszewski z...@chopin.edu.pl wrote: 18-08-2009 o 22:32:55 Robert Dailey rcdai...@gmail.com wrote: On Aug 18, 3:31 pm, Duncan Booth duncan.bo...@invalid.invalid wrote: Robert Dailey rcdai...@gmail.com wrote: Hello, I want to simply wrap a function up into

Re: How to create functors?

2009-08-18 Thread Jerry Hill
On Tue, Aug 18, 2009 at 4:27 PM, Robert Daileyrcdai...@gmail.com wrote: Hello, I want to simply wrap a function up into an object so it can be called with no parameters. The parameters that it would otherwise have taken are already filled in. Like so:      print1 = lambda: print( Foobar )

Re: How to create functors?

2009-08-18 Thread Rami Chowdhury
why am I able to use print as a function in general-purpose code in my Python 2.6 script I believe it's because that is parsed as the print statement followed by a parenthesized expression. On Tue, 18 Aug 2009 13:42:59 -0700, Robert Dailey rcdai...@gmail.com wrote: On Aug 18, 3:40 pm,

Re: How to create functors?

2009-08-18 Thread Grant Edwards
On 2009-08-18, Robert Dailey rcdai...@gmail.com wrote: Hello, I want to simply wrap a function up into an object so it can be called with no parameters. The parameters that it would otherwise have taken are already filled in. Like so: print1 = lambda: print( Foobar ) print1()

Re: How to create functors?

2009-08-18 Thread Leonhard Vogt
The example I gave earlier is a bit contrived, the real example fundamentally requires a lambda since I am actually passing in local variables into the functions the lambda is wrapping. Example: def MyFunction(): localVariable = 20 CreateTask( lambda: SomeOtherFunction( localVariable ) ) #

Re: How to create functors?

2009-08-18 Thread Diez B. Roggisch
The example I gave earlier is a bit contrived, the real example fundamentally requires a lambda since I am actually passing in local variables into the functions the lambda is wrapping. Example: funcs = [] for i in xrange(10): def f(i=i): print i funcs.append(f) for f in

Re: How to create functors?

2009-08-18 Thread Jan Kaliszewski
Dnia 18-08-2009 o 22:51:19 Robert Dailey rcdai...@gmail.com napisał(a): The example I gave earlier is a bit contrived, the real example fundamentally requires a lambda since I am actually passing in local variables into the functions the lambda is wrapping. Example: def MyFunction():