Arc Forumnew | comments | leaders | submitlogin
Type Bug?
6 points by tc-rucho 5593 days ago | 4 comments
Ok, first of all, the credit for finding this bug out goes to edeion, since it was due to him asking in #arc about numbers comparison that I noticed this.

Let's start the denmostration:

  (type 2) => int
  (type 2.0) => int
  (type 2.1) => num
It initially makes sense for 2.0 to be 'int since it can be losslessly coerced to an integer, but this is where the problem starts:

  (coerce 2.0 'int) => 2.0 ; ouch
  (is 2.0 2) => nil
  (iso 2.0 2) => nil
  (isa 2.0 2) => nil
I'm aware coerce will first check if the target type differs from the object's type before doing it's job, hence it fails when 2.0 is typed as 'int

TC



2 points by palsecam 5592 days ago | link

In the definition of 'ar-type in ac.scm, change:

   ((integer? x) 'int)
by:

   ((and (integer? x) (exact? x))  'int)
Same file, definition of 'ar-coerce, change:

   ((integer? x) [...]
by:

   ((and (integer? x) (exact? x)) [...]
This leads to:

   (type 2) => int
   (type 2.0) => num
   (type 2.1) => num
   (coerce 2.0 'int) => 2
------

"It initially makes sense for 2.0 to be 'int since it can be losslessly coerced to an integer": mostly a question of personal taste but I don't agree.

"2.0" is not "2". An integer has no decimal part. If you want an integer, either you say "2" or you coerce "2.0" to 'int. In my view, the "integer" notion is when you're dealing with low level stuff (like in C) and at this level you don't want any cleverness (like 2.0 being an int because it is mathematically equals to 2).

The fix above makes it work like that (type of 2.0 is 'num).

Plus, there are languages (say, Python) in which:

   3 / 2.0 = 1.5
   3 / 2 = 1
Edit: and in Arc also it differs!:

  (/ 3 2.0)  => 1.5 
  (/ 3 2) => 3/2

-----

2 points by edeion 5592 days ago | link

My question came from http://arcfn.com/foundation-doc.html#numbers where I read:

>(type 5.0)

int

Which indeed surprised me. And what I experimented surprised me even more.

Thanks again, tc-rucho, for the bugreport. I tried to post a similar one but the forum barred me with the message: "You're submitting too fast. Please slow down. Thanks." I guess that was a bug, but I can't tell where it came from. I have kept the message in store in case it could help finding this out.

-----

3 points by pg 5592 days ago | link

Yes, that coerce looks like a bug; will fix.

-----

1 point by pg 5588 days ago | link

Fixed in 3.1.

-----