| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| 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)) | ?- |
|
#2
| |||
| |||
| 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 |
|
#3
| |||
| |||
| 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. |
|
#4
| |||
| |||
| 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 |
|
#5
| |||
| |||
| 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 |
|
#6
| |||
| |||
| 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 |
|
#7
| |||
| |||
| 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. |
|
#8
| |||
| |||
| 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 |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.