Search code examples
declarativeoz

Determining if OZ variable is bound?


Is there a safe way to ask if a single assignment variable in OZ is bound or not?

Using an unassigned data flow variable in a way that requires the value will cause the program to wait until a value is assigned. In a sequential environment, this means the the program hangs. Assigning a different value to a variable will cause the program to fail. So both ways "tell" me if the variable was bound but not in a safe way.

I'm looking for some function "Bound" where

local X Y=1 Xbound YBound in 
   Xbound={Bound? X}
   Ybound={Bound? Y}
end

gives false and true for Xbound and Ybound respectively.

My use case involves processing a list where values are added incrementally with the last value always being unbound. I want to use the last bound item (the one before unbound one.) And I'm trying to work in the OZ paradigm with the least concepts added (so no mutable variables or exceptions.)


Solution

  • You can check whether a variable is bound with the function IsDet.

    See here: http://mozart.github.io/mozart-v1/doc-1.4.0/base/node4.html (also works in Mozart 1.3.0)

    A word of caution: if you are using multiple threads, this opens the door for race conditions.