Ordered Values

Ordered  module

The Ordered module provides various utility methods for anything that defines ordering and from-ordering:.

o ordering  Integer

The ordering of the value in its sequence.

Example:

> 1 ordering
1
> $a ordering
97
> 1/2 ordering
0
o from-ordering: n  any
  | n is-a?: Integer

Creates a value given its ordering in its sequence.

Example:

> Integer from-ordering: 1
1
> Character from-ordering: 97
$a
> Rational from-ordering: 2
2/1
o succ  any

Moves forward one "step".

Example:

> 1 succ
2
> $a succ
$b
> 3/2 succ
2/1
o pred  any

Moves backward one step.

Example:

> 1 pred
0
> $a pred
$`
> 3/2 pred
0/1
o shift: diff  any
  | diff is-a?: Integer

Moves around in the ordering by diff steps.

Example:

> 1 shift: 2
3
> $f shift: -2
$d
x to: y by: diff  List
  | diff is-a?: Integer

Returns a list of the values in the ordering from x to y, shifting by diff.

Example:

> 1 to: 5 by: 2
[1, 3, 5]
> $a to: $z by: 3
[$a, $d, $g, $j, $m, $p, $s, $v, $y]
> $z to: $a by: -3
[$z, $w, $t, $q, $n, $k, $h, $e, $b]
x up-to: y  List

x to: y by: 1.

x down-to: y  List

x to: y by: -1.