|REBOL 3 Docs||Guide||Concepts||Functions||Datatypes||Errors|
|TOC < Back Next >||Updated: 6-Feb-2010 Edit History|
It is common to represent version numbers, Internet addresses, and RGB color values as a sequence of three or four integers. These types of numbers are called a tuple! (as in quintuple) and are represented as a set of integers separated by periods.
1.3.0 2.1.120 220.127.116.11 ; version 18.104.22.168 255.255.255.0 ; net addresses/masks 0.80.255 200.200.60 ; RGB colors
Each integer field of a tuple! datatype can range between 0 and 255. Negative integers produce an error.
Three to ten integers can be specified in a tuple. In the case where only two integers are given, there must be at least two periods, otherwise the value is treated as a decimal.
probe 1.2 ; is decimal 1.2
probe type? 1.2 decimal!
probe 1.2.3 ; is tuple 1.2.3
probe 1.2. ; is tuple 1.2.0
probe type? 1.2. tuple!
Use the to-tuple function to convert data to the tuple! datatype:
probe to-tuple "12.34.56" 12.34.56
probe to-tuple [12 34 56] 12.34.56
Use tuple? to determine whether a value is a tuple! datatype.
probe tuple? 22.214.171.124 true
Use the form function to print a tuple as a string:
probe form 126.96.36.199 188.8.131.52
Use the mold function to convert a tuple into a string that can be read back into REBOL as a tuple:
probe mold 184.108.40.206 220.127.116.11
Use the print function to print a tuple to standard output after using the reform function:
print 18.104.22.168 22.214.171.124
During math operations, elements of a tuple will clip at 0 and 255. This is done to make math easier for common tuple operations such generating as color values.
print navy 0.0.128
print navy * 2 0.0.255
print gray 128.128.128
print gray + green 128.255.128
|TOC < Back Next >||REBOL.com - WIP Wiki||Feedback Admin|