Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/language/traps should warn against using [Z] to get the transpose of a list-of-lists #1400

Closed
smls opened this issue Jun 30, 2017 · 3 comments
Labels
docs Documentation issue (primary issue type)

Comments

@smls
Copy link
Contributor

smls commented Jun 30, 2017

Every now and then, someone gets they idea that they can use [Z] to create the transpose of a list-of-lists:

my @matrix = <X Y>, <a b>, <1 2>;
my @transpose = [Z] @matrix;

say @transpose;  # [(X a 1) (Y b 2)] -- so far so good

And everything works fine... until you get an input @matrix with exactly one row (child list):

my @matrix = <X Y>,;
my @transpose = [Z] @matrix;

say @transpose;  # [(X Y)] -- not the expected transpose [(X) (Y)]

I've explained the cause of this surprising edge-case behavior, which basically ruins [Z] for variable-size inputs, in this SO answer (which should be easy to understand without also having to read the associated SO question).

I think this has all the markings of a trap:

  • The syntax is simple (so people will continue to "discover" it), and elegant (so they'll be happy to use it).
  • It's quite sensible to expect, on first sight, that it will do the right thing.
  • It does in fact do the right thing for most inputs, meaning that it might slip through unit tests etc.

Thus, I think the Perl 6 documentation should mention it in its "Traps to avoid" document.

@smls smls added the docs Documentation issue (primary issue type) label Jun 30, 2017
@AlexDaniel
Copy link
Member

FWIW, we now have this ticket: https://rt.perl.org/Ticket/Display.html?id=131686

@AlexDaniel
Copy link
Member

Another interesting ticket (although maybe unrelated): rakudo/rakudo#1210

@AlexDaniel
Copy link
Member

I think this is now resolved in 6519ef5. I copied some parts of your OP here, let me know if that's a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation issue (primary issue type)
Projects
None yet
Development

No branches or pull requests

2 participants