Arc Forumnew | comments | leaders | submitlogin
Inheritance Idea
1 point by Bogart 5952 days ago | 1 comment
Say I want to make a subclass of a list. I can annotate a list with my class name and overload functions on it via redef or defm, but I won't be able to get the inheritance. If I try to give it a function for lists, it won't understand it. The most direct way to get around this is to look on up the annotation chain. That is:

  (redef isa (ob class)
  	(or (old ob class)
  		(let repr (rep ob)
  			(unless (is repr ob)
  				(isa repr class)))))
The only problem with this is that there might be a situation where you don't want inheritance. For example, 1 is always an int, no matter how it's tagged, and functions on ints will always work on it. How would one get around this?


1 point by almkglor 5951 days ago | link

The lack of the ability to subclass has been galling. Take a look at the "Create your own collection" series, for example. Each of them emulate tables, but they need to do a lot of background hackery just to emulate tables. And it's hard to determine which subclass of tables it uses.

So I introduce "zen typing". You wear a blindfold (i.e. ignore the type) and just code as if the existing functions will work. Let the functions fight over how to exactly implement them ^^

-----