From jan@swi.psy.uva.nl Thu Jan 10 10:55:08 2002
Received: from gollem.swi.psy.uva.nl (root@gollem.swi.psy.uva.nl [145.18.152.30])
	by swi.psy.uva.nl (8.11.6/8.11.2) with ESMTP id g0A9t8T18460;
	Thu, 10 Jan 2002 10:55:08 +0100 (MET)
Received: (from jan@localhost)
	by gollem.swi.psy.uva.nl (8.11.3/8.11.3/SuSE Linux 8.11.1-0.5) id g0A9t8p32044;
	Thu, 10 Jan 2002 10:55:08 +0100
Date: Thu, 10 Jan 2002 10:55:08 +0100
Message-Id: <200201100955.g0A9t8p32044@gollem.swi.psy.uva.nl>
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Subject: Re: [SWIPL] Embedding Deterministic Prolog Predicates in XPCE's function objects
To: Fabien Todescato <f.todescato@larisys.fr>,
   "'SWI Prolog Mailing List (E-mail)'" <prolog@swi.psy.uva.nl>
In-Reply-To: Fabien Todescato's message of Thu, 10 Jan 2002 09:46:26 +0100
Phone: +31 - 20 - 525 6121

> Dear XPCErs,

[maybe better try xpce-users@swi.psy.uva.nl]

> 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

