Re: [eclipse-users] passing predicate names

From: Joachim Schimpf (Independent Contractor) <"Joachim>
Date: Wed, 12 Sep 2007 14:25:38 +0100
Kish Shen wrote:
> 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.

and inside this predicate you would then use

	suspend(Pred, Priority, Var->Event, Susp)_at_Caller

to call suspend/4 in the Caller module's context (where Pred is visible).


-- Joachim
Received on Wed Sep 12 2007 - 14:25:45 CEST

This archive was generated by hypermail 2.3.0 : Tue Apr 16 2024 - 09:13:19 CEST