LOGTALK - what to do with multifile

This is a discussion on LOGTALK - what to do with multifile within the PROLOG forums in Programming Languages category; How to deal with converting Prolog programs that use multifile predicates into Logtalk? I cannot make the following working - gives compilation error :- use_module(library(lists)). :- use_module(library(clpfd)). :- object(obj). :- uses(clpfd, [fd_global /3, dispatch_global /4, fd_max /2, fd_min /2, val /1, minmax /1, #> /2, #=< /2]). :- public(le/3). le(X, Y, B) :- fd_global(le(X, Y, B), P, [minmax(X), minmax(Y), val(B)]). :- multifile dispatch_global/4. dispatch_global(le(X, Y, B), P, Q, Actions) :- le_solver(B, X, Y, Actions). le_solver(B, X, Y, Actions) :- var(B), !, ( fd_max(X, Xmax), fd_min(Y, Ymin), Xmax =< Ymin -> Actions = [exit, B = 1] ; ( fd_min(X, Xmin), ...

Go Back   Application Development Forum > Programming Languages > PROLOG

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 06-30-2008, 11:30 AM
A.L.
Guest
 
Default LOGTALK - what to do with multifile

How to deal with converting Prolog programs that use multifile
predicates into Logtalk?

I cannot make the following working - gives compilation error

:- use_module(library(lists)).
:- use_module(library(clpfd)).

:- object(obj).

:- uses(clpfd, [fd_global /3, dispatch_global /4, fd_max /2, fd_min /2, val /1, minmax /1, #> /2, #=< /2]).

:- public(le/3).

le(X, Y, B) :-
fd_global(le(X, Y, B), P, [minmax(X), minmax(Y), val(B)]).

:- multifile dispatch_global/4.

dispatch_global(le(X, Y, B), P, Q, Actions) :-
le_solver(B, X, Y, Actions).

le_solver(B, X, Y, Actions) :-
var(B),
!,
(
fd_max(X, Xmax), fd_min(Y, Ymin), Xmax =< Ymin
->
Actions = [exit, B = 1]
;
(
fd_min(X, Xmin), fd_max(Y,
Ymax), Xmin > Ymax ->
Actions = [exit, B =
0]
;
Actions = []
)
).

le_solver(0, X, Y, [exit, call('#>'(X, Y))]).

le_solver(1, X, Y, [exit, call('#=<'(X, Y))]).

:- end_object.

| ?- logtalk_load(lgt_test2).

<<< loading source file lgt_test2...
>>> compiling source file lgt_test2...

compiling object obj...
WARNING! Singleton variable in clause for predicate le/3: P

ERROR! domain_error(directive,(multifile)/1)
in directive: :-multifile dispatch_global/4

!
error(error(domain_error(directive,(multifile)/1),directive((multifile
dispatch_global/4))),logtalk_load(lgt_test2))
| ?-
Reply With Quote
  #2  
Old 06-30-2008, 01:02 PM
Paulo Moura
Guest
 
Default Re: LOGTALK - what to do with multifile

On Jun 30, 4:30*pm, A.L. <alewa...@zanoza.com> wrote:
> How to deal with converting Prolog programs that use multifile
> predicates into Logtalk?
>
> I cannot make the following working - gives compilation error


You cannot use the multifile/1 directive inside Logtalk entities.

> :- use_module(library(lists)).


Logtalk provides a "list" library object that you can probably use.

> :- use_module(library(clpfd)).
>
> :- object(obj).
>
> :- uses(clpfd, [fd_global /3, dispatch_global /4, fd_max /2, fd_min /2, val /1, minmax /1, #> /2, #=< /2]).
>
> :- public(le/3).
>
> le(X, Y, B) :-
> * * * * fd_global(le(X, Y, B), P, [minmax(X), minmax(Y), val(B)])..
>
> :- multifile dispatch_global/4.
>
> dispatch_global(le(X, Y, B), P, Q, Actions) :-
> * * * * le_solver(B, X, Y, Actions).


Does this clause works as a default clause for the predicate
dispatch_global/4?

> ...
> :- end_object.


Is the number of files contributing with clauses for the multifile
predicate know a priori?

Cheers,

Paulo

Reply With Quote
  #3  
Old 06-30-2008, 01:53 PM
A.L.
Guest
 
Default Re: LOGTALK - what to do with multifile

On Mon, 30 Jun 2008 10:02:17 -0700 (PDT), Paulo Moura
<pjlmoura@gmail.com> wrote:

>
>You cannot use the multifile/1 directive inside Logtalk entities.
>
>> :- use_module(library(lists)).

>
>Logtalk provides a "list" library object that you can probably use.
>
>> :- use_module(library(clpfd)).
>>
>> :- object(obj).
>>
>> :- uses(clpfd, [fd_global /3, dispatch_global /4, fd_max /2, fd_min /2, val /1, minmax /1, #> /2, #=< /2]).
>>
>> :- public(le/3).
>>
>> le(X, Y, B) :-
>> * * * * fd_global(le(X, Y, B), P, [minmax(X), minmax(Y), val(B)]).
>>
>> :- multifile dispatch_global/4.
>>
>> dispatch_global(le(X, Y, B), P, Q, Actions) :-
>> * * * * le_solver(B, X, Y, Actions).

>
>Does this clause works as a default clause for the predicate
>dispatch_global/4?
>
>> ...
>> :- end_object.

>
>Is the number of files contributing with clauses for the multifile
>predicate know a priori?


dispatch_global/3 is part of clpfd library. I don't know how many
pieces of this predicated are located in separate files.
diapatch_global is used to define global constraints usin gclpfd
library

A.L.
Reply With Quote
  #4  
Old 06-30-2008, 02:20 PM
Paulo Moura
Guest
 
Default Re: LOGTALK - what to do with multifile

On Jun 30, 4:30*pm, A.L. <alewa...@zanoza.com> wrote:
> How to deal with converting Prolog programs that use multifile
> predicates into Logtalk?


Follows a sketch of a possible solution whenever the number of Prolog
files containing clauses for the multifile predicate is know a priori.

Assume that the multifile predicate is named mp/1 and is defined in
two files.

1. Define a protocol containing the declaration of the multifile
predicate:

:- protocol(ptc).

:- public(mp/1).

:- end_protocol.

2. Define a category per file containing the clauses for the mp/1
predicate:

:- category(ctg1,
implements(ptc)).

mp(1).
mp(2).

:- end_category.


:- category(ctg2,
implements(ptc)).

mp(3).
mp(4).

:- end_category.

3. Define an object importing all the categories and defining aliases
to the imported predicates:

:- object(obj,
implements(ptc),
imports(ctg1, ctg2)).

:- alias(ctg1, mp/1, ctg1_mp/1).
:- alias(ctg2, mp/1, ctg2_mp/1).

mp(X) :-
::ctg1_mp(X).
mp(X) :-
::ctg2_mp(X).

:- end_ object.

The predicate aliases above are needed to allow access to the
overridden clauses of the mp/1 predicate (by default, the clauses from
"ctg1" would override the clauses from the "ctg2" category as a
consequence of the predicate lookup mechanism).

4. Compiling and loading the above Logtalk entities allows you to
access all clauses of the former multifile predicate. For example:

| ?- obj::mp(X).
X = 1 ;
X = 2 ;
X = 3 ;
X = 4
yes

Hope this helps. Cheers,

Paulo
Reply With Quote
  #5  
Old 06-30-2008, 02:30 PM
Paulo Moura
Guest
 
Default Re: LOGTALK - what to do with multifile

On Jun 30, 6:53*pm, A.L. <alewa...@zanoza.com> wrote:
> On Mon, 30 Jun 2008 10:02:17 -0700 (PDT), Paulo Moura
> ...
> >Is the number of files contributing with clauses for the multifile
> >predicate know a priori?

>
> dispatch_global/3 is part of clpfd library. I don't know how many
> pieces of this predicated are located in separate files.
> diapatch_global is used to define global constraints usin gclpfd
> library


Assuming that I'm understanding the SP documentation on the
dispatch_global/4 predicate, its clauses are defined by the user.
Thus, what's the trouble in finding which files define clauses for
this predicate?

Cheers,

Paulo

Reply With Quote
  #6  
Old 07-01-2008, 05:58 AM
Paulo Moura
Guest
 
Default Re: LOGTALK - what to do with multifile

On Jun 30, 7:30*pm, Paulo Moura <pjlmo...@gmail.com> wrote:
> On Jun 30, 6:53*pm, A.L. <alewa...@zanoza.com> wrote:
>
> > On Mon, 30 Jun 2008 10:02:17 -0700 (PDT), Paulo Moura
> > ...
> > >Is the number of files contributing with clauses for the multifile
> > >predicate know a priori?

>
> > dispatch_global/3 is part of clpfd library. I don't know how many
> > pieces of this predicated are located in separate files.
> > diapatch_global is used to define global constraints usin gclpfd
> > library

>
> Assuming that I'm understanding the SP documentation on the
> dispatch_global/4 predicate, its clauses are defined by the user.
> Thus, what's the trouble in finding which files define clauses for
> this predicate?


Re-reading the SP documentation, you cannot define clauses for the
dispatch_global/4 predicate inside objects. The problem is not that
the predicate is declared multifile. The problem is that defining a
clause for this predicate inside an object would change its name,
breaking its ties to the "clpfd" library. You may, however, include
clauses for the dispatch_global/4 predicate inside Logtalk source
files as long as they are not encapsulated inside a Logtalk object or
category (the Logtalk compiler should copy them verbatim to the
generated Prolog files). You may define the body of the predicate to
call object predicates using message sending. Let me known if this
solution is workable.

Cheers,

Paulo

Reply With Quote
  #7  
Old 07-01-2008, 07:45 AM
A.L.
Guest
 
Default Re: LOGTALK - what to do with multifile

On Tue, 1 Jul 2008 02:58:45 -0700 (PDT), Paulo Moura
<pjlmoura@gmail.com> wrote:

>On Jun 30, 7:30*pm, Paulo Moura <pjlmo...@gmail.com> wrote:
>> On Jun 30, 6:53*pm, A.L. <alewa...@zanoza.com> wrote:
>>
>> > On Mon, 30 Jun 2008 10:02:17 -0700 (PDT), Paulo Moura
>> > ...
>> > >Is the number of files contributing with clauses for the multifile
>> > >predicate know a priori?

>>
>> > dispatch_global/3 is part of clpfd library. I don't know how many
>> > pieces of this predicated are located in separate files.
>> > diapatch_global is used to define global constraints usin gclpfd
>> > library

>>
>> Assuming that I'm understanding the SP documentation on the
>> dispatch_global/4 predicate, its clauses are defined by the user.
>> Thus, what's the trouble in finding which files define clauses for
>> this predicate?

>
>Re-reading the SP documentation, you cannot define clauses for the
>dispatch_global/4 predicate inside objects. The problem is not that
>the predicate is declared multifile. The problem is that defining a
>clause for this predicate inside an object would change its name,
>breaking its ties to the "clpfd" library. You may, however, include
>clauses for the dispatch_global/4 predicate inside Logtalk source
>files as long as they are not encapsulated inside a Logtalk object or
>category (the Logtalk compiler should copy them verbatim to the
>generated Prolog files). You may define the body of the predicate to
>call object predicates using message sending. Let me known if this
>solution is workable.
>

\
Thanks for clarification. I will check

A.L.
Reply With Quote
  #8  
Old 08-12-2008, 07:17 AM
Paulo Moura
Guest
 
Default Re: LOGTALK - what to do with multifile

On Jun 30, 4:30*pm, A.L. <alewa...@zanoza.com> wrote:
> How to deal with converting Prolog programs that use multifile
> predicates into Logtalk?
>
> I cannot make the following working - gives compilation error
>
> :- use_module(library(lists)).
> :- use_module(library(clpfd)).
>
> :- object(obj).
>
> :- uses(clpfd, [fd_global /3, dispatch_global /4, fd_max /2, fd_min /2, val /1, minmax /1, #> /2, #=< /2]).


The current Logtalk development version (available from the Logtalk
Subversion server) adds support for using use_module/2 directives
within objects and categories (object components), allowing you to
write instead:

:- use_module(clpfd, [fd_global/3, dispatch_global/4, fd_max/2, fd_min/
2, val/1, minmax/1, (#>)/2, (#=<)/2]).

Examples using the Markus Triska's CLP(FD) library distributed with
SWI-Prolog and YAP are included in the current Logtalk development
version (see lgtsvn/examples/constraints).

Cheers,

Paulo

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 08:32 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.