Tuples

Tuples are a group of one or more data. They form the foundation of all value passing in Wolf.

Construction

Tuples are constructed by enclosing data in parentheses ( ). Data is separated by either commas , or newlines.

("hello", "world", 2025)

(
	1, 2, 3
	4, 5, 6
	7, 8, 9
)

Empty tuples are also allowed. Conceptually, they contain no data.

()

Single-value tuples

Wolf can automatically convert between single-value tuples of any depth. This includes getting rid of all tuples, wrapping a value in a tuple.

2
(2)
((2))
(((2)))

This is only done in limited situations where there’s a clear conversion to be made.

As a result, a tuple with a single value can be used to rearrange computation order.

-- The tuple evaluates to 8, then is multiplied by 2.
2 * (5 + 3)

Named data

By default, data in tuples is named automatically by position, starting with 0 for the first datum, 1 for the second datum, etc.

(
	2015 -- named `0`
	5    -- named `1`
	15   -- named `2`
)

You can explicitly provide names by putting a dot-prefixed name before the data.

(
	.year  2015 -- named `year`
	.month 5    -- named `month`
	.day   15   -- named `day`
)

Names can’t be reused in the same tuple.

-- This is not allowed.
(
	.0 2015, 
	.0 5, 
	.0 15
)

It’s valid to mix explicitly named data with unnamed data. Unnamed data will not consider explicitly named data when assigning automatic names.

Be aware that explicitly named data can still have namespace collisions with automatically named data.

(
	10         -- named `0`
	11         -- named `1`
	.foo "a"   -- named `foo`
	12,        -- named `2`
	.bar "b",  -- named `bar`
	13,        -- named `3`
	14         -- named `4`
)

Accessing data

You can access a datum with the dot . operator, followed by the name of the datum to be accessed.

-- Evaluates to 5.
(3, 5, 7) .1

-- Evaluates to 2015.
(.year 2015, .month 5, .day 15) .year

-- Evaluates to "Bob"
(.name "Bob", .age 25) .name

Nested accesses are written with spaces. This allows dots to be used in names.

-- These are allowed.
(.wolf.phfox.net "hello") .wolf.phfox.net
(.wolf (.phfox (.net "hello"))) .wolf .phfox .net

-- This is not allowed.
(.wolf (.phfox (.net "hello"))).wolf.phfox.net

Flattening

If you’re putting a tuple inside of another tuple, you can flatten its contents by using an ellipsis ... instead of a name.

-- These two expressions are equivalent.
(... (1, 2, 3), 4, 5)
(1, 2, 3, 4, 5)

-- So are these two expressions.
(... (.year 2015, .month 5), .day 15)
(.year 2015, .month 5, .day 15)