Arithmetic
The arithemtic operators in Lisp mostly have the same names and the same
behaviour as in other languages you have encountered. However, one place to
be wary is with any operation involving division: because some Lisps have a
wide variety of numeric types (sometimes including rational numbers) the
results may not always be what you expect.
- (+ [ num1 num2 ... ] )
- Computes the sum of
the arguments using the generic function
binary+
.
Given zero arguments, +
returns 0
.
One argument returns that argument. The arguments are combined
left-associatively.
- (- num1 [ num2 ... ] )
- Computes the result
of subtracting successive arguments, from the second to the last, from
the first using the generic function
binary-
. Zero
arguments is an error. One argument returns the negation of the
argument, using the generic function negate
. The
arguments are combined left-associatively.
- (* [ num1 num2 ... ] )
- Computes the
product of the arguments using the generic function
binary*
. Given zero arguments, *
returns 1
. One argument returns that argument. The
arguments are combined left-associatively.
- (/ num1 [ num2 ... ] )
- Computes the result
of dividing the first argument by its succeeding arguments using the
generic function
binary/
. Zero arguments is an error.
One argument computes the reciprocal of the argument. It is an error in
the single argument case, if the argument is zero.
- (% num1 [ num2 ... ] )
- Computes the result
of taking the remainder of dividing the first argument by its succeeding
arguments using the generic function
binary%
. Zero
arguments is an error. One argument returns that argument.
- (abs num)
- Computes the absolute value of
num
.
- (negate num)
- Computes the additive inverse of
num
.
- (zerop num)
- Compares number with the corresponding
zero element of
num
, that is 0
for
integers and 0.0
for floating point using the generic
function binary=
.
- binary+, binary-, binary*, binary/, binary%
- These are
the two argument implementations of the corresponding operations.
These functions are called by the n-ary argument functions described
above. These are generic functions in order to implement the different
behaviours needed to combine different kinds of numbers. Note: this
organization and use of generic functions is EuLisp specific, but the
n-ary functions above should be available in most Lisps.