[Python-ideas] Where-statement (Proposal for function expressions) (original) (raw)
Carl Johnson cmjohnson.mailinglist at gmail.com
Thu Jul 16 01:12:17 CEST 2009
- Previous message: [Python-ideas] Where-statement (Proposal for function expressions)
- Next message: [Python-ideas] Where-statement (Proposal for function expressions)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Daniel Stutzbach wrote:
Unlikely, but this is:
total =3D sum(f(item) for item in lst) where: def f(item): return item.size if item.size > 0 else 1
Yes, that seems much more sensible than trying to repeat the where's inside of list comp or gen exp.
Daniel Stutzbach wrote:
How about the following as additional syntactic sugar for the common one-= function case?
x =3D blah(f) where def f(item): bodyoff
I like it.
Gerald Britton wrote:
Why not just use the Haskell approach?
foo(x,y) =3D myfunc(bar) where: =A0 =A0 =A0 =A0 =A0 myfunc, bar =3D f(x), g(y) where: =A0 =A0 =A0 =A0 =A0 =A0 =A0f,g =3D func1, func2
Because I've been looking at that for a couple minutes and still have no idea what it is supposed to mean. :-( List comprehensions and pattern matching are the only Haskell features that make any sense to me.
Jan Kaliszewski wrote:
I don't like the direction of limiting content of the block to set of sin= gular simple statements. I suppose where-block should simply create a separ= ate nested scope.
Yes. It strikes me that one of the problems with Ruby is that there are different scoping rules for blocks, lambda, methods, procs, and whatever else=85 It would be much easier for users if "where" blocks had the exact same scoping rules as functions. Daniel Stutzbach's suggested equivalence strikes me as exactly correct:
[return|yield|x=3D] expression_list where: suite
is roughly equivalent to:
def where_expression(): suite return expression_list [return|yield|x=3D] where_expression()
-- Carl Johnson
- Previous message: [Python-ideas] Where-statement (Proposal for function expressions)
- Next message: [Python-ideas] Where-statement (Proposal for function expressions)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]