% $Id: Solve.oz,v 1.1 2007/11/26 20:13:05 leavens Exp leavens $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Mozart System Supplements % This file gives the extensions to the basic Mozart system that % are used in the book "Concepts, Techniques, and Models of Computer % Programming". The contents of this file can be put in the .ozrc % file in your home directory, which will cause it to be loaded % automatically when Mozart starts up. % Authors: Peter Van Roy and Seif Haridi % May 9, 2003 declare % ... I took out the stuff from other chapters... Gary T. Leavens %%%%%%%%%%%%%%%%%%%%%%%%%%% Chapter 9 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Lazy problem solving (Solve) % This is the Solve operation, which returns a lazy list of solutions % to a relational program. The list is ordered according to a % depth-first traversal. Solve is written using the computation space % operations of the Space module. local fun {SolStep S Rest} case {Space.ask S} of failed then Rest [] succeeded then {Space.merge S}|Rest [] alternatives(N) then {SolLoop S 1 N Rest} end end fun lazy {SolLoop S I N Rest} if I>N then Rest elseif I==N then {Space.commit S I} {SolStep S Rest} else Right C in Right={SolLoop S I+1 N Rest} C={Space.clone S} {Space.commit C I} {SolStep C Right} end end in fun {Solve Script} {SolStep {Space.new Script} nil} end end