Arc Forumnew | comments | leaders | submitlogin
1 point by thaddeus 5580 days ago | link | parent

> "Finally, why is obj called obj?"

I like "obj". After all in OOP isn't an object simply a property list of key/value pairs with initial values set to define the object?

   i.e.

   (= vampire (obj teeth "fangs" hair "black" food "blood"))

   (= Dracula vampire)

 So now we have an instance named "Dracula" of a "vampire" object....  
or maybe I'm on glue thinking this was the intent.... T.


2 points by conanite 5579 days ago | link

I share your guess that 'obj is a contraction of "object". I don't think it means exactly what your example suggests. Continuing your example, if you write

  (= conanite vampire)
, the symbols 'vampire, 'conanite and 'Dracula all refer to the same object instance, so it's probably not what you want. In other words, you can turn conanite's hair blue like this:

  (= Dracula!hair 'blue) ; *not tested*
I don't know if it's the glue, but I think 'deftem ("define template") and 'inst ("instantiate template") do what you describe here.

  (deftem vampire name nil fangs 2 hair 'black requires 'blood) ; sorry, my vampire is defined a little differently
'deftem sorta kinda creates a "class" - but only with data slots, no behaviour.[1] Now, if you want to call up some vampires,

  (= Dracula (inst 'vampire 'name "Dracula"))
  (= conanite (inst 'vampire 'hair 'gray))
inst is pretty similar to obj, except internally it relies on a set of preconfigured "templates" which provide the set of keys (and their default values) for the thing you are going to build. It's used in blog.arc to define blog posts, as well as news.arc to define news items, and user accounts.

[1] at least, not by design, but there's nothing to stop you from assigning a function as the default value of any slot; except then it couldn't really be written to disk ...

-----

2 points by thaddeus 5579 days ago | link

Ah... you're correct. I was thinking of the inst behaviour.

Too bad the following doesn't work:

   arc> (= vampire (obj teeth "fangs" hair "black" food "blood"))
   #hash((hair . "black") (food . "blood") (teeth . "fangs"))
   arc> (= Dracula (inst 'vampire))
   #hash()
Thanks for the correction... (haven't worked on arc for a few weeks :) T.

-----