Arc Forumnew | comments | leaders | submitlogin
OOP in Arc
6 points by pgwoden 6096 days ago | 5 comments
We all know from the PG's website that "Arc isn't especially object-oriented." Does it actually have (or will it have) and OO features at all? As far as I can tell from the tutorial, there are currently none.


3 points by sacado 6095 days ago | link

If you implement your objects like hash tables (the way it is done in Lua, Javascript, Perl or -- secretly -- in Python), you can easily implement anything you need, including duck typing and inheritance : http://arclanguage.com/item?id=3155.

But not strong encapsulation, sorry. This can be done with closures however, if you really need it (but I don't think Arc is the right language if you want to constrain the developer at all).

You can also make any function doing dynamic dispatch based on the type of objects. For example, you can redefine the + function to perform a special operation when called with a foo object as a parameter, or behave the usual way in the other cases. That's a method-calling mechanism (even more powerful actually). Use any object representation you need (hash table, list, cons cell, integer, ...) and 'annotate, and you're done !

-----

3 points by eds 6096 days ago | link

I believe that Arc intends to provide features sometimes considered to be OO, but not packaged in a single monolithic system like most OO langauges. So while you should (at least theoretically) be able to accomplish anything in Arc you could do in an OO language, don't expect it to conform to your concept of OO.

For example, see the discussion http://arclanguage.org/item?id=4855.

-----

2 points by jmatt 6095 days ago | link

If templates isn't feature rich enough, I imagine it is just a matter of time before someone implements a more complete OO system in arc.

In the meantime there are a bunch of schemes and lisps that support different object systems. You'll want to look for CLOS (Common Lisp Object System) and MOP (metaobject protocol) in the descriptions. I've used gauche scheme and had some good luck. http://practical-scheme.net/gauche/

-----

3 points by drcode 6096 days ago | link

http://arcfn.com/doc/template.html

-----

1 point by jimbokun 6088 days ago | link

http://arclanguage.com/item?id=1648

-----