Page 1 of 1
integer functions on floats
Posted: Thu Mar 30, 2006 5:53 pm
by Dmi
Lutz, I just got an idea:
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?
Posted: Thu Mar 30, 2006 6:27 pm
by Lutz
I know some using this. Those who don;t like it should put:
in there init.lsp or ~/.init.lsp
Code: Select all
> (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
Posted: Fri Mar 31, 2006 12:40 am
by Dmi
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... :-)