#
#	Class to augment any other class with bootstrapping information
#
#	Gaston H. Gonnet (March 15th, 2009)
#
Bootstrapped := proc( Base:anything, Positive:{0,posint}, OutOf:{0,posint} )
    option polymorphic, NoIndexing, NormalizeOnAssign;
if nargs=1 then return( noeval( procname( Base, 0, 0 )))
elif nargs <> 3 then error('Bootstrapped must have exactly 3 arguments')
elif Positive > OutOf then error('number of positives must be <= OutOf') fi;
noeval(procname(args))
end:

# the selector is only called on unknown field names (integer indexing
# is disallowed), so this has to be resolved by the base type
Bootstrapped_select := proc( this:Bootstrapped, sel, val )
if nargs=2 then this['Base',sel]
elif nargs=3 then this['Base',sel] := val
else error('invalid number of arguments') fi;
end:

# the type function has to respond to Bootstrapped or the base type
Bootstrapped_type := proc( this:Bootstrapped, t )
lprint('call to Bootstrapped_type',args)
end:

CompleteClass(Bootstrapped);


printlevel := 100;
ExtendClass( BootstrappedTree, Tree,
	[Positive,{0,posint},0],
	[OutOf,{0,posint},0] );
CompleteClass( BootstrappedTree );

t := Rand(Tree);

c := proc( t:Tree )
if type(t,Leaf) then t
else BootstrappedTree(Tree(procname(t[Left]),t[Height],
	procname(t[Right]))) fi
end:

bt := c(t);
done
