Strange predicate behavior?

Started by bfulgham, September 16, 2004, 05:56:27 PM

Previous topic - Next topic

bfulgham

If I do this:


> (integer? 25)
true


So far, so good.  but what about:


> (integer? (sqrt 25))
nil


Huh?  Am I doing something wrong?  It's almost as though integer?

is evaluateing the sqrt function, rather than the result of the function.



Am I misunderstanding how newLisp evaluates data?

Lutz

#1
All math functions return floats. Only +, -, * , /, % and the bit manipulating functions return integers.



This is one area where newLISP is different from most scripting languages which do all math in  (double) floats internally.  You can have the same in newLISP redefining +,-,/* this way (see chapter "Customization ..." in the manual):



(constant '+ add)

(constant '- sub)

(constant '* mul)

(constant '/ div)

(constant '% mod)



preserving pure integer arithmetic is useful when interfacing with some 'C' library functions or compiling newLISP for CPUs incapable of floating point operations and when doing extensive bit-fiddleing.



'C' library imports in newLISP are very short (think 'scripting') because they don't have to declare types of parameters passed. This makes it necessary to distinguish between integers and floats in newLISP. If library imports are of little concern overload +,-,*,/,% as shown above.



Functions which require integers in newLISP, i.e. indices into lists/arrays etc. automatically convert floats into integers. All functions requiring floats convert integers to floats as well.



Lutz