brownplt / lambda-py

Other
58 stars 10 forks source link

Numeric primitives return objects of class 'num', which doesn't exist in python. #25

Closed dbp closed 11 years ago

dbp commented 11 years ago

N.B.: I sent this same thing to the list.

In builtins/num.rkt, make-builtin-num creates ints or floats depending on what the number is. This lines up with how python deals with numbers.

If you add an int and a float in python, you get a float, similarly with multiplication, division, etc. Furthermore, if you do integer division and the remainder is non-zero, the division is performed as if the original numbers were floats.

However, in the primitives implementation of base, the numeric primitives return values of type num, and int and float are both subtypes. This 'num' type seems to be a problem, because as far as I can tell, there is no such type in python - float and int are independent classes with no superclass (aside from object).

Here is an example of why this is wrong (this will fail in our implementation):

x = 1 + 1.5
assert(x.__class__ == float)
amtriathlon commented 11 years ago

This issue seems fixed since numeric primitives also create int or floats depending on what the result is and the example is passing in current master.

amtriathlon commented 11 years ago

The issue still is present for some numeric primitives such us *, /, //, % and cmp.