Arc Forumnew | comments | leaders | submitlogin
Type bug? (bis) (w/eventual-patch)
1 point by palsecam 5606 days ago | 3 comments
Kind of follow-up to http://arclanguage.org/item?id=10188

Problem:

   arc(3.1)> (= intg 2)
   2
   arc> (coerce intg 'num)
   2
   arc> (type (coerce intg 'num))
   int
   arc> (isa (coerce intg 'num) 'num)
   nil
Eventual patch, in the definition of 'ar-coerce in ac.scm, change:

    ((exint? x)     (case type
		      ((num)     x)
by:

    ((exint? x)     (case type
                      ((num)     (exact->inexact x))
w/patch:

   arc> (= intg 2)
   2
   arc> (type intg)
   int
   arc> (coerce intg 'num)
   2.0
   arc> (type (coerce intg 'num))
   num
   arc> (isa (coerce intg 'num) 'num)
   t
------

However, this is just my opinion, this is pedantic, this is a bit playing on terminology, and this would be more difficult to patch, but I expect:

   arc> (isa intg 'num)
   t
An integer is a number after all (Z ⊆ C). If you want to know if intg is a "non-integer number" or not, you could always check (~isa intg int).

What do you people think about all this?



2 points by tc-rucho 5605 days ago | link

  Regarding the last part:
  What we are talking about here is:
  num => float
  int => int
Of course an integer is a number, but number here means what float does everywhere else.

Having 'isa report 2 as 'num, would only screw up things. In any case, this is what 'or is meant to be used for. (or (isa intg 'int) (isa intg 'num))

-----

1 point by palsecam 5604 days ago | link

> Having 'isa report 2 as 'num, would only screw up things.

OK, I too can consider this point of view, that's why I asked what people here think about this proposal. Thanks for giving your opinion tc-rucho!

> (or (isa intg 'int) (isa intg 'num))

Yep true, this makes it easy to check.

But yes, as rntz pointed it out, don't forget num is not just only float here. We are not in C ;-)

   arc> (type 3+2i)   ; (Mz)Scheme/Arc also handle complex numbers natively
   num
Although this doesn't invalidate your point, it's just a question of terminology.

-----

2 points by rntz 5605 days ago | link

'num is not float; rationals are also 'nums.

  arc> (/ 2 3)
  2/3
  arc> (type 2/3)
  num

-----