x-lang

← Index

x/core/arithmetic

Variadic +, -, *, /, % folded over the binary C primitives.

+

Variadic addition. Returns the sum of all arguments.

Parameters:

Returns: NUMBER — Sum of all arguments, or 0 with no arguments

Examples:

(+ 1 2 3) => 6
(+) => 0

*

Variadic multiplication. Returns the product of all arguments.

Parameters:

Returns: NUMBER — Product of all arguments, or 1 with no arguments

Examples:

(* 2 3 4) => 24
(*) => 1

/

Variadic integer division. Folds left.

Parameters:

Returns: NUMBER — Quotient from left fold

Examples:

(/ 100 5 2) => 10

-

Variadic subtraction. With one argument, negates. With multiple, folds left.

Parameters:

Returns: NUMBER — Difference, or negation with one argument

Examples:

(- 10 3 2) => 5
(- 5) => -5

&

Bitwise AND.

Parameters:

Returns: INTEGER — Bitwise AND

Examples:

(& 12 10) => 8

|

Bitwise OR.

Parameters:

Returns: INTEGER — Bitwise OR

Examples:

(| 12 10) => 14

^

Bitwise XOR.

Parameters:

Returns: INTEGER — Bitwise XOR

Examples:

(^ 12 10) => 6

<<

Left shift.

Parameters:

Returns: INTEGER — Shifted value

Examples:

(<< 1 4) => 16

>>

Arithmetic right shift.

Parameters:

Returns: INTEGER — Shifted value

Examples:

(>> 16 2) => 4
(>> -16 2) => -4

<

Test numeric less-than.

Parameters:

Returns: BOOL — t if a < b

Examples:

(< 1 2) => #t
(< 2 1) => #f

~

Bitwise NOT.

Parameters:

Returns: INTEGER — Bitwise complement

Examples:

(~ 0) => -1
(~ 5) => -6