It's a solution to my immediate problem, but I'm still at a loss as to
why my original attempt enters into a wait. In combining some ideas
that you gave me, with my original attempts, I think I see where I've
been going astray. It would appear that binding a top level variable
within a choice statement causes my grief. In piecing together the
behavior, I wrote 3 versions of the list generator. The first (ListA)
generates the infinite choices similar to your solution with no binding
involved. The second (ListB) tries to bind the variable that is sent to
the function. The third (ListC) is what I originally started with - it
has the same problem as ListB.
So, I guess my question is: Is it not possible to bind a top level
variable within Choice? I'm speculating that the choice doesn't allow a
bind, but rather goes into a wait until such time as the top level space
gets bound. But since the top level is waiting on the choice to
succeed, you go into a wait state.
%% N possible solutions
fun {SolveN N F}
L = {Solve F}
in
{List.take L N}
end
%% Generates the solutions, with no binding
fun {ListA L}
if {IsDet L} == true then
case L
of H|T then H|{ListA T}
else L
end
else
choice
nil
[] _|{ListA _}
end
end
end
%% attempt to bind unbound tail
fun {ListB L}
if {IsDet L} == true then
case L
of H|T then H|{ListB T}
else L
end
else
choice
L = nil %% Why does binding attempt cause wait?
[] H T in
L = H|{ListB T}
end
end
end
%% same here
fun {ListC L}
choice
L = nil
[] H T in
L = H|{ListC T} %% if L unbound, then gets bound here
end
end
local X in
%% These should just echo back the list as the only solution
{Browse a1#{SolveN 1 fun {$} {ListA 1|2|3|nil} end}}
{Browse b1#{SolveN 1 fun {$} {ListB 1|2|3|nil} end}}
{Browse c1#{SolveN 1 fun {$} {ListC 1|2|3|nil} end}}
%% This doesn't bind X, so it completes successfully
{Browse a2#{SolveN 1 fun {$} {ListA 1|2|3|X} end}}
%% I get frozen on either of these two
{Browse b2#{SolveN 1 fun {$} {ListB 1|2|3|X} end}}
{Browse c2#{SolveN 1 fun {$} {ListC 1|2|3|X} end}}
end
Thanks,
Chris Rathman
Filip Konvicka wrote:
Well then try the following:
local
fun {FindTail L}
if {IsDet L}==false then
nil#_
else
case L
of nil then
nil#nil
[] H|T then
H2#T2={FindTail T}
in
(H|H2)#T2
end
end
end
fun {GenLists L}
H#T={FindTail L}
in
if {IsDet T} then
[L]
else
fun lazy {GL N}
{Append H {List.make N}}|{GL N+1}
end
in
{GL 0}
end
end
InitSegment={List.take {GenLists a|b|c|_} 5}
in
{Browse InitSegment}
end
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users