Re: Alternative to multi-line lambdas: Assign-anywhere def statements

2015-02-12 Thread Ian Kelly
On Wed, Feb 11, 2015 at 8:56 PM, Chris Angelico wrote: > On Thu, Feb 12, 2015 at 1:57 PM, Ian Kelly wrote: >> The reason I don't like this replacing def isn't because the name is >> necessarily lost. It's because the lack of the well-defined def >> statement encourages more complex usages like >>

Re: Alternative to multi-line lambdas: Assign-anywhere def statements

2015-02-11 Thread Chris Angelico
On Thu, Feb 12, 2015 at 1:57 PM, Ian Kelly wrote: > The reason I don't like this replacing def isn't because the name is > necessarily lost. It's because the lack of the well-defined def > statement encourages more complex usages like > > functions['f'] = x -> x**2 > > where such implicit tran

Re: Alternative to multi-line lambdas: Assign-anywhere def statements

2015-02-11 Thread Ian Kelly
On Wed, Feb 11, 2015 at 7:06 PM, Terry Reedy wrote: >> I can't see why the parser would understand more easily >> >> def f(x): >> return x**2 >> than >> >> f = x-> >> return x**2 > > > The parser parses both equally well. That is not the issue. The compiler could at some point recogniz

Re: Alternative to multi-line lambdas: Assign-anywhere def statements

2015-02-11 Thread Terry Reedy
On 2/11/2015 8:04 AM, Albert van der Horst wrote: It is not until we assign the object to a name (which becomes thereby a function) that the __name__ thingy comes into play, like so. But __name__ would not come into play. f = x->x**2 This would mean to create an anonymous function object

Re: Alternative to multi-line lambdas: Assign-anywhere def statements

2015-02-11 Thread Ethan Furman
On 02/11/2015 05:04 AM, Albert van der Horst wrote: > That's the reason why my ideal Python doesn't attach a name to a lambda > denotation: > > x -> x**2 Hmmm. So now let's say you have a few dozen of these types of functions, and you want to talk about the twenty-sixth one with a peer... are

Re: Alternative to multi-line lambdas: Assign-anywhere def statements

2015-02-11 Thread Clarence
On Wednesday, February 11, 2015 at 8:04:33 AM UTC-5, Albert van der Horst wrote: > In article , > Ethan Furman wrote: > >-=-=-=-=-=- > > > >On 01/24/2015 11:55 AM, Chris Angelico wrote: > >> On Sun, Jan 25, 2015 at 5:56 AM, Ethan Furman wrote: > >>> If the non-generic is what you're concerned ab

Re: Alternative to multi-line lambdas: Assign-anywhere def statements

2015-02-11 Thread Albert van der Horst
In article , Ethan Furman wrote: >-=-=-=-=-=- > >On 01/24/2015 11:55 AM, Chris Angelico wrote: >> On Sun, Jan 25, 2015 at 5:56 AM, Ethan Furman wrote: >>> If the non-generic is what you're concerned about: >>> >>> # not tested >>> dispatch_table_a = {} >>> dispatch_table_b = {} >>> dispatch_tabl

Re: Alternative to multi-line lambdas: Assign-anywhere def statements

2015-01-25 Thread Steven D'Aprano
Yawar Amin wrote: > Hi Steven, > > On Saturday, January 24, 2015 at 11:27:33 PM UTC-5, Steven D'Aprano > wrote: >> [...] >> > Doesn't the traceback tell us exactly where the lambda was called >> > from? >> >> Yes (assuming the source code is available, which it may not be), but > > If the sourc

Re: Alternative to multi-line lambdas: Assign-anywhere def statements

2015-01-25 Thread Yawar Amin
Hi Steven, On Saturday, January 24, 2015 at 11:27:33 PM UTC-5, Steven D'Aprano wrote: > [...] > > Doesn't the traceback tell us exactly where the lambda was called > > from? > > Yes (assuming the source code is available, which it may not be), but If the source code is not available, then you're

Re: Alternative to multi-line lambdas: Assign-anywhere def statements

2015-01-24 Thread Devin Jeanpierre
On Sat, Jan 24, 2015 at 5:58 PM, Ethan Furman wrote: > On 01/24/2015 11:55 AM, Chris Angelico wrote: >> On Sun, Jan 25, 2015 at 5:56 AM, Ethan Furman wrote: >>> If the non-generic is what you're concerned about: >>> >>> # not tested >>> dispatch_table_a = {} >>> dispatch_table_b = {} >>> dispatch

