Bretheren and Sisteren .. I'm trying to understand the "for <ZIP syntax> -> (param)" syntax in perl6, using pugs Version: 6.2.13, on Windows. I'm getting confusing results - I cannot tell if this is a pugs issue, or a perl6 syntax problem, documentation problem, or (most likely) my brain malfunction. Given:
my @names = ('Jack', 'Emma', 'Robert'); my @ages = (20, 19, 35);
I'm trying to print them in NAME, AGE pairs.
Here is my code with results from pugs:
pugs> for zip(@names; @ages) -> [ $name, $age ] {say " $name is $age +years old"} Internal error while running expression: *** Unexpected "[" expecting subroutine parameters, trait or block at <interactive> line 1, column 27
This (to me) seems like the documentation on the pugs website is wrong. So I try something different - remove the brackets:
pugs> for zip(@names; @ages) -> $name, $age {say " $name is $age ol +d"} Jack 20 is Emma 19 old Robert 35 is old undef
OK - that does run, but seems to mix up the 2 entities into a single variable, probably a array-ref.
pugs> for zip(@names; @ages) -> $name, $age {say " $name.[0] is $ +name[1] old; while $age.[0] may be $age [1]"} Jack is 20 old; while Emma may be 19 Robert is 35 old; while may be undef
OK - making SOME progress above - at least I extracted all the data. Still, it did not put info into the parameters in a manner I would like.
pugs> for zip(@names; @ages) -> @_ {say " @_[0] is @_[1] years old +;"} Jack is 20 years old; Emma is 19 years old; Robert is 35 years old;
OK !! That worked perfectly. But - I would like to use NAMED variables, not @_. None of the attempts below do what I want:
pugs> for zip(@names; @ages) -> ($n,$a) {say " $n is $a old; "} Jack 20 is Emma 19 old; Robert 35 is old; undef pugs> for @names Z @ages -> ($n,$a) {say " $n is $a old; "} Jack 20 is Emma 19 old; Robert 35 is old; undef pugs> for @names Z @ages -> ($n;$a) {say " $n is $a old; "} Jack 20 is Emma 19 old; Robert 35 is old; undef pugs> for @names Z @ages -> $n,$a {say " $n is $a old; "} Jack 20 is Emma 19 old; Robert 35 is old; undef pugs> for @names Z @ages -> $n;$a {say " $n is $a old; "} Jack 20 is Emma 19 old; Robert 35 is old; undef
Could a fellow monk point me in the right direction - where can I RTFM on syntax related to this, and how should I do this ?

     "As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom


In reply to perl6/pugs zip + for + subroutine params by NetWallah

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.