Re: [eclipse-users] passing predicate names

From: Kish Shen <kisshen_at_...5...>
Date: Wed, 12 Sep 2007 12:12:12 +0100
Malcolm Ryan wrote:
> In many places in my code I have lines that look like:
>
> (ground(Var) ->
> 	true
> ;
> 	suspend(Pred, Priority, Var->Event, Susp)
> )
>
> I'd like to factor this out into a new predicate:
>
> suspend_if_var(Pred, Priority, Var, Event, Susp).
>
> but If I put this in a different module (a library of utilites I  
> share across my modules) then there are problems with knowing what  
> module 'Pred' comes from. Is there any easy way to make sure that  
> Pred contains the appropriate module information *without* having to  
> write it in of every call? So I can do:
>
> suspend_if_var(predicate, ...)
>
> and not
>
> suspend_if_var(current_module:predicate, ...)
>
> Malcolm
> 	
> --
>       "The act of defending any of the cardinal virtues has today all
>        the exhilaration of a vice."
>                                      - G.K.Chesterton A Defense of  
> Humility
>
>
>
>
> _______________________________________________
> ECLiPSe-Users mailing list
> ECLiPSe-Users_at_...2...
> http://www.crosscoreop.com/mailman/options/eclipse-users
>   
Hi Malcolm,

ECLiPSe provides the tools mechanism for doing what you want. This is 
described in the modules chapter of the user manual.

Essentially, you declare suspend_if_var/5 as a tool predicate, and when 
you call it, ECLiPSe will add an extra argument, giving the caller 
module, to the predicate, and this is what you define:

:- tool(suspend_if_var/5, suspend_if_var_body/6).

suspend_if_var_body(Pred, Priority, Var, Event, Susp, Caller) :-
     ....

where Caller is the module  where  suspend_if_var/5 was called  from.

The user manual goes into more detail about this, along with other 
features of  ECLiPSe's module system (which has some important 
differences from other Prolog's module system, so it is probably worth 
reading this if you are familiar with the module system of other Prologs).

Cheers,

Kish
Received on Wed Sep 12 2007 - 12:12:25 CEST

This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:20 CEST