This module contains some handy functions to convert numbers
to strings and vice-versa, as well some
<character>
to <string>
conversions. [Note: It might be a good idea to
try making string-to-integer
and
integer-to-string
methods on
as
, which is the usual generic for type
coercions. Ask about this on the GD mailing list.]
as | [Function] |
Convert a character to a string.
Synopsis
as (class, character) => (string)
Parameters
class An instance of singleton(<string>)
.character An instance of <character>
.
Return Values
string An instance of <string>
.
Description
as(<string>, character)
returns a fresh instance of<string>
of size 1, whose only element is the character.
digit-to-integer | [Function] |
Convert a character to the integer it denotes.
Synopsis
digit-to-integer (character) => (integer)
Parameters
character An instance of <character>
. An error is signalled character it is not alphanumeric.
Return Values
integer An instance of <integer>
. Between 0 and 35, inclusive.
Description
Digit-to-integer
converts an alphanumeric character to an integer. '0' through '9' convert to 0 to 9, and 'a' through 'z' convert to 10 to 35. An error is signalled if the character is not in this range.
integer-to-digit | [Function] |
Convert an integer to the corresponding digit.
Synopsis
integer-to-digit (digit, #key base, uppercase) => (digit)
Parameters
digit An instance of <integer>
.base:
An instance of <integer>
. Between 2 and 35, inclusive, representing the radix of the digit to return. The default base is 10.uppercase:
An instance of <boolean>
. For#t
returns uppercase letters for digits greater than 10, and lowercase for#f
. The default is#f
.
Return Values
digit An instance of <character>
. The returned digit is an alphanumeric character.
Description
Integer-to-digit
converts an integer to the corresponding digit in the specified base. If the integer is outside the range a single digit in the specified base can represent, an error is signalled. Digits for values of 10 or higher are represented with the letters 'a' through 'z', with 'a' for 10 and 'z' for 35.
integer-to-string | [Function] |
Converts an integer to a string value.
Synopsis
integer-to-string (num, #key base, uppercase) => (number)
Parameters
num An instance of <integer>
.base:
An instance of <integer>
.Base:
should be between 2 and 36, inclusive, and is the radix of the string representation. An error will be signalled for radixes not in this range. Defaults to10
.uppercase:
An instance of <boolean>
. If it is#t
, then uppercase letters will be used to represent digits higher than 9, and lowercase will be used if#f
.
Return Values
number An instance of <string>
.
Description
Integer-to-string
converts an integer to a string. String representations for radixes above 10 use the letters 'a' through 'z' for the digits from 10 to 35. So hexadecimal numbers would use [0-9] and [a-f], and base 20 would use [0-9] and [a-j], and base 36 would use all the alphanumeric characters.
string-to-integer | [Function] |
Read a sequence of characters as an integer.
Synopsis
string-to-integer (string, #key base) => (integer)
Parameters
string An instance of <sequence>
. Any<sequence>
of<character>
objects are acceptable. This is typically but not necessarily a<string>
.base:
An instance of <integer>
. Between 2 and 36, inclusive, denoting the base to read integers in. An error is signalled if base is not in this range. Defaults to10
.
Return Values
integer An instance of <integer>
.
Description
String-to-integer
converts a sequence of<character>
objects to an integer. The characters are the digits of the string representation, and must lie between '0' and 'z', with a maximum depending on the base. For example, octal (base 8) digits must be in [0-7], decimal digits must be in [0-9], and hexadecimal digits must be in [0-9] or [a-f]. An error is signalled if this constraint is violated. (Start negative integers with a '-', so "-36" would become -36.)