[Python-ideas] Combining test and assignment

Mike Meyer mwm at mired.org
Sun Jan 22 23:24:12 CET 2012

On Sun, 22 Jan 2012 12:04:48 +0000
Paul Moore <p.f.moore at gmail.com> wrote:

> On 22 January 2012 04:51, Steven D'Aprano <steve at pearwood.info> wrote:
> > Assignment as an expression feels unnatural to me:
> >
> > if spam() as x != 'ham':
> >    frobulate(x)
> >
> > doesn't really correspond to any natural English order.
> While in general I agree with you, there *is* a natural reading of this:
> "if spam() isn't 'ham', frobulate it"
> The fact that you have to choose a name is because computer languages
> have to be more explicit than natural languages, and can't deal with
> the implicit referent involved in the English usage of "it".

Others have pointed out that they can. My favorite example is Paul
Graham's anaphoric macros, which bind the evaluated expression to "it"
and then call the associated blocks.

Two things of note in his discussion
(http://dunsmor.com/lisp/onlisp/onlisp_18.html). First, he provides
versions for the other conditional execution statements. Second, the
one that is *most* used - he claims even more often than the regular
version - is for while.

Mike Meyer <mwm at mired.org>		http://www.mired.org/
Independent Software developer/SCM consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

More information about the Python-ideas mailing list