Subject: Re: [SWIPL] Embedding Deterministic Prolog Predicates in XPCE's function objects

From: Jan Wielemaker <[email-masked]>
Date: Thu, 10 Jan 2002 10:55:08 +0100

> Dear XPCErs,

[maybe better try [email-masked]]

> I have to implement a menu the items of which are dynamically enabled
> according to some possibly complex conditions. Such dynamic conditions may
> be specified by providing a code object yielding a boolean object as the
> 'condition' argument of the menu item constructor - see the documentation of
> the initialise method for the menu_item class -.
> 
> In my case, I need to implement the condition logic in Prolog, and therefore
> I am seeking a means to wrap a condition/1 Prolog predicate yielding either
> @on or @off, into an XPCE function object.

<snip>

> My question is :
> 
> Would it be possible to define a class derived from the XPCE 'function'
> class, so that the 'execute' behaviour is overloaded in order to call the
> embedded predicate directly ?
> 
> Any hints greatly appreciated. Thanks a lot for your attention.

Clever `solution', though unnecessary complicated.  You can already do
this using obtainers on @prolog, that call predicates with one argument
more than passed.

?- assert(hello(world)).

?- send(@pce, write, @prolog?hello).
world

?- send(@pce, write, ?(@prolog, plus, 1, 2))
3

If you don't like this syntax, you should indeed be able to subclass
class function and play around.  Unfortunately the machinery in class
function doesn't use clean message passing, but low-level internal
calls, so this doesn't work.  What you *can* do however is subclass
class ? and modify the initialisation thereof:

:- pce_begin_class(test, ?).

initialise(I, Pred:name) :->
	send_super(I, initialise, @prolog, Pred).

:- pce_end_class(test).

hello(world).

test :-
	send(@pce, write, test(hello)).

?- test.
world.

	Cheers --- Jan