The Science of Programming/SwayPresentations/Objects/InheritanceImplementationStrategies

Inheritance Implementation Strategies

So how to implement the big three via concatenation inheritance?

For simplicity, let's assume a sequential search of the environment table when trying to resolve a variable.

Will use Sway syntax from here on out.

The quintessential class/constructor:

   function node(item,next)
       {
       this;
       }

Making nodes:

   var items = node(1,node(2,node(3,:null)));

Or shorthand:

   var # = node;
   var items = right(1 # 2 # 3 # :null);

Using nodes:

   while (itemsĀ != :null)
       {
       inspect(items . item);
       items = items . next;
       }

The function right can be written in Sway using reflection.


Next Previous Top