What is a tuple literal?

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
pemo18
Posts: 76
Joined: Fri Apr 27, 2018 10:38 am
Location: Germany

What is a tuple literal?

Post by pemo18 »

Hello X#-Team,

This is more out of curiosity but it could also be interesting for other X# developers.

What is a tuple literal? I asume from the help file and by experimenting with it that X# supports Tuples like in C# but I have no clue how to instantiate one. The help file is mentioning that I would have to use a tuple literal.

Tuples could be an alternative when a method shall return more than one value. I would prefer tuples over ref parameters.

May be its worth mentioning in the X# language talk tomorrow.

Kind regards,
Peter
User avatar
Chris
Posts: 4593
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

What is a tuple literal?

Post by Chris »

Hi Peter,

Is this really mentioned in the help? Where? I might be missing something, but I do not think this is implemented yet, but Robert may need to correct me of course! (Here or in an online session :) )

A tuple literal is something like this:

VAR oMyTuple := (1,"abc")

which creates a tuple with two generic parameters, an INT and a STRING and assigns their values. I think we have decided that this is the syntax that will be used in X# as well (same to c#).
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
pemo18
Posts: 76
Joined: Fri Apr 27, 2018 10:38 am
Location: Germany

What is a tuple literal?

Post by pemo18 »

Hi Robert,

It was a false alarm. The System.Tuple class was only used as an example for being able to use >> for declaring generics in the section Changes in 0.2.2.

And there are several error mesages like XS8138 that states "use the tuple syntax to define tuple names" etc.

What striked me was error XS8181 - 'new' cannot be used with tuple type. Use a tuple literal expression instead.

But thats ok. It would be definitely a helpful feature in a future release.

Regards,
Peter
FFF
Posts: 1535
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

What is a tuple literal?

Post by FFF »

Chris wrote:VAR oMyTuple := (1,"abc")
which creates a tuple with two generic parameters, an INT and a STRING and assigns their values. I think we have decided that this is the syntax that will be used in X# as well (same to c#).
While in curiosity mode: I read that you may at max set 8 params in a tuple. And "the main purpose of tuples is to safely return multiple values from a method without resorting to out parameters".
In what differs this from a crippled Vo-style array?
EDIT: did further reading, ok, there's quite more behind ;) main difference being tuples "value type" with mutable elements - makes me wonder, what trickery they do behind the scenes to make this work...
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
User avatar
Chris
Posts: 4593
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

What is a tuple literal?

Post by Chris »

Hi Karl,

I would say that the main difference is that the tuple parameters are strongly typed and the length of the parameters is known at compile time and they can even have "names". So you cannot access by mistake an element of the VO array that does not exit, or is of the wrong type (because of a mistake in the element number) etc.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
Post Reply