Arc Forumnew | comments | leaders | submitlogin
type dispatching
4 points by conanite 6181 days ago | 6 comments
There have been some threads relating to the proper interpretation of forms where the object in functional position is not a function. The goal being to give a sensible meaning to, for example,

  (10 x)
  ("thing" 'sym)
  ('foo 1/2) ; not that I can think of a sensible interpretation for this ...
Would it be useful for the interpreter, considering the object in functional-position, and finding it does not reference a function, to consider its type, and lookup a function based on that? In other words, automatically translating

  (10 x)
into something like

  (int-type-function 10 x)
While this seems interesting for primitive types (int, string, symbol etc), I am guessing this could bring extraordinary power to 'annotate. For example,

  (set current-user (annotate 'user (get-current-user))
  (current-user 'disable)
results in

  (user-type-function current-user 'disable)
I agree that "int-type-function" is ugly and we could find a neater convention, but does the principle make sense? It seems to provide a way to make programs shorter and more readable at the same time. Or am I completely missing something?


6 points by absz 6181 days ago | link

This exists on the Anarki, in the form of defcall: http://arclanguage.org/item?id=3743 . Yes, it's quite helpful :)

-----

2 points by bOR_ 6179 days ago | link

tempting reason to switch from arc2 to anarki :).If I understand right, I could make arc understand that if I have a list of lists, (mylist 3 2) wants the second position from the third list.

Nice, is this a something that you can influence locally, within a function, or is it a do-once-per-program thing of arc?

I'll keep it in mind when I'm extending and abstracting my first arc prog at http://bagofsouls.com/images/arc-life.arc :).

-----

2 points by almkglor 6179 days ago | link

Yes, this is possible, although you should note that 'defcall is global (do-once-per-program)

-----

1 point by bOR_ 6179 days ago | link

Is it possible to have it in a local way? (per function / module)

-----

1 point by almkglor 6179 days ago | link

No, or rather not yet.

It might be possible to do so by using some sort of dynamic global (a la kennytilton's implementation some time back, but using 'thread-local objects to handle it).

-----

3 points by conanite 6181 days ago | link

Aha, that was before my time. And there I was thinking I was being original. Thanks for the link.

-----