Re: [eclipse-clp-users] Checking for existing clauses without dynamic definition?

From: Joachim Schimpf <jschimpf_at_coninfer.com>
Date: Fri, 30 May 2014 20:01:47 +0200
On 30/05/2014 01:14, Travis Johnson wrote:
> Hi Joachim!
> 
> What does the "@Module" statement do?

It overrides the "context module".  Some predicates are sensitive to the module context from which
they are called, essentially because in different module different things (predicates, etc) are
visible.

For example, compile_term([p:-writeln(hello)]) will create a predicate p/0 which is local to the
module from which compile_term/1 was called.  If you wanted to create the predicate in a different
module, you would use compile_term([p:-writeln(hello)])@SomeOtherModule.

Related to this is the tool-declaration, which allows you to write our own predicate that knows
from which module context it was called:

> :- tool(dynamic_to_static/1, dynamic_to_static_/2).
> dynamic_to_static_(F/N, Module) :-
> 	functor(Head, F, N),
> 	findall(Head:-Body, clause(Head, Body), Clauses)@Module,
> 	abolish(F/N)@Module,
> 	compile_term(Clauses)@Module.

Here, the system maps any call to dynamic_to_static/1 into a call to dynamic_to_static_/2 by adding
the call's context module as an extra argument.  You can then use this module for @Module
annotations where needed.

If all your code were in the same module (including dynamic_to_static/1 itself), you wouldn't need
any of this.  I just wanted to show a piece of code general enough to go into a utilities library.

The overview of the module system is here http://www.eclipseclp.org/doc/userman/umsroot037.html

Cheers,
Joachim
Received on Fri May 30 2014 - 18:02:03 CEST

This archive was generated by hypermail 2.2.0 : Thu Jun 12 2014 - 06:15:02 CEST