Re: [eclipse-clp-users] "twice" similar to "once"

From: Marco Gavanelli <marco.gavanelli_at_...17...>
Date: Tue, 22 Mar 2016 08:36:47 +0100
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.

	->	!, retract(previously_solved)
	;	assert(previously_solved)).

In ECLiPSe you can have better, reentrant code by using non-logical 
storage predicates:


Received on Tue Mar 22 2016 - 08:00:46 CET

This archive was generated by hypermail 2.3.0 : Fri Aug 16 2019 - 15:13:40 CEST