Arc Forumnew | comments | leaders | submitlogin
4 points by rntz 6115 days ago | link | parent

Well, this approach basically is the 'annotate approach, except instead of having a separate basic data type - a "tagged" object - you just use cons cells, where the car is the type and the cdr the rep.

The problem is that unless you make lists also use this representation, as Mathematica does, you can't distinguish between lists and objects of other types - a major problem, especially if you use anarki stuff like 'defm and 'defcall. Moreover, objects of this form do not evaluate to themselves, but to structurally equivalent objects. This is usually okay, but if you're using shared, mutable data structures, it's kind of problematic; moreover, it can introduce a lot of unnecessary consing. This isn't likely to be a major problem (how often are objects subject to excess evaluation?), but if it does crop up, it could make for some nasty bugs.



2 points by almkglor 6114 days ago | link

> Well, this approach basically is the 'annotate approach, except instead of having a separate basic data type - a "tagged" object - you just use cons cells, where the car is the type and the cdr the rep.

Except for the case where (isa R T), where (annotate T R) returns R directly:

  arc> (annotate 'int 0)
  0

-----

1 point by rntz 6113 days ago | link

This isn't a fundamental difference. Just as 'annotate could as easily create a new doubly-wrapped object, 'annotate-cons can as easily not cons when the type is the same.

    (def annotate-cons (typ val)
      (if (isa val typ) val (cons typ val)))

-----

1 point by rincewind 6114 days ago | link

the difference between this and annotate is that this lets you write one quote less, compare:

   >(point 1 2)
   (point 1 2)
and

   >'#3(tagged point (1 2))
   #3(tagged point (1 2))

-----

2 points by rntz 6113 days ago | link

As far as I'm concerned, this is a bug/misfeature in Arc. Objects should always evaluate to themselves unless they're symbols or lists.

-----