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
  ;base class, constructor w/o arguments
end

to prototype2 :param
  ;base class, constructor with an argument
end

to model1
  use prototype2 "constant
  ;derived class, constructor w/o arguments
end

to model2 :p1 :p2
  (use prototype1 prototype2 :p1)
  ;multiple inheritance, constructor with 2 arguments
end

to model3 :proto
  use call :proto
  ;dynamic inheritance, any base class w/o required
  ;arguments in constructors are allowed
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