Re: term_expansion/2 with DCG clauses

Paulo Moura <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 14/08/2013, at 19:15, Michael Hendricks <[email protected]> wrote:

> By tracking a little state under recursive expansion, one can control both order and macro selection.  So the two approaches seem equivalent to me, in this case.

As Richard would wrote, "An example would be handy about now." :-) Assume that you have three expansions that should occur in a fixed order:

	A -> B -> C

In Logtalk, you can simply write:

:- object(my_hook_object, implements(expanding)).

	term_expansion(Pristine, Transformed) :-
		a::term_expansion(Pristine, Transformed0),
		b::term_expansion(Transformed0, Transformed1),
		c::term_expansion(Transformed1, Transformed).

:- end_object.

| ?- logtalk_load([a,b,c,my_hook_object]), logtalk_load(my_pristine_source_file, [hook(my_hook_object)]).

Or have at the beginning of the "my_pristine_source_file" the directive:

:- set_logtalk_flag(hook, my_hook_object).

And type in alternative:

| ?- logtalk_load([a,b,c,my_hook_object,my_pristine_source_file]).

Can you show us exactly how you would do the same (fixed order expansions) under recursive expansion?

Cheers,

Paulo


-----------------------------------------------------------------
Paulo Moura
Logtalk developer

Email: <mailto:[email protected]>
Web:   <http://logtalk.org/>
-----------------------------------------------------------------
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.