[Python-ideas] explicitation lines in python ?
Bruce Leban
bruce at leapyear.org
Sat Jun 26 09:43:19 CEST 2010
I really dislike the idea that when I read an expression I'd have to scan to
the end of the statement to figure out if it's a forward or backward
reference. Is this
def foo(a, b):
return x * y:
x : a + b
y : a - b
really significantly better than:
def foo(a, b):
x = lambda: a + b
y = lambda: a - b
return x() * y()
Note that when I see the () there's an explicit marker that x and y are not
simple variables so personally I wouldn't want to "save" those few
characters. So really what you're doing is allowing me to put these in a
different order and saving 7 characters. But I can reorder them easily
enough if I want to:
def foo(a, b):
result = lambda: x() * y()
x = lambda: a + b
y = lambda: a - b
return result()
--- Bruce
http://www.vroospeak.com
http://jarlsberg.appspot.com
On Fri, Jun 25, 2010 at 11:48 PM, geremy condra <debatem1 at gmail.com> wrote:
> On Fri, Jun 25, 2010 at 11:55 PM, Chris Rebert <pyideas at rebertia.com>
> wrote:
> > On Fri, Jun 25, 2010 at 7:58 PM, Stephen J. Turnbull <stephen at xemacs.org>
> wrote:
> >> Daniel DELAY writes:
> >>
> >> > (Sorry if this has already been discussed earlier on this list, I
> have
> >> > not read all the archives)
> >>
> >> I think if you search for "first-class blocks" and "lambdas", or
> >> similar, you'll find related discussion (although not exactly the same
> >> thing). It also looks very similar to the Haskell "where", maybe
> >> searching for "Haskell where" would bring it up.
> >>
> >> > Renouncing to list comprehension occurs rather often when I write
> python
> >> > code
> >> >
> >> > I think we could greatly improve readability if we could keep list
> >> > comprehension anywhere in all cases, but when necessary explicit a
> too
> >> > complex expression in an indented line :
> >> >
> >> > htmltable = ''.join( '<tr>{}</tr>'.format(htmlline) for line in
> table):
> >> > htmlline : ''.join( '<td>{}</td>'.format(cell) for cell in line)
> >>
> >> (Edited for readability; it was munged by your mail client. ;-)
> >>
> >> I'm not sure I like this better than the alternative of rewriting the
> >> outer loops explicitly. But if you're going to add syntax, I think
> >> the more verbose
> >>
> >> htmltable = ''.join('<tr>{}</tr>'.format(htmlline) for line in table)
> \
> >> with htmlline = ''.join('<td>{}</td>'.format(cell) for cell in
> line)
> >>
> >> looks better. Note that the "with" clause becomes an optional part of
> >> an assignment statement rather than a suite controlled by the
> >> assignment, and the indentation is decorative rather than syntactic.
> >> I considered "as" instead of "=" in the with clause, but preferred the
> >> "=" because that allows nested "with" in a natural way. (Maybe, I
> >> haven't thought carefully about that at all.) Obviously "with" was
> >> chosen because it's already a keyword.
> >>
> >> I suspect this has been shot down before, though.
> >
> > Prior thread:
> > [Python-ideas] Where-statement (Proposal for function expressions)
> > http://mail.python.org/pipermail/python-ideas/2009-July/005114.html
>
> I was all set to dislike this syntax, but after reading over it a bit I
> find myself liking it a lot. Was the code for this (or similar) ever
> written, or was it just proposed?
>
> Geremy Condra
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100626/7a44658a/attachment.html>
More information about the Python-ideas
mailing list