Russ Abbott wrote:
In reply to code that I wrote that looked though a list of values and
failed if two of them were equal (==), Raph suggested the code
below--which is better than my original nested double loop.
In class today, Brian Smith proposed the following clever hack.
proc {AllDistinct Xs}
thread
try {MakeRecord test Xs _}
catch _ then fail end
end
end
It uses the fact that MakeRecord will fail if the field names it gets
have a repeated value. It suspends until all values are instantiated. So
the point is not really to make a record but to use MakeRecord's check
on the list of fields to detect duplicates. The only reason to wrap it
all in a try-catch is to get rid of the diagnostics that are printed in
the Oz emulator buffer window otherwise.
Indeed, it will work. It is semantically sound. But as you said, it
waits until all variables in Xs are determined. This may generate a
huge amount of search for nothing. Mine concurrently checks all
constraints that constitute the AllDistinct constraint.
Cheers,
raph
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users