Python syntax in Lisp and Scheme

Ed Avis ed at membled.com
Sat Oct 4 15:46:26 EDT 2003


mike420 at ziplip.com writes:

>I'd like to know if it may be possible to add a powerful macro system
>to Python, while keeping its amazing syntax,

I fear it would not be.  I can't say for certain but I found that the
syntax rules out nesting statements inside expressions (without adding
some kind of explicit bracketing, which rather defeats the point of
Python syntax) and you might run into similar difficulties if adding
macros.  It's a very clean syntax (well, with a few anomalies) but
this is at the price of a rigid separation between statements and
expressions, which doesn't fit well with the Lisp-like way of doing
things.

Myself I rather like the option chosen by Haskell, to define an
indentation-based syntax which is equivalent to one with bracketing,
and let you choose either.  You might do better to add a new syntax to
Lisp than to add macro capabilities to Python.  Dylan is one Lisp
derivative with a slightly more Algol-like syntax, heh, Logo is
another; GNU proposed some thing called 'CTAX' which was a C-like
syntax for Guile Scheme, I don't know if it is usable.

If the indentation thing appeals, maybe you could preprocess Lisp
adding a new kind of bracket - say (: - which closes at the next line
of code on the same indentation level.  Eg

    (: hello
       there
    (goodbye)

would be equivalent to

    (hello
     there)
    (goodbye)

I dunno, this has probably already been done.

-- 
Ed Avis <ed at membled.com>




More information about the Python-list mailing list