Marco, Thanks. Non-logical variables can indeed be used to count the solutions. Thank you once again. Regards, Shrirang > On 22-Mar-2016, at 5:01 PM, Marco Gavanelli <marco.gavanelli_at_unife.it> wrote: > >> On 22/03/16 04:18, Edgaonkar, Shrirang wrote: >> Similar to "once / 1" I would like to write "twice / 1" goal so that >> the first solution backtracks and finds the second solution. I wish >> to get both the solutions. > > In order to get two solutions (without recomputing the first), you need > to store some information in a way that survives backtracks. > > The first idea that comes to my mind is to use assert and retract, that > are standard and work in all Prolog compilers: > > :- dynamic previously_solved/0. > > twice(Goal):- > call(Goal), > (previously_solved > -> !, retract(previously_solved) > ; assert(previously_solved)). > > In ECLiPSe you can have better, reentrant code by using non-logical > storage predicates: > > http://eclipseclp.org/doc/userman/umsroot050.html > > Best, > Marco > > -- > http://docente.unife.it/marco.gavanelli > > ------------------------------------------------------------------------------ > Transform Data into Opportunity. > Accelerate data analysis in your applications with > Intel Data Analytics Acceleration Library. > Click to learn more. > http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140 > _______________________________________________ > ECLiPSe-CLP-Users mailing list > ECLiPSe-CLP-Users_at_lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users ______________________________________________________________________ Disclaimer: This email and any attachments are sent in strictest confidence for the sole use of the addressee and may contain legally privileged, confidential, and proprietary data. If you are not the intended recipient, please advise the sender by replying promptly to this email and then delete and destroy this email and any attachments without any further use, copying or forwarding.Received on Tue Mar 22 2016 - 10:29:52 CET
This archive was generated by hypermail 2.2.0 : Wed Mar 23 2016 - 18:13:12 CET