Why is Python popular, while Lisp and Scheme aren't?

Michael Hudson mwh at python.net
Wed Nov 13 08:37:50 EST 2002


Carl Banks <imbosol at vt.edu> writes:

> Martin Maney wrote:
> > I'd love to "get" why some form of assignment on the fly is so evil that we
> > have to invent hacks to work around its lack over and over again (recipie
> > 1.9 in the Cookbook).  The lack interacts especially badly with a language
> > where indentation is a mandantory part of the control structure.  :-(
> 
> Well, I highly disagree that changing assignment semantics is the
> solution to this, for three reasons.  First, I have a general distaste
> for anything that returns a value and has side effects.  Second, it
> leads to all kinds of unreadability in the code by people abusing it.
> Third, it is an incomplete solution.
> 
> The idiom you speak of is common enough.
> 
> do_A()
> if test_based_on_A():
>     take_action_A()
> else:
>     do_B()
>     if test_based_on_B():
>         take_action_B()
>     else:
>         do_C()
>         if test_based_in_C():
>             take_action_C()
>         else:
>             ...

*This* is asking to be written as a loop:

for (prelim, test, action) in [(do_A, test_based_on_A, take_action_A),
                               (do_B, test_based_on_B, take_action_B),
                               (do_C, test_based_on_C, take_action_C)]:
    prelim()
    if test():
       action()
       break
else:
    whatever()

I often find that it's possible to wrap up fairly complicated control
flows like this in a neat way, but often it takes a bit of staring to
come up with it.  Isn't there a pithy quote along the lines of
"constraints spark creativity"?

[...]
> And, getting this back to the topic, you could do this if Python had
> macros.  But I agree with Alex here; Python isn't the language for
> that.  That's why we have Lisp.  Having the occasional useful syntax
> not available (tryexcept anyone? conditional operator?) is a price
> you pay sometimes.

The only biggy for me is the lack of Lisp style (with-... ) macros;
which of these do you prefer:

def 

-- 
3. Syntactic sugar causes cancer of the semicolon.
  -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html



More information about the Python-list mailing list