Python syntax in Lisp and Scheme

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Mon Oct 13 07:12:04 EDT 2003


On Mon, 13 Oct 2003 03:19:11 +0000, Raffael Cavallaro wrote:

> Most, but not all. From <http://okmij.org/ftp/papers/Macros-talk.pdf>
> 
> "One sometimes hears that higher-order functions (and
> related non-strictness) make macros unnecessary. For
> example, In Haskell, 'if' is a regular function.

It's not. It could easily be a regular function which would look like
'if condition branch1 branch2' and behave exactly the same (arguments
would often have to be parenthesized), but it's a keyword with the syntax
'if condition then branch1 else branch2' (condition and branches don't
have to be parenthesized because of 'then' and 'else' delimiters).
OTOH && and || are regular functions.

> So you're willing here to trade code size for readability. The pro-macro 
> camp (myself included) find that macros make source code easier to read 
> and write than the equivalent HOF solution. We're willing to trade that 
> ease of use for a little compiled code size, especially when this means 
> you can write your code in what amounts to a domain specific language.

Note that Lisp and Scheme have a quite unpleasant anonymous function
syntax, which induces a stronger tension to macros than in e.g. Ruby or
Haskell.

In Haskell one often passes around monadic actions instead of anonymous
nullary functions, so it's not only the lambda syntax. Putting such action
in a function argument doesn't make it run. Laziness also reduces the
number of anonymous functions. Partial application doesn't require lambda,
binary operators can be partially applied on either argument. The 'do'
notation and list comprehensions are another case where other languages
would use anonymous functions. Yes, they are built in the language rather
than library features - but with all these things only few anonymous
functions remain and thus they are not so scary.

I happen to be in the other camp. Macros indeed make it easier to embed a
domain-specific language, OTOH they require the rest of the syntax to be
more regular than pretty (so they can examine code) and they make the
language and its implementations complicated. Just a tradeoff...

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/





More information about the Python-list mailing list