From 6b40554c9dca2a0a75d62f76300a5b5a2b8d3820 Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Tue, 7 Nov 2023 19:30:40 -0800 Subject: [PATCH] document leo tuples --- documentation/leo/03_language.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/documentation/leo/03_language.md b/documentation/leo/03_language.md index 5e7f41ad9..837c3c01e 100644 --- a/documentation/leo/03_language.md +++ b/documentation/leo/03_language.md @@ -278,7 +278,7 @@ record token { ### Array -Leo supports static arrays. Arrays are declared as `[type; length]`. Arrays cannot be empty nor modified. +Leo supports static arrays. Arrays are declared as `[type; length]` and can be nested. Arrays cannot be empty nor modified. Arrays only support constant accesses (the index must be a constant value). The accessor value must be a constant integer. @@ -329,6 +329,24 @@ transition sum_with_loop(a: [u64; 4]) -> u64 { } ``` +### Tuple + +Leo supports tuples. Tuples are declared as `(type1, type2, ...)` and can be nested. Tuples cannot be empty nor modified. + +Tuples only support constant access with a dot `.` and a constant integer. + +Tuples can contain primitive data types, structs, or arrays. Structs and records can also contain tuples. + +```leo +program test.aleo { + transition baz(foo: u8, bar: u8) -> u8 { + let a: (u8, u8) = (foo, bar); + let result: u8 = a.0 + a.1; + return result; + } +} +``` + ### Transition Function Transition functions in Leo are declared as `transition {name}() {}`.