2.6 (aux number)

Operating on numbers.

2.6.1 Procedures

Procedure: factorial n

Return n!

Example:

> (factorial 6)
720
Procedure: largest numbers

Return the largest number in the list of numbers.

Specification:

numbers (list of numbers): See example.

Return value (number): The largest number or 0, if the list is empty.

Example:

> (largest (list 4 2.5 15 68))
68
Procedure: minus-one n

Return n-1.

Example:

> (minus-one 10)
9
Procedure: number->string-abbr number

Return number as a string abbreviation for thousands and millions.

Specification:

number (number): See examples.

Return value (string): The number but rounded down and abbreviated. For example:

Examples:

> (number->string-abbr 1568.51)
"+1.0K"
(number->string-abbr 12352)
"+12K"
> (number->string-abbr 80437231)
"+80M"
Procedure: plus-one n

Return n+1.

Example:

> (plus-one 7)
8
Procedure: range a b

Return the list of integers in the range [a, b].

Specification:

a (integer): The first number in the range.

b (integer): The last number in the range.

Return value (list of integers): All the numbers in the range.

Example:

> (range -2 3)
(-2 -1 0 1 2 3)
Procedure: skip-count n KEY: #:start #:skip

Return a list of numbers from start to n, inclusive.

Specification:

n (natural): The number at which the count stops.

start (natural): Optional. The number at which the count starts. If not provided, it defaults to 0.

skip (natural): Optional. The number to use for skip counting. If not provided, it defaults to 1.

Return value (list of naturals): The numbers in the count. If n is 0, return (list 0).

Examples:

;;; Count to five like a programmer.
> (skip-count 5)
(0 1 2 3 4 5)
;;; Count to five like a normal person.
> (skip-count 5 #:start 1)
(1 2 3 4 5)
;;; Count by tens until 100.
> (skip-count 100 #:start 10 #:skip 10)
(10 20 30 40 50 60 70 80 90 100)
Procedure: sum n

Return the sum of the natural numbers from 0 to n.

Example:

> (sum 11)
66