Arithmetic operations
One big difference as compared to other Lisps is that Nujel does not support rational numbers or complex numbers by default, all operations are done on fixnums and flonums, with not added checks for overflows.
Reasoning
This is mostly to keep Nujel as minimal as possible, since it wouldn't seem to benefit any project being written in Nujel right now, and might have a performance impact due to the additional checks.
1. Basic operators
Nujel supports most standard operators for integers as well as floating-point numbers (or fixnums and flonums). There is no operation called mod/modulo, but instead it is called rem
, just like in Clojure.
Division will also always return a flonum, if you want to do an integer division you can use div/int
instead. Apart from that doing operations between fixnums and flonums will result in a flonum, with fixnums only being returned when both operands are fixnums.
(+ 1 2 3 4) ; You can add as many numbers as you want 10 (+ 1 2 (+ 3 4)) 10 (+ (+ 1 2) (+ 3 4)) 10 (+ 1 -2) ; You can also use negative numbers in additions -1 (+ 1 (- 2)) ; - can also be used to negate numbers -1 (+ 1 (- (+ 1 1))) ; Results of a calculation can also be negated -1 (+ 1 "drei") ; You can only calculate with numbers :type-error
2. Exceptions
Dividing through zero generates an exception, which is probably not that suprising, this however also extends to floating point operations where NaN as well as +/-Inf are invalid values that Nujel will not create, instead raising an Exception.
Reasoning
This seems to be an inconsitency in how integers and floating-point numbers are handled, since I can't think of time where I wanted a NaN/Inf value it seems reasonable to me to handle this case just like integers, meaning raising an exception.
(/ 10 0) :float-inf (div/int 10 0) :divide-by-zero
3. Conversion
Nujel also provides a couple of functions for converting between the different numeric formats.
In general, Nujel will never implicitly convert a flonum to a fixnum, since that might mean loosing precision, if it does it is considered a bug in the implementation.
It will however implicitly convert fixnum's to flownum's whenever that seems to be the least suprising choice.
(int 1.1) 1 (float 1) 1.0