str % vals -like idea but for statements
Dan Schmidt
dfan at dfan.org
Wed Feb 12 09:43:02 EST 2003
Beni Cherniavsky <cben at techunix.technion.ac.il> writes:
| On 2003-02-11, Dan Schmidt wrote:
|
|> I don't think I will ever fully get used to 'and' being of type
|>
|> (bool, T) -> T
|>
| It's not. It's (T, T) -> T!
Right :) Or I guess more accurately it's (T1, T2) -> T1 | T2 (yecch)
| What a handy starting point. I have had this new idea for the last days:
| I want the analog of ``str % vals`` for statements.
|
| [...]
|
| My proposal
| ===========
|
| Allow adding a class-like indented block of code to any simple statement,
| with the semantics that the block is evaluated first and the statement is
| the evaluated with the block's variables in scope. Here is how you do a
| conditional expression morea readably with it::
|
| print "Complex text about", n, things where:
| if n == 1:
| things = "thing"
| else:
| things = "things"
| print "More code..."
|
| True, it's not more compact but it's more arguably more readable.
Haskell does this (with the same keyword) and I like it very much
there. I would like it fine in Python too (though I don't really miss
it), but given Python's history and philosophy of keeping the language
small, I don't see much chance of it being added.
Dan
--
http://www.dfan.org
More information about the Python-list
mailing list