Declaration of inheritance from a base class
use function_call
(use fn_call1 fn_call2 ...)
Declaration of a base class. POOL function used to define a class is also a constructor for this class.
Declaration of a base class is done in a similar style, by calling a base class constructor.
The use
instruction can be used in the class definition only,
right after the header to class_name arguments
.
Multiple inheritance can be applied using optional arguments of the use
instruction; also use of multiple use
instructions is accepted.
The function_call is using the standard function call syntax, with required and optional arguments accepted.
Also a dynamic call syntax is valid here. In this case any base class can be used if its constructor has the
number of arguments matching the number of call
arguments.
to prototype1
end
to prototype2 :param
end
to model1
use prototype2 "constant
end
to model2 :p1 :p2
(use prototype1 prototype2 :p1)
end
to model3 :proto
use call :proto
end
Example:
to prototype :param
to fn op :x end
let "x :param
end
to model :p1 :p2
use prototype :p1
to fn op :x + :y end
let "y :p2
end
"p := (newt $prototype 2)
"m := (newt $model 2 3)
print fn @ :p
print fn @ :m
Output:
2
5
See also:
Inheritance, virtual functions
Turtle - object
Dynamic call to a function
Table of Content