fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: What is a tuple literal?

What is a tuple literal? 06 May 2020 15:32 #14390

  • pemo18's Avatar

  • pemo18

  • Topic Author


  • Posts: 35
  • 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

    Please Log in or Create an account to join the conversation.

    Last edit: by pemo18.

    What is a tuple literal? 06 May 2020 17:06 #14396

  • Chris's Avatar

  • Chris


  • Posts: 1957
  • 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#).
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    What is a tuple literal? 06 May 2020 17:36 #14401

  • pemo18's Avatar

  • pemo18

  • Topic Author


  • Posts: 35
  • 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

    Please Log in or Create an account to join the conversation.

    What is a tuple literal? 06 May 2020 17:49 #14403

  • FFF's Avatar

  • FFF


  • Posts: 956
  • 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 (X# 2.5a; Xide 1.25; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    Last edit: by FFF.

    What is a tuple literal? 06 May 2020 18:13 #14408

  • Chris's Avatar

  • Chris


  • Posts: 1957
  • 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.
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1