Re: Alternative to multi-line lambdas: Assign-anywhere def statements

2015-01-24 Thread Steven D'Aprano
Yawar Amin wrote: > Hi Ethan, > > On Saturday, January 24, 2015 at 9:00:12 PM UTC-5, Ethan Furman wrote: >> [...] >> __name__ being one of them. One of the reasons lambda >> is not encouraged is because its name is always '', which just >> ain't helpful when the smelly becomes air borne! ;) >

Re: Alternative to multi-line lambdas: Assign-anywhere def statements

2015-01-24 Thread Yawar Amin
Hi Ethan, On Saturday, January 24, 2015 at 9:00:12 PM UTC-5, Ethan Furman wrote: > [...] > __name__ being one of them. One of the reasons lambda > is not encouraged is because its name is always '', which just > ain't helpful when the smelly becomes air borne! ;) Doesn't the traceback tell us e

Re: Alternative to multi-line lambdas: Assign-anywhere def statements

2015-01-24 Thread Ethan Furman
On 01/24/2015 11:55 AM, Chris Angelico wrote: > On Sun, Jan 25, 2015 at 5:56 AM, Ethan Furman wrote: >> If the non-generic is what you're concerned about: >> >> # not tested >> dispatch_table_a = {} >> dispatch_table_b = {} >> dispatch_table_c = {} >> >> class dispatch: >> def __init__(self, dis

Re: Alternative to multi-line lambdas: Assign-anywhere def statements

2015-01-24 Thread Yawar Amin
Hi, On Saturday, January 24, 2015 at 3:36:04 PM UTC-5, Devin Jeanpierre wrote: > [...] > Obviously, nobody will be happy until you can do: > > def call(*a, **kw): return lambda f: f(*a, **kw) > > @call() > def x, y (): > yield 1 > yield 2 > > Actually, maybe not even then. You're proba

Re: Alternative to multi-line lambdas: Assign-anywhere def statements

2015-01-24 Thread MRAB
On 2015-01-24 19:55, Chris Angelico wrote: On Sun, Jan 25, 2015 at 5:56 AM, Ethan Furman wrote: If the non-generic is what you're concerned about: # not tested dispatch_table_a = {} dispatch_table_b = {} dispatch_table_c = {} class dispatch: def __init__(self, dispatch_table): self.disp

Re: Alternative to multi-line lambdas: Assign-anywhere def statements

2015-01-24 Thread Devin Jeanpierre
On Sat, Jan 24, 2015 at 11:55 AM, Chris Angelico wrote: > That's still only able to assign to a key of a dictionary, using the > function name. There's no way to represent fully arbitrary assignment > in Python - normally, you can assign to a name, an attribute, a > subscripted item, etc. (Augment

Re: Alternative to multi-line lambdas: Assign-anywhere def statements

2015-01-24 Thread Chris Angelico
On Sun, Jan 25, 2015 at 5:56 AM, Ethan Furman wrote: > If the non-generic is what you're concerned about: > > # not tested > dispatch_table_a = {} > dispatch_table_b = {} > dispatch_table_c = {} > > class dispatch: > def __init__(self, dispatch_table): > self.dispatch = dispatch_table > de

Re: Alternative to multi-line lambdas: Assign-anywhere def statements

2015-01-24 Thread Ethan Furman
On 01/23/2015 10:28 PM, Chris Angelico wrote: > > cmd = {} > def command(func): > cmd[func.__name__] = func > return func > > @command > def foo(*args): > print("You asked to foo.") > > but this is hardly generic. There's no convenient way to give an > argument to a decorator that sa

Re: Alternative to multi-line lambdas: Assign-anywhere def statements

2015-01-24 Thread Tim Chase
On 2015-01-24 17:28, Chris Angelico wrote: > but this is hardly generic. There's no convenient way to give an > argument to a decorator that says "please assign this here", short > of using some stupid eval hack... is there? > > (Incidentally, for a non-generic dispatch table, a callable dict > su

Alternative to multi-line lambdas: Assign-anywhere def statements

2015-01-23 Thread Chris Angelico
In some random and rambling discussion about Python, the notion came up that multi-line lambda functions are often sought as a means of populating dictionaries and other such structures. Conceptually, "def foo(...): ..." is broadly equivalent to "foo = FunctionType(...)"; but the only type of assig