From f.todescato@larisys.fr Thu Jan 10 09:38:10 2002
Received: from gradian ([217.109.164.148])
	by swi.psy.uva.nl (8.11.6/8.11.2) with SMTP id g0A8c9T12245
	for <prolog@swi.psy.uva.nl>; Thu, 10 Jan 2002 09:38:09 +0100 (MET)
Received: from 192.168.1.17 by gradian (InterScan E-Mail VirusWall NT); Thu, 10 Jan 2002 09:37:35 +0100
Received: by servcom.larisys.france with Internet Mail Service (5.5.2653.19)
	id <CR58V0L0>; Thu, 10 Jan 2002 09:37:47 +0100
Message-ID: <0D871E2C396E7A44B47CB01EC05664A7172675@servcom.larisys.france>
From: Fabien Todescato <f.todescato@larisys.fr>
To: "SWI Prolog Mailing List (E-mail)" <prolog@swi.psy.uva.nl>
Date: Thu, 10 Jan 2002 09:37:47 +0100
Return-Receipt-To: Fabien Todescato <f.todescato@larisys.fr>
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2653.19)
Content-Type: text/plain;
	charset="iso-8859-1"
Subject: [SWIPL] Embedding Deterministic Prolog Predicates in XPCE's function obje
	cts

Dear XPCErs,

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.

I can define as follows the 'prologFunction' class wrapping a unary
predicate :

:- use_module(library(pce)).

:- pce_begin_class(prologFunction,object).

  variable(p,prolog_term,both).

  initialise(Self,P:prolog_term) :->
    send_super(Self,initialise)
  , send(Self,p(P))
  .

  apply(Self,Y) :<-
    get(Self,p,P)
  , call(P,Y)
  .

:- pce_end_class.

This way, if F is an instance of the above class, then F?apply is an XPCE
function that yields the result of the Prolog predicate embedded in F.

The example below demonstrates the use of a wrapped unary prolog predicate
always yielding @on.

example :-
  new(F,prologFunction('='(@on))) % F is the wrapped Prolog predicate
yielding @on.
, new(M,message(@prolog,write_ln,F?apply))
, send(M,forward)
.

We get on the console :

?- example.
@on

Yes

Although this seems to be working, the use of of the '?' obtainer with the
apply selector is a little bit clumsy.

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.

Fabien TODESCATO

