Skip to content

Using Tuples

NN--- edited this page Apr 11, 2012 · 5 revisions

Using Tuples

  • Category: Lists, Tuples and Options
  • Description: This sample shows simple uses of tuples
  • Code:
using System;
using System.Console;
using Nemerle;

def data = (1, 2, 3); // type od "data": int * int * int
WriteLine($"data = $data");
def f(a, b, c)  { (a + b, b + c, c + a) } // function type: int * int * int -> int * int * int
    
def result = f(f(f(data))); // pass tuple as function arguments
WriteLine($"result = $result");
def (r1, r2, r3) = result;
WriteLine($"r1 = $r1, r2 = $r2, r3 = $r3");
def (r4, r5, r6) = f(result);
WriteLine($"r4 = $r4, r5 = $r5, r6 = $r6")
  • Execution Result:
data = (1, 2, 3)
result = (17, 16, 15)
r1 = 17, r2 = 16, r3 = 15
r4 = 33, r5 = 31, r6 = 32

[Copyright ©](Terms of use, legal notice)

Clone this wiki locally