I am learning LISP right now and I haven't found anything on how to get the modulus in LISP. Is there someway to get it inside of a function? I know other languages like Java use % in order to find the modulus, but what does LISP use?
mod performs the operation floor on number and divisor and returns the remainder of the floor operation. rem performs the operation truncate on number and divisor and returns the remainder of the truncate operation. mod and rem are the modulus and remainder functions when number and divisor are integers.
In Lisp, the function for computing a remainder is % . The function returns the remainder of its first argument divided by its second argument.
Scheme modulo is implemented as ((n%m)+m)%m.
How about mod
, from the page:
(mod -1 5) => 4
(mod 13 4) => 1
(mod -13 4) => 3
(mod 13 -4) => -3
As an alternative to mod
, the Common Lisp floor
function returns modulo as its second value. This is useful in cases where you are also interested in the quotient.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With