"David A. Black" <dblack / wobblini.net> writes:

> Hi --
>
> On Tue, 3 Aug 2004, James Britt wrote:
>
>> David Alan Black mentioned macros as (possibly) a facility for 
>> introducing arbitrary syntax.  I'm no Lisper, but no examples I've seen 
>> of Lisp macros suggest that this is what goes on.  I do not think you 
>> can use Lisp macros to get a Lisp interpreter to under truly arbitrary code.
>
> My ignorance of Lisp macros is almost complete.  Mainly I was going by
> the (possibly completely wrong) impression that what people usually
> mean by "having macros in Ruby" is allow on-the-fly redefinition of
> syntax, including punctuation.

Lisp does allow you to completely redefine the syntax, but through
features that aren't usually included in the typical definition of
``Lisp macros'' -- namely, the ability to define reader macros, which
basically lets you hook into the lexer and do whatever you want.

Lisp syntax essentially consists of a bunch of literals (integer
literals, string literals, symbols, etc) and ``forms.''  A form is
a list, and looks like (foo bar baz).  In typical circumstances, the
evaluation of a form is initially dispatched on the head of the list.

If the head is a function name -- i.e., either a symbol whose value is a
function, or a LAMBDA form -- then the corresponding function is called
with the results of evaluation of every other item in the list.

If the head names a macro, the tail of the list is applied to the macro
without evaluating the arguments.  The macro is like a regular Lisp
function, but what it's returned isn't the value of the form -- first,
the result is evaluated; the macro returns an expression, not a value.

Lisp doesn't make that annoying, since Lisp syntax consists solely of
Lisp values.  (+ 1 2) is just a list of the symbol +, the number 1, and
the number 2.

If Lisp macros were implemented in Ruby, they wouldn't necessarily let
you change the syntax to your whims.  Your macros would need to conform
to the standard method call syntax, for example.

It's true that many Lisp macros are merely kludges to avoid typing
`lambda', and Ruby's blocks address that nicely.  You can even specify
some data declaratively with blocks.  But Lisp macros are definitely
more powerful -- they can do arbitrary introspection and manipulation of
their arguments.

Also, I'm not very coherent at this time of night.

  mikael