REBOL Document

To - Function Summary


Summary:

Constructs and returns a new value after conversion.

Usage:

to type spec

Arguments:

type - The datatype or example value. (must be: any-type)

spec - The attributes of the new value. (must be: any-type)

Description:

Every datatype provides a TO method to allow conversions from other datatypes. The to-binary, to-block, and all other to- functions are mezzanine functions that are based on this TO function.

Here are a few examples:


 probe to file! "test.r"
 %test.r


 probe to list! [1 2 3]
 make list! [1 2 3]

The TO function lets the target datatype be specified as an argument, allowing you to write code such as:


 flag: true
 value: to either flag [integer!][decimal!] 123
 print value
 123

The conversions that are allowed depend on the specific datatype. Some datatypes allow special conversions, such as:


 print to integer! false
 0


 print to integer! true
 1


 print to logic! 1
 true


 print to time! 600 ; # of seconds
 0:10

Related:

make - Constructs and returns a new value.

AltStyle によって変換されたページ (->オリジナル) /