Re: [Python-ideas] Statements vs Expressions... why?
On Thu, 2008-09-11 at 13:48 -0400, Mike Meyer wrote:
On Thu, 11 Sep 2008 10:40:29 -0700 Cliff Wells
wrote: Several examples have already been posted in this thread (which has probably gone on long enough).
Yes, I mentioned them. Roughly half have come from *other* people, so they don't count.
Since they were more or less exactly what I had in mind, I think they suffice.
If you really believe the thread has gone on long enough, then the proposal is dead. If you are actually interested in seeing it happen, then the real obstacle is that expressions built out of statements that use indentation for control flow are *ugly*.
That's only for people not used to seeing them or programming in that style. Proponents of functional and expression-oriented languages would strongly disagree. Whether or not they might be ugly *in Python* is a seemingly separate question, but I don't think it is. In fact, it seems it would be much more attractive than many traditional FP languages.
If you have a way around it, I'd love to see it. If you don't - then again, the proposal is dead.
Anyway, as was mentioned earlier, Logix very much resembles what I'm describing:
http://www.livelogix.net/logix/tutorial/3-Introduction-For-Python-Folks.html...
That link doesn't have any examples, it just repeats many of the words that have already been posted.
Yes, the Logix documentation is sorely lacking (I believe the project to be long-dead), but the intent seemed clear enough to me.
If you have a link with real live examples - in particular, showing how you can use for loops to replace lcs and similar things, please provide it.
From an earlier example I posted:
dispatch = { '1': lambda x: ( for i in range(x): if not x % 2: yield 0 else: yield 1 ), '2': lambda x: ( for i in range(x): yield i ) } for i in dispatch[val](1): print i Overall, if you are familiar with functional programming, it doesn't take a lot to imagine more examples. If you aren't, then it probably won't make much sense or seem too appealing in any case. Regards, Cliff
Cliff Wells wrote:
If you have a link with real live examples - in particular, showing how you can use for loops to replace lcs and similar things, please provide it.
From an earlier example I posted:
dispatch = { '1': lambda x: ( for i in range(x): if not x % 2: yield 0 else: yield 1 ),
'2': lambda x: ( for i in range(x): yield i ) }
for i in dispatch[val](1): print i
To me, this is the most (perhaps only ;-) readable such example. But it is unnecessary. Even without metaclasses, as someone else suggested (and thank you for the idea), the following works today, and is even more readable to me. class disclass(): # 3.0 def f1(x): for i in range(x): if not x % 2: yield 0 else: yield 1 def f2(x): for i in range(x): yield i dispatch = disclass.__dict__ val = '1' for i in dispatch['f'+val](2): print(i) for i in dispatch['f'+val](3): print(i) val = '2' for i in dispatch['f'+val](4): print(i)
0 0 1 1 1 0 1 2 3
In 3.0, a class decorator could, I believe, both replace the class with its dict, and strip the leading 'f' from the 'fn' keys. So there is another 'need' for generalized lambda that isn't. Terry Jan Reedy
participants (2)
-
Cliff Wells
-
Terry Reedy