Hi Chris,
Thanks for the solver. When we get to FDs I'd like to use it in the class. For now, though I don't want my class to think about solvers.
Also, the fact that you pass Digits as a reference rather than calling it makes things confusing. While talking about Chapter 9 I want to think in terms of calling functions like Digits, which can call other functions with similar constructs.
So I guess I want a bit more than I said and not just a working version of Digits. Basically, I want to be able to use Oz like straight Prolog--at least while we're doing Chapter 9. So my request is for instructions for translating a simple Prolog program into a running Oz program. I'm not concerned for now about cuts or even about "running the program in two directions". I just want to know how to use Oz to write basic Prolog programs.
I usually introduce Prolog with examples like Exercise 3 in Chapter 12, the zebra problem. (Although there are much simpler problems that illustrate the same point.) I'd like to write that problem or ones similar to it in Oz without FDs. For examples, here's a site with a bunch of easier puzzles:
http://www.puzzles.com/Projects/LogicProblems.html.
-- Russ
On 2 Oct 2005 23:53:34 -0000, [EMAIL PROTECTED] <
[EMAIL PROTECTED]> wrote:
--- [EMAIL PROTECTED] wrote:
> Can someone give me a version of Digits
that will run?
The SolveOne and SolveAll functions are available on
the books web page, but I can't recall which specific file has them. Below
is the Digits example that works 4 me:
declare
%%%%%%%%%%%%%%%%%%%%%%%%%%%
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.
fun {Solve Script}
{SolStep {Space.new Script} nil}
end
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
fun
{SolveOne F}
L = {Solve F}
in
if L==nil then nil else [L.1] end
end
fun {SolveAll F}
L = {Solve F}
proc {TouchAll L}
if
L==nil then skip else {TouchAll L.2} end
end
in
{TouchAll L}
L
end
%%%%%%%%%%%%%%%%%%%%%%%%%%% Digits %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fun {Digit} choice 0 [] 1 [] 2 [] 3 [] 4 [] 5 [] 6 [] 7 [] 8 [] 9 end end
{Browse {SolveAll Digit}}
Thanks,
Chris Rathman
_________________________________________________________________________________
mozart-users mailing list [email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users
_________________________________________________________________________________ mozart-users mailing list [email protected] http://www.mozart-oz.org/mailman/listinfo/mozart-users
