Arc Forumnew | comments | leaders | submitlogin
2 points by Pauan 5188 days ago | link | parent

By the way, this reminds me of Traits.js: http://traitsjs.org/

I remember being sorta-vaguely interested in it a long while ago, but never tried it. Now that I've learned Arc, all I can see is that the examples would be half as short (or shorter!) with macros. :P

If I were to strictly translate the example on their home page, it might look like this:

  (def make-color-trait (c)
    (trait color (fn () c)))

  (def make-point (x y)
    (trait-compose (make-color-trait 'red)
                   (trait getx  (fn () x)
                          gety  (fn () y)
                          print (fn () (string x '@ y)))))
                          
  (= p (make-point 0 1))
  (p 'color) -> 'red
Okay, not quite half as short, but even so. From what I can tell, traits seems to be an interesting way to combine objects together, according to a contract. Not saying this is "The Way", but it might be interesting to write a traits.arc library to play around with it.

---

Also, apparently traits were invented in Self... which also invented prototypes (!):

http://en.wikipedia.org/wiki/Trait_%28computer_programming%2...