Arc Forumnew | comments | leaders | submitlogin
Extend Arc functions (github.com)
10 points by CatDancer 5797 days ago | 3 comments


2 points by rntz 5796 days ago | link

This is vaguely similar to 'defmulti in "lib/multi.arc" on Anarki (http://arclanguage.org/item?id=8330), except this allows one to override existing functions, and explicitly has in-order overriding semantics rather than look-up semantics. Similar code, different use-cases. The label argument makes it a nice improvement over anarki's 'redef, though. Personally, I think the ultimate solution to this problem is to unify pattern-matching and inheritance (http://www.rntz.net/post/oo-and-pattern-matching.html), but this is a pretty neat hack.

-----

2 points by Darmani 5796 days ago | link

Problems occur if two extensions conflict -- i.e.: if the tests for two different extensions both return true on an input. However, this can easily be modified to create some sort of alert if that's the case.

Problems can also occur if one person's code only works with a certain extension not in place. A solution would probably involve some sort of scoping mechanism like

  (using-extensions (+ '(table complex)  my-standard-extensions*)
    ...
    (my-code [+ ...])
    ...)

-----

1 point by CatDancer 5796 days ago | link

Having the tests for two extensions return true for an input can be useful, for example if you have a specific case and a general case. By loading the specific extension after the general extension, the specific one will override the general one.

-----