Coerces an object to a type. That is, it returns an instance of type that has the same contents as object. If object is already an instance of type, it is returned unchanged. In general, the value returned may or may not be freshly allocated.
Predefined methods allow coercion between integers and characters, between strings and symbols, and between collection types. No methods are predefined for other classes. Programs may define additional methods.
open
| type | An instance of <type>. |
| object | An instance of <object>. |
| instance | An instance of <object>. |
Coerces an object to a type. | |
as is defined for <sequence>s. | |
This method on <integer>, <character> returns a numeric equivalent for the character. | |
This method on <character>, <integer> returns the character equivalent of the integer. | |
This method on as returns the symbol that has the name string. | |
This method on as returns the name of the symbol, which will be a string. | |
The method on <string>, <character> creates a string of length 1, containing the character. |
as is defined for <sequence>s. When converting between collection types, the return value will have the same number of elements as collection. If the collection is an instance of <sequence> and the collection-type is a subtype of <sequence>, the elements will be in the same order. The individual elements may also undergo some conversion.
| collection-type | An instance of <type>. |
| collection | An instance of <sequence>. |
| instance-of-collection-type | An instance of collection-type. |
This method on <integer>, <character> returns a numeric equivalent for the character. The integer returned is implementation dependent.
| type | An instance of singleton(<integer>). |
| character | An instance of <character>. |
| integer | An instance of <integer>. |
This method on <character>, <integer> returns the character equivalent of the integer.
| type | An instance of singleton(<character>). |
| integer | An instance of <integer>. |
| character | An instance of <character>. |
This method on as returns the symbol that has the name string. If the symbol does not yet exist, it is created. This method on as will always return the same symbol for strings of the same characters, without regard to alphabetic case.
as(<symbol>, "foo")
⇒ #"foo"
#"FOO" == as(<symbol>, "foo")
⇒ #t
#"Foo"
⇒ #"foo"
| type | An instance of singleton(<symbol>). |
| string | An instance of <string>. |
| symbol | An instance of <symbol>. |
The method on <string>, <character> creates a string of length 1, containing the character.