cathoderay/minifyme — pull request #1 by rhcarvalho (2011-11-20 11:28:25+00:00)
Title: Nano contribution to style

Hi Ronald, the rationale for this commit is, as per PEP8:
--
The preferred way of wrapping long lines is by using Python's implied line
continuation inside parentheses, brackets and braces. Long lines can be
broken over multiple lines by wrapping expressions in parentheses. These
should be used in preference to using a backslash for line continuation.
--

My ultimate goal was to do something lispy like (and cond1 cond2 cond3 ...). That in Python is *almost* equivalent to all([cond1, cond2, cond3]) the difference being Lisp's (and) is a macro and only evaluates arguments when needed (doing proper short-circuiting), whereas Python's all() is a function call that takes a list, and therefore all arguments (think of the elements of the list) are evaluated prior to the function getting control, leaving no room for short-circuiting. So, in this sense, Python is (and I feel bad to say) a not so powerful language. Where are the Python macros?!

To implement something that would behave externally more like (and ...) we would need to implement lazy evaluation, for example using lambdas.

all2([lambda: cond1, lambda: cond2, ...])

And all2 cannot be the same as all. All2 must call each arg[i] when appropriate.

Still we couldn't have infinite lists of conditions... could we? Before all2 gets to do its job, we'd have to figure out the whole list. A solution would be all3, which takes as argument an iterator. As long as we can get the next element, we're good to go.

[]'s

Rodolfo