%
(function)
%
is the remainder operator/function—not to be confused with mod
(i.e., modulo).
repl> (root-env '%)
@{:doc "(% & xs)\n\nReturns the remainder of dividing the first value of xs by each remaining value."
:value <function %>}
%=
(macro)
There is also a macro variant that mutates its first argument.
repl> (macex '(%= x 2))
(set x (<function %> x 2))
repl> (root-env '%=)
@{:doc "(%= x & ns)\n\nShorthand for (set x (% x n))."
:macro true
:source-map ("boot.janet" 145 1)
:value <function %=>}
Things I Learned
- Janet numbers are always IEEE 754 double-precision floating-point values.
%
is variadic, though it’s not clear to me whether that’s generally useful for a remainder operation.%
corresponds to therem
instruction in the abstract machine.%
is implemented via C’s fmod.- Arbitrary objects can be used with the
%
function if the object in question implements the:%
or:r%
methods.