[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Macros and Language Design.



On Fri, 2003-04-04 at 02:20, Matthew Estes wrote:
> 	They talk about using a "kernel language approach". They have this small 
> kernel of language, and then, through a parser generator tool, other 
> constructs are added to the language by translating them into the kernel 
> language. Is this comparable to what Lisp macros do? A while back, in the 
> macros discussion, someone(Paul Graham?) mentioned that macros are useful 
> to the language designer even if they are not exposed in the language, is 
> this what he was talking about?

Yup!  This is the major point of LISP macros (except that you don't need
to worry about parser generators, because LISP's syntax is
ultra-simple).

You can take LISP, a general purpose programming language--with all the
libraries and tool support that implies--and layer a succinct,
high-level domain language over it.  Furthermore, you can implement this
domain language as a portable library, and allow the LISP compiler to
worry about lots of icky expansion details (actually, some of LISP's
descendants--particularly the Chez Scheme look-alikes--do a better job).

Of course, because language design is hard, you can fall into the trap
of writing a nasty little domain language which all your users hate for
years to come.  That's one of those risks.

> 	Also, to further my understanding of macros, I have some examples of more 
> complex things I think macros could solve. I'm a senior electrical 
> engineering student, and we've been doing some VHDL, and for the subset of 
> the language we're allowed to use, its rather tedious to write finite state 
> machines. So I wrote a program, in C, to take a transition list of the 
> Finite State Machine and translate it into VHDL(with usually a 10-20x 
> increase in the lines of code from the transition table to the VHDL). A 
> friend of mine uses a Java tool called Torque to generate code for his a 
> lot of his database work in a project of his. Are these the kinds of things 
> the reason Lisp programmers love macros?

Yes.  If you're using a code generation tool, you've admitted that
there's a big gap between your language and your problem domain.  And if
this is the case, why not fix your language?

Macros provide a fairly nice way to fix your language, if your macro
system is good enough.  But, like code generators, macros are an awfully
big hammer, and you shouldn't use them without carefully ruling out your
alternatives.

Cheers,
Eric