Menu

#32 let (x,y) = ...

open
nobody
None
5
2005-02-23
2005-02-16
No

Make access to tupple contents easier. I believe Groovy
has this feature:

Taken from manual.html:Example 7.2. Method returning
several values using a tuple

#1 usage improvement: allow local variables on tupple
returns:

declaration:
(int, int) minMax(int x, int y) = x < y ? (x, y) : (y, x);
use:
(x, y) = minMax(3,5); // not very convincing for this
function.
println("(" + x + ", " + y + ")");

#2 usage improvement: allow local variables on tupple
arguments:
void printTuple((int x, int y) tuple)
{
// /** Declare two local variables, and assign to each
the //corresponding value
// in the tuple.
// */
// (int x, int y) = tuple;

println("(" + x + ", " + y + ")");
}

Discussion

  • Daniel Bonniot

    Daniel Bonniot - 2005-02-22
    • summary: Tupple usage --> Tuple usage
     
  • Daniel Bonniot

    Daniel Bonniot - 2005-02-22

    Logged In: YES
    user_id=88952

    I'd like to ask for some clarifications:

    For #1:
    You can already do
    (x, y) = minMax(3,5);
    provided that x and y are previously declared. You can also
    declared them at that spot with:
    (int x, int y) = minMax(3,5);

    Is that you want to be able to declare them without
    specifying the type? I believe this could be useful, but a
    specific syntax should be used to make that clear.
    Consistently, this should be
    let (x, y) = minMax(3,5);
    and
    var (x, y) = minMax(3,5);
    for constant and variables, respectively.

    Does this correspond to what you expected?

    For #2:
    Unless I'm mistaken, what you are asking for is already
    possible:
    void printTuple((int x, int y) tuple)

    You can even leave the name 'tuple' out since it is not used:
    void printTuple((int x, int y))

    Is that so? Is this missing from the documentation?

     
  • Nobody/Anonymous

    Logged In: NO

    My misunderstanding. - From your reply, the current usage
    is fine.

    However, example 7.2 in the User's Manual is misleading as
    it fails to use feature #2. It should be updated, or shown
    as an alternative.

     
  • Daniel Bonniot

    Daniel Bonniot - 2005-02-23
    • summary: Tuple usage --> let (x,y) = ...
     
  • Daniel Bonniot

    Daniel Bonniot - 2005-02-23

    Logged In: YES
    user_id=88952

    OK, I updated the manual accordingly.

    I leave this report open, as I believe it would be useful to
    support the 'let (x,y) = ...' syntax.

     

Log in to post a comment.

MongoDB Logo MongoDB