-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTuples.t2t
48 lines (37 loc) · 1.41 KB
/
Tuples.t2t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Tuples
%!includeconf: config.t2t
== Introduction ==
Tuples are a core part of the language syntax as they are used for argument
passing and returning. Tuples are temporary grouping of elements. Tuples can't
be stored they can only be packed or unpacked. The syntax for a tuple is a set
of values seperated by comas. Paranthises can be used to control where tuples
begin and end. It is often benificial to surround the tuple with paranthies
even if not nessary to promote clarity.
```
1, 2, 3; // A tuple.
1, "one", 1.0; // Tuples can contain any types.
(1, 2, 3, 4,); // A trailing comma is allowed.
```
== Unpacking ==
The assignment operator (``=``) is used for unpacking tuples. It unpacks the
values from the right tuple into the variables in the laft tuple. The right
side is evaluated before the left side. If a value is to be discarded just
don't put a variable name. All extra values on the right side are ignored.
```
var a, b, c, d;
a, b = 3, 4;
assert( a == 3 && b = 4 );
c, d = a, b;
assert( c == 3 && d = 4 );
a, b = b, a; // Flip the values.
assert( a == 4 && b = 3 );
,,a = 1,2,3,4;
assert( a == 3 );
```
== Tuple Nesting ==
Because tuples can not be stored there is no use of a tuple inside of a tuple.
Pool simply drops all elemets other than the first. This is because commonly
you just want the first return value.
```
assert (0,1,2,3,4) == ((0),1,2,(3,(-1,-1,-1),(-1,-1)),(((4),-1, -1), -1));
```