The first level of modularity in a programming language is the 'if' control. Everyday programs reveal that the the 'if' is very often used the following way:
if status_variable=case1 bloc1a eif status_variable=case2 bloc1b else bloc1c ... if status_variable=case1 bloc2a eif status_variable=case2 bloc2b else bloc2c
Drivers / API / generic functions is an elegant and efficient way to rewrite such a common piece of code ...... and when software design and efficiency call for the same solution, it is a must.
Important: You have to keep in mind this key difference between Pliant genericity and C++ one: In C++, genericity applyes at 'class' level. In other words, if a class contains a generic method, then all it's instance will be generical. On the other hand, if an existing class is not generical, you have no way to add generic methods to it. In Pliant, genericity applyes at 'instance' level. You can define generic methods on any existing data type, but you can apply them only to true objects (global variables and objects allocated by 'new' function).
Now, still according to my experiment, the same mistake has been repeated several times in computer tools evolution ...
Before introducing Pliant generic functions, we must define Pliant generic type notion. In the initial example, we would introduce one Pliant generic type which is the glue code, and one Pliant instance type of that generic type for each case.
A Pliant generic type is an ordinary Pliant type, it simply contains a list of instance types defined using maybe method of the Type type.
generic_type maybe possible_type arg_rw Type generic_type ; arg Type possible_type
Now a generic method is a method (or function) applied on the generic type, marked as generic using the generic keyword, that will have a different implementation for each of the instance types.
module "/pliant/language/compiler.pli" type Number void Number maybe Int Number maybe Intn Number maybe Float method n show -> s arg Number n ; arg Str s generic s := "?" method i show -> s arg Int i ; arg Str s s := string i gvar Link:Int i :> new Int i := 5 gvar Link:Number n :> i console n:show eol
Please remember: Generic methods can be called only on true Pliant objects (allocated by 'new'), not on variables allocated on the stack or on objects fields.
Several generic types may share the same index for virtual functions if they have the same generic level and don't have any instance type in common when the generic function is defined.