Arc Forumnew | comments | leaders | submitlogin
1 point by rntz 5637 days ago | link | parent

What would the intended result be? Just to get the same number back? Although intuitive, that would violate a fairly important invariant: that (coerce x ty) either errors or returns an object whose type is ty. 0.0? That seems a bit odd. I suppose 'exact->inexact would work.


1 point by CatDancer 5637 days ago | link

Why is this invariant important?

-----

1 point by rntz 5637 days ago | link

It's more or less what coerce means.

-----

2 points by CatDancer 5637 days ago | link

In arc3 I can already ask 'coerce to convert something for me into some general type and get back a more specific subtype:

  arc> (type (coerce "0" 'num))
  int
Maybe that's ok.

-----

1 point by rntz 5637 days ago | link

Hm. I wasn't thinking of it in terms of sub- and super-types, but in that context it makes sense. Thinking this way, if 'int is a subtype of 'num, then (isa 2 'num) should ideally return t; unfortunately it's nil in the present arc. :( I guess we'll just have to chalk arc's handling of types up as a bit of leaky abstraction and leave it be. I'll go push a fix for (coerce 0 'num) to anarki.

-----

2 points by CatDancer 5637 days ago | link

  (def isa (x y)
    (or (is (type x) y)
        (and (is y 'num) (is (type x) 'int))))

  arc> (isa 34 'num)
  t
On the one hand, this seems like the "right" answer, on the other hand, so far I've haven't needed this.

-----