The Science of Programming/SwayPresentations/Objects/InheritanceImplementationStrategies

< The Science of Programming‎ | SwayPresentations/Objects

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)

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