REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 6-Feb-2010 Edit History  

REBOL 3 Datatypes: Tuple!

Contents

Concept

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 1.0.2.32     ; version
199.4.80.250 255.255.255.0 ; net addresses/masks
0.80.255 200.200.60        ; RGB colors

Format

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!

Creation

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

Related

Use tuple? to determine whether a value is a tuple! datatype.

probe tuple? 1.2.3.4
true

Use the form function to print a tuple as a string:

probe form 1.2.3.4
1.2.3.4

Use the mold function to convert a tuple into a string that can be read back into REBOL as a tuple:

probe mold 1.2.3.4
1.2.3.4

Use the print function to print a tuple to standard output after using the reform function:

print 1.2.3.4
1.2.3.4

Auto Clipping

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