Python syntax in Lisp and Scheme

Dirk Thierbach dthierbach at gmx.de
Tue Oct 7 14:06:11 EDT 2003


james anderson <james.anderson at setf.de> wrote:
> Matthias Blume wrote:

>> Most of the things that macros can do can be done with HOFs with just
>> as little source code duplication as with macros.  (And with macros
>> only the source code does not get duplicated, the same not being true
>> for compiled code.  With HOFs even executable code duplication is
>> often avoided -- depending on compiler technology.)

> is the no advantage to being able to do either - or both - as the
> occasion dictates?

I can't parse this sentence, but of course you can also use HOFs in Lisp
(all flavours). The interesting part is that most Lisp'ers don't seem
to use them, or even to know that you can use them, and use macros instead.

The only real advantage of macros over HOFs is that macros are guaranteed
to to executed at compile time. A good optimizing compiler (like GHC
for Haskell) might actually also evaluate some expressions including
HOFs at compile time, but you have no control over that. 

> i'd be interested to read examples of things which are better done
> with HOF features which are not available in CL.

HOFs can of course be used directly in CL, and you can use macros to
do everything one could use HOFs for (if you really want).

The advantage of HOFs over macros is simplicity: You don't need additional
language constructs (which may be different even for different Lisp
dialects, say), and other tools (like type checking) are available for
free; and the programmer doesn't need to learn an additional concept.

- Dirk




More information about the Python-list mailing list