7.7
3.4 Nat
(require cur/stdlib/nat) | package: cur-lib |
This library defines the datatype Nat
and several functions on them.
Extends #%datum with nat-datum for handling natural number literals.
The natural number datatype.
procedure
(nat->unary n) → syntax?
n : syntax?
A phase 1 function that converts a natural number in decimal notation, as a syntax object, into a unary notation of the same natural number, as a syntax object.
procedure
syn : syntax? f : procedure?
A phase 1 procedure for parsing natural number literals.
Allows writing natural numbers in decimal notation.
This module automatically updates #%datum using this procedure.
Examples:
> 0 (z)
> 10 (s (s (s (s (s (s (s (s (s (s (z)))))))))))
A more lispy name for s.
Examples:
Example:
Add n and m.
Examples:
Multiply n and m.
Examples:
Compute e to the mth exponent.
Examples:
Examples:
procedure
(nat-equal? n m) → Bool
n : Nat m : Nat
Return true if and only if n is equal to m.
Examples:
> (nat-equal? (s z) (s z)) (true)
> (nat-equal? z (s z)) (false)
Return true if and only if n is even.
Examples:
Return true if and only if n is not even.
Examples: