Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!zodiac!joyce!sri-unix!quintus!ok
From: ok@quintus.uucp (Richard A. O'Keefe)
Newsgroups: comp.lang.prolog
Subject: Re: Why no macro facility?
Message-ID: <162@quintus.UUCP>
Date: 8 Jul 88 21:34:34 GMT
References: <9671@lll-winken.llnl.gov>
Sender: news@quintus.UUCP
Reply-To: ok@quintus.UUCP (Richard A. O'Keefe)
Organization: Quintus Computer Systems, Inc.
Lines: 46

In article <9671@lll-winken.llnl.gov> daven@lll-crg.llnl.gov (Dave Nelson) writes:
>Could someone tell me why prolog has no built-in macro facility?
>Even the industrial strength, full-featured prolog I am currently
>evaluating doesn't have such a thing.
>
If the Prolog you are evaluating hasn't got the term_expansion/2 hook
(which first saw the light of day in C-Prolog years ago) it is not
"full-featured".  You can use term_expansion/2 to plug in any macro
system you like (see my "Practical Prolog for Real Programmers"...).
[Note that a hook into "assert" as some Prologs have just isn't good
enough; you would like to be able to process things that will never
go into the data base.]

There is a "right" way to do macros in Prolog, but getting all the
details right (interaction with cut, ..., what should debugger see, ...)
is a pain.  Lisp is a *wonderful* source of inspiration for this work:
it gets so many things wrong.

Stony Brook Prolog (available from Saumya Debray at the University of
Arizona) contains a macro facility which takes the right approach, but
there are a lot of fiddly details which need a lot more thought.

>This sort of source-to-source transformation of files, *which can then
>be compiled*, is the LISP feature I miss the most (so far :-).

If you were using Quintus Prolog or SB Prolog you wouldn't be missing it.

>Oh, and another thing...would it be so hard to put in a compile(pred, arity)
>to take a currently interpreted predicate and compile it?  All the
>compile(frob) directives interpret frob as a filename.

The absence of ensure_compiled(Name/Arity) -- please, NOT another name botch
like abolish/2 -- is an historical accident: DEC-10 Prolog had the compiler
and interpreter in different "high segments", so the compiler would have
found it hard to get at interpreted code.  In ALS Prolog and NIP and some
others, such an operation would be completely pointless, as there is no
distinction between compiled and interpreted code.  ZYX Prolog does have
such an operation.  (Unfortunately, they called it compile/1, which does
rather nasty things to programs that want to compile files.  Boo hiss.)

In DEC-10 Prolog and its successors, you can do

my_compile(Preds) :-
	tell('SCRTCH.PL'),	% oh, those DEC 6.3 file-names...
	listing(Preds),
	told,
	compile('SCRTCH.PL').