I'm using the Tree definition, that comes with The VDM++ Toolbox v9.0.2 and, when trying to use the function addRoot() (using the interpreter), on the first usage, I always get the error: "Run-Time Error 266: Operation or function is not in scope". If I run the function again, it works. Why does it have this behaviour?
I'm adding the Tree code that comes with VDM++ Toolbox. (Please ignore type and syntax errors, since I've fixed them all and it still won't work)
-- START CODE -- The Tree Class
class Tree
types
protected
tree = <Empty> | node;
public
node :: lt: Tree
nval : int
rt : Tree
instance variables
protected
root: tree := <Empty>;
operations
protected
nodes : () ==> set of int
nodes () ==
cases root:
<Empty> -> return ({}),
mk_node(lt,v,rt) -> return(lt.nodes() union {v} union rt.nodes())
end ;
protected
addRoot : int ==> ()
addRoot (x) ==
root := mk_node(new Tree(),x,new Tree());
protected
rootval : () ==> int
rootval () == return root.nval
pre root <> <Empty>;
protected
gettree : () ==> tree
gettree () == return root;
protected
leftBranch : () ==> Tree
leftBranch () == return root.lt
pre not isEmpty();
protected
rightBranch : () ==> Tree
rightBranch () == return root.rt
pre not isEmpty();
protected
isEmpty : () ==> bool
isEmpty () == return (root = <Empty>);
end Tree
-- END CODE --