newLISP Fan Club

Forum => Anything else we might add? => Topic started by: Dmi on March 30, 2006, 09:53:13 AM

Title: integer functions on floats
Post by: Dmi on March 30, 2006, 09:53:13 AM
Lutz, I just got an idea:


(+ 1.5 2.3) => 3

In my own practice, this implicit conversion from a float to an integer in functions, such as (+) and (-) mostly causes a mistakes and is really useful in rare cases.



Probably, it will be good - to supress the conversion (throw a type error) and force programmer convert it explicitly?
Title:
Post by: Lutz on March 30, 2006, 10:27:07 AM
I know some using this. Those who don;t like it should put:

(constant (global '+) add)
   ...

in there init.lsp or ~/.init.lsp

> (constant (global '+) add)

> (+ 1.2 3.4)
4.6
>



Then there will be always implicit conversion to float only like in Perl/Python etc., and only when writing library interfaces the (int ...) cast is used. I believe throwing errors will confuse more as all other functions also convert from/to int/float as needed.



Lutz
Title:
Post by: Dmi on March 30, 2006, 04:40:25 PM
Thanx for a trick - now my financial calculations will lose the cents less frequently :-)



Simply I've think about absence of such autoconversion for strings and got an idea, that the integers relyes to the floats like to the strings...

Just an idea... :-)