PLOGHELP MACRO                             Jonathan Laventhol, July 1983
                              Revised by Kathryn Seifert, September 1986

Library program to define macros in Prolog

Keywords: macros


There is a macro facility in POPLOG Prolog, so that atoms as they are
read in (as part of terms) can be turned into something else, or cause
an action.


-- HOW TO DEFINE MACROS -----------------------------------------------

Macro words have a macro value which can be a list of items, or an item,
or a POP-11 procedure.

Here is a table of actions:

    value of macro word                 behaves as if you typed

        foo                                     foo
        1234                                    1234
        [listing, '(', goo, ')', '.']           listing(goo).

(If you set the value of a macro to be a Prolog variable, that variable
will behave as though it is a global constant.  Do not rely on this
behaviour as it may be withdrawn in the future.)

There is a library package to help you set up macros:

    ?- library(macro).

Then you have three predicates:

    ?- macro(Value, Name).
        (Both arguments should be instantiated.)
        This will set the atom in Name to be a macro with given value.
    ?- killmac(Namestring).
        (Namestring should be instantiated to be a Prolog string.)
        The named macro will cease to be a macro.
    ?- macval(Namestring, Value).
        (Namestring should be instantiated to be a Prolog string.)
        Sets Value to be the value of the named macro.


-- For those who also know POP-11 -------------------------------------

You can put an entry in the global hash table PROLOG_MACRO for any word.
When that word is being read, if there is an entry in the table for it
(ie, the value is non-FALSE, then

    * If the entry is a POP-11 procedure, it is run, taking its arguments from
      the input stream , anything left on the stack replacing the word.

    * If the entry is a list, the contents of the list replace the word.

    * Otherwise, the entry replaces the word.

POP-11 procedures used as Prolog macros should have the same functionality
as a POP-11 macro, although they needn't actually be POP-11 macros.  To stop
a word being expanded as a macro, put false as its entry:

    false -> prolog_macro("myword");

For more information, see SHOWLIB * MACRO.

-- RELATED DOCUMENTATION ----------------------------------------------

HELP * MACRO
 Discussion of POP-11 macros

--- C.all/plog/help/macro
--- Copyright University of Sussex 1990. All rights reserved. ----------
