Hi there,
Though I haven't looked at your other definitions yet, it is true that
All can be greatly redesigned. First of all, it is worth noticing that
it looks a bit strange to have this predicate return a boolean, as
more usual logic programming would simply fail when not all elements
satisfied the given predicate. This usual interpretation would very
straightforwardly be implemented as:
{ForAll L P} % built-in ForAll. Here P does not return a boolean, just
fails when the predicate does not hold.
{List.all L P} % Here P returns a boolean
However, if your list is really undetermined (that is, even its length
is unknown) at this point, you'll really need something extra. My
point is: use the above commands and leave only two possible choice
sources:
(i) the length of the list;
(ii) P itself.
If (i) is not known, you might resort to the following:
-------------------------------------------
declare
local
proc {FirstConstraint CurLen L Len}
if {IsFree L} then
CurLen =<: Len
else
case L of
nil then CurLen = Len
[] _|Rest then {FirstConstraint CurLen+1 Rest Len}
end
end
end
in
proc {VarLenList L Len}
AuxLen = {FD.decl}
{FirstConstraint 0 L AuxLen}
in
if {IsDet AuxLen} then skip else
thread
{Wait AuxLen}
{MakeList AuxLen L}
end
end
AuxLen = Len
end
end
declare
L = _|_|_|_|_
Len = {VarLenList L}
{Browse L#Len} % First see the result of this line then feed the following line:
Len = 5 % look at the browser again
-------------------------------------
Well, maybe by now you are beginning to see why Mozart does not offer
a high-level logic library. That's because there are various ways to
get stuff done, usually better efficieny-wise than the plain Prolog
style.
Cheers,
Jorge.
> I create simple logic library for parsing text (part of this library in
> archive by link below). But execution time of parsing text using it is very
> painful.
>
> Library contain LChar module that translate some function of original Char
> module to nondetermistik variant, LList module - similary to List and String
> module that incapsulate some string-specific operations - all in
> nondeterministik way.
> main.oz file contain simple use case of library - parsing the text such
> "attr_name attribute values" to record property("attr_name", "attribute
> values"). And such simple example work 35 second on my machine! After I
> replace the realisation of Char module by content in char1.oz file, the time
> grow short to 25 second. I think that problem in All procedure in LList
> module:
>
> proc {All List Predicate Result}
> choice
> List = nil Result = false
> [] X in List = X|nil {Predicate X true} Result=true
> [] X in List = X|nil {Predicate X false} Result=false
> [] X T in
> X|T=List
> {Predicate X true}
> {All T Predicate true}
> Result=true
> [] X T in
> X|T=List
> {Predicate X false}
> Result = false
> end
> end
>
> This predicate bind Result to true if all members of list obey to Predicate
> and false if exist one or more members that not.
>
> Archive with example:
> http://www.4shared.com/file/120658649/438bf6be/logic.html
>
> _________________________________________________________________________________
> 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