In the following, either of the first two constraints work, but the third one doesn't.
local
fun {Plus2 X Y} X + Y end
proc {Plus3 X Y Z} X + Y =: Z end
proc {Test Answer}
A B
in
Answer= [A B]
Answer ::: 1#9
% A + B =: 5 % OK
% {Plus3 A B 5} % OK
% {Plus2 A B} =: 5 % Not OK
{FD.distribute ff Answer}
end
in
{Browse {SearchAll Test}}
end
I assume (now that I've spent some time thinking about it) that the third constraint
fun {Plus2 X Y} X + Y end
proc {Plus3 X Y Z} X + Y =: Z end
proc {Test Answer}
A B
in
Answer= [A B]
Answer ::: 1#9
% A + B =: 5 % OK
% {Plus3 A B 5} % OK
% {Plus2 A B} =: 5 % Not OK
{FD.distribute ff Answer}
end
in
{Browse {SearchAll Test}}
end
I assume (now that I've spent some time thinking about it) that the third constraint
{Plus2 A B} =: 5
doesn't work because neither A nor B is directly affected by the constraint. In the second constraint, the variables are unified with X and Y in Plus2, which are directly affected by the constraint. Right?
If that's the explanation, it makes sense once one thinks it through. But before thinking it through, I had imagined that Oz would push the unification through Plus2 somehow and apply the constraint to the result. In general, I suppose that isn't possible.
This would be useful to mention somewhere in the tutorial. (Perhaps it is and I missed it or forgot it.) I felt quite frustrated until I figured out what was wrong with using Plus2.
This came up because I was trying to rewrite SEND + MORE = MONEY by writing a function {MakeNumber Digits} that took a list of variables (like [S E N D]) and returning their value as a number. I wanted to write a constraint that looked something like:
{MakeNumber [S E N D]} + {MakeNumber [M O R E]} =: {MakeNumber [M O N E Y]}
As you can imagine, I got no useful output at all!
-- Russ
_________________________________________________________________________________ mozart-users mailing list [email protected] http://www.mozart-oz.org/mailman/listinfo/mozart-users
