[Python-ideas] Statements vs Expressions... why?

Cliff Wells cliff at develix.com
Thu Sep 11 20:19:24 CEST 2008


On Thu, 2008-09-11 at 13:48 -0400, Mike Meyer wrote:
> On Thu, 11 Sep 2008 10:40:29 -0700
> Cliff Wells <cliff at develix.com> 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#3.1
> 
> 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




More information about the Python-ideas mailing list