Re: Ideas on how to transform a prolog program into a clp program
Edison Mera <[email protected]> Wed, 9 Apr 2014 16:50:24 +0200
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CAKkUgY6KZNAhq3vycFqQLEPTppJROnu-M6nzhXf8ohTkedEN3g@mail.gmail.com> |
In this case, you can use the refactoring tool, first install it with:
pack_install('https://github.com/edisonm/refactor.git').
And then run the following commands in the swipl shell:
replace_term(Module:_, A<B, A#<B,[]).
rshow. % if you want to see the changes
rcommit. % if you are happy with such changes
use rreset if you don't want to apply the changes, but want to modify the
refactoring rule.
Best Regards,
Edison <http://edisonm.com/>
2014-04-08 9:20 GMT+02:00 Jan Wielemaker <[email protected]>:
> On 08-04-14 02:38, fybertas wrote:
> > I've been trying to transform a prolog program into a clp(constraint
> > logic program): therefore, I need to add finite domain constraints to
> > variables in the program; I also need to change the operators in the
> > program to their equivalence in clp (for instance, change "<" into
> > "#<").
>
> Most likely it is not that simple. For example, clp(fd) doesn't like
> cuts too much ... If the program works, it is also not clear what you
> gain. It might turn single moded predicates into multi moded ones. If
> that is what you are after, you could be on the right track.
>
> > But I am kind of stuck as to how to implement this using prolog, here are
> > two possible ways IMO:
> > (1) process the prolog file by term input/output, identify the terms and
> > clauses(which is not very explicit), then perform the above two
> > transformation.
>
> That is done using term_expansion/2 (or maybe just goal_expansion/2) in
> this case. E.g.,
>
> goal_expansion(A<B, A#<B).
>
> > (2) read in the file using "consult", then process the clauses in the
> > memory, use assert and retract to manipulate clauses.
>
> Yes, but the output will look ugly as you loose all variable names
> and all comments.
>
> > (3) Or maybe there are some library that can help me with this?
>
> See http://www.swi-prolog.org/pack/list?p=refactor. It seems the
> pack is not upgraded regularly. You can find the github repo by
> clicking on the author's link (Edison Mera). There you find recent
> activity.
>
> Hope this helps
>
> Cheers --- Jan
>
> >
> > Could someone shed some light on this? I have tried to find tutorials on
> > advanced Prolog programming but couldn't find much.
> >
> >
> >
> > --
> > View this message in context:
> http://swi-prolog.996271.n3.nabble.com/Ideas-on-how-to-transform-a-prolog-program-into-a-clp-program-tp14746.html
> > Sent from the SWI Prolog mailing list archive at Nabble.com.
> > _______________________________________________
> > SWI-Prolog mailing list
> > [email protected]
> > https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
> >
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>
-------------- next part --------------
HTML attachment scrubbed and removed