[mercury-users] lisp macros
Richard A. O'Keefe
ok at cs.otago.ac.nz
Tue Jun 4 14:12:34 AEST 2002
schachte at cs.mu.OZ.AU (Peter Schachte) wrote:
Parse, no, but sometimes it is difficult to write a module that
expands source code in such a way that it can successfully expand
itself. I often use a trick to ensure that my term_expansion clauses
are not applied to the module that defines them.
I'm sure he remembers the {add,del}_expansion/1 commands in the QP library.
:- module(my_module, [..., my_expander/2, ...]).
:- use_module(library(add_portray)).
:- del_expansion(my_expander).
...
my_expander(In, Out) :- ...
...
:- add_expansion(my_expander).
The "add_expansion" call at the end means that my_module:my_expander/2
is not installed as a term expander until it is complete.
The "del_expansion" call at the beginning means that the module can
safely be *re*loaded; the expansion will never apply to this module.
If I can trust the copyright notice, the original version of that library
module came out in 1987. The version I have is data 1989. No special
tricks have been needed since.
The Erlang solution is that if you use a transformer module, the compiler
loads the *current* compiled state of that module, and only emits the
*new* compiled state as a complete unit after all processing is complete.
I think that is the most sensible solution to this problem. For a
system that supplies only a source-to-binary compiler, it will not be
possible to compile a file that defines expansion clauses that are
meant to be run on itself: you would need to have compiled the file
before you could compile the same file.
Can you say 'cpp'? I knew you could. The C preprocessor was used while
developing the C preprocessor. You need to have compiled an EARLIER VERSION
of the file before you can compile the next version, but heck, that's how
Mercury was built.
Peter Schachte That government is best which governs least.
schachte at cs.mu.OZ.AU -- Thomas Jefferson
We don't agree with Thomas Jefferson about owning slaves (which he did);
we don't have to agree with him about anything else either.
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list