Re: Attempt at approximating Lisp's "macroexpansion"

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 07/17/2013 05:49 PM, Ian Tegebo wrote:
> Alan,
> 
> Unfortunately, I left out some details.  First, I started the top-level:
> 
> $ swipl
>   ...
> 1 ?- edit(file('arec_mod.pl')).
> 
> Then, I edited the file to look like:
> 
> arec_mod.pl:
> :- module(arec_mod,[]).
> :- use_module(library(record)).
> :- record arec(afield:atom='').
> 
> Then, I compiled it from the editor with C-c, C-b.  Back in the top-level:
> 
> 2 ?- module(arec_mod).
> true.
> 
> arec_mod: 3 ?- expand_term(:- record arec(afield:atom=''),Res).
> ERROR: Syntax error: Operator expected
> ERROR: expand_term(:- record
> ERROR: ** here **
> ERROR: arec(afield:atom=''),Res) .

This looks like a bug.  The toplevel should do the reading with the
currently active module syntax.  This affects the toplevel, but otherwise
shouldn't affect whatever preprocessing you are trying to do.

> 
> Now, even if I consult library(record) from the default working module:
> 
> arec_mod: 4 ?- [library(record)].
> 
> The "record" atom is still not recognized as an operator:
> 
> arec_mod: 5 ?- current_op(1150,fx,record).
> false.
> 
> And that was confusing because I expected the exported operator to be
> available given that I'd changed the working module at the top-level.  Now
> let's do:
> 
> arec_mod: 6 ?- module(user).
> true.
> 
> 7 ?- [library(record)].
> % library(record) compiled into record 0.01 sec, 59 clauses
> true.
> 
> 8 ?- current_op(1150,fx,record).
> true.
> 
> 9 ?- module(arec_mod).
> true.
> 
> arec_mod: 10 ?- current_op(1150,fx,record).
> true.
> 
> arec_mod: 11 ?- expand_term(:- record arec(afield:atom=''),Res).
> Res = [default_arec(arec('')), ...
> 
> So, what does this mean?  It appears that the operator table at the
> top-level doesn't reflect the current working module.  Is the user module's
> operator table expected to be the only one in use while in the top-level?

No.  I must admit I never use module/1 to switch the toplevel module.  I
doubt many people do.

>  If so, I feel like this somewhat weakens its usefulness for debugging
> modules.  I got into the habit of using module/1 at the top-level for the
> convenience of atom completion.

Atom completion is not module-aware.  Typically, you just type the goal
in the user module and expect DWIM to add the module for you.  Of course,
I'll fix the toplevel to use the current module for reading.

	Cheers --- Jan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.