📖
Rede Language Design
  • Overview
    • Introduction
    • Scope
    • Terms and Definitions
  • Annexes
    • Annex A - Complete Grammar
    • Annex B - Symbols and Keywords
    • Annex C - Code Examples
      • Behaviors
      • Comments
      • Crashes
      • Data Types
        • Built-in Types
          • Context Collections
            • Buckets
            • Compositions
              • Registrations
              • Deregistrations
            • Operables
          • Primitives
          • Value Collections
            • Arrays
            • Dictionaries
            • Lists
            • Sets
            • Tuples
        • Custom Types
      • Evaluation
      • Mappings
      • Meta
      • Operations
        • Groups
      • Patterns
    • Annex D - Program Examples
      • Hello World
      • FizzBuzz
      • Fibonacci
      • Shape Drawing
      • Deserialization
      • Serialization
Powered by GitBook
On this page
  • Type Declaration
  • Accessing
  • Retrieving
  • Setting
  • Operators
  • Count
  • Difference (by Type Matching)
  • Equality
  • Intersection (by Type Matching)
  • Union
  1. Annexes
  2. Annex C - Code Examples
  3. Data Types
  4. Built-in Types
  5. Value Collections

Tuples

The following code examples demonstrate the built-in tuple type offered by the language. See section [TBD] for details.

Type Declaration

Tuple Name: {Int, Int, Bool}.
Tuple Name: {Int*2*, Bool}.

Accessing

Retrieving

some tuple: {Int, Int, Bool} [1, 2, false];
some tuple (0) = 1
some tuple: {Int, Int, Bool} [1, 2, false];
some tuple (0, 2) = {1, false}
some tuple: {Int, Int, Bool} [1, 2, false];
some tuple (-1) = {false}
some tuple: {Int, Int, Bool} [1, 2, false];
some tuple !(0) = {2, false}
some tuple: {Int, Int, Bool} [1, 2, false];
some tuple (...) = {1, 2, 3}  `Total collection accessor.`
some tuple: {Int, Int, Bool} [1, 2, false];
some tuple ((0, 2]) = {2, false}
some tuple: {Int, Int, Bool} [1, 2, false];
some tuple !((0, 2]) = {1}

Setting

some tuple (0) is 1,
some tuple (0, 2) is {1, true},
some tuple ([0, 2]) is {1, 3, true}, `Range must be within the Tuple's bounds.`

Operators

Count

|{1, 2, false}| = 3
|some tuple| = 5

Difference (by Type Matching)

{1, 2, false} - {3, true} = {2}
{2, 3, 4, 5} - {1, 2} = {4, 5}

Equality

Setup

`Assume the following for all equality code examples.`

some tuple: {Int, Int, Bool} [1, 2, false];

Approximate

other tuple: {Bool, Int, Int} [false, 1, 2];
some tuple ~ other tuple

Collective

{1, 1} &= 1  `All elements match the right-side element(s).`
{1, 2, 2, 1} &= {1, 2}
{true, true} &= true
{false, false} &= false
someTuple |= 1  `At least one element matches the right-side element(s).`
someTuple |= {1, true}
{true, false, 0} |= true
{true, 1, false} |= false

Strict

some tuple = {1, 2, false}
some tuple = {1, 2, ...}  `Match remaining values.`

Intersection (by Type Matching)

{1, 2, false} % {2, 3, 4, 5} = {1, 2}
{2, 3, 4, 5} % {1, 2, 3, 3} = {2, 3, 4, 5}

Union

{1, 2} + {2, false, 3} = {1, 2, 2, false, 3}
{2, 3} + {1, 2, true} = {2, 3, 1, 2, true}
PreviousSetsNextCustom Types

Last updated 1 year ago