Help with Perl 6 script

--000000000000211cfc058fa09c83
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Greetings

I have this Perl 6 script from Rosetta, which I wanted to run on Perl 5
(due to the Active Sate Perl and App version that I have). However, several
syntax errors appear given the difference (some) in language.Here's the
script:

---

# Simple Vector implementation
multi infix:<+>(@a, @b) { @a Z+ @b }
multi infix:<->(@a, @b) { @a Z- @b }
multi infix:<*>($r, @a) { $r X* @a }
multi infix:</>(@a, $r) { @a X/ $r }
sub norm { sqrt [+] @_ X** 2 }

# Runge-Kutta stuff
sub runge-kutta(&yp) {
    return -> \t, \y, \=CE=B4t {
        my $a =3D =CE=B4t * yp( t, y );
        my $b =3D =CE=B4t * yp( t + =CE=B4t/2, y + $a/2 );
        my $c =3D =CE=B4t * yp( t + =CE=B4t/2, y + $b/2 );
        my $d =3D =CE=B4t * yp( t + =CE=B4t, y + $c );
        ($a + 2*($b + $c) + $d) / 6;
    }
}

# gravitational constant
constant G =3D 6.674e-11;
# astronomical unit
constant au =3D 150e9;

# time constants in seconds
constant year =3D 365.25*24*60*60;
constant month =3D 21*24*60*60;

# masses in kg
constant $ma =3D 2e30;     # Sun
constant $mb =3D 6e24;     # Earth
constant $mc =3D 7.34e22;  # Moon

my &dABC =3D runge-kutta my &f =3D sub ( $t, @ABC ) {
    my @a =3D @ABC[0..2];
    my @b =3D @ABC[3..5];
    my @c =3D @ABC[6..8];

    my $ab =3D norm(@a - @b);
    my $ac =3D norm(@a - @c);
    my $bc =3D norm(@b - @c);

    return [
        flat
        @ABC[@(9..17)],
        map G * *,
        $mb/$ab**3 * (@b - @a) + $mc/$ac**3 * (@c - @a),
        $ma/$ab**3 * (@a - @b) + $mc/$bc**3 * (@c - @b),
        $ma/$ac**3 * (@a - @c) + $mb/$bc**3 * (@b - @c);
    ];
}

loop (
    my ($t, @ABC) =3D 0,
        0, 0, 0,                                 # Sun position
        au, 0, 0,                                # Earth position
        0.998*au, 0, 0,                          # Moon position
        0, 0, 0,                                 # Sun speed
        0, 2*pi*au/year, 0,                      # Earth speed
        0, 2*pi*(au/year + 0.002*au/month), 0    # Moon speed
    ;
    $t < .2;
    ($t, @ABC) =C2=BB+=3D=C2=AB (.01, dABC($t, @ABC, .01))
) {
    printf "t =3D %.02f : %s\n", $t, @ABC.fmt("%+.3e");
}


---

I'm having problem specially in the "multi infix" and even in the "norm"
sub routine. The problem is that I do not understand the construction of
these in Perl 5 (otherwise, I would translate this easely, and I wouldn't
be asking for help...)

Any help is apreciated.

Clear skies

Rui Fernandes

--000000000000211cfc058fa09c83
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div style=3D"font-size:small" class=3D"gmail_default">Gre=
etings</div><div style=3D"font-size:small" class=3D"gmail_default"><br></di=
v><div style=3D"font-size:small" class=3D"gmail_default">I have this Perl 6=
 script from Rosetta, which I wanted to run on Perl 5 (due to the Active Sa=
te Perl and App version that I have). However, several syntax errors appear=
 given the difference (some) in language.Here&#39;s the script:</div><div s=
tyle=3D"font-size:small" class=3D"gmail_default"><br></div><div style=3D"fo=
nt-size:small" class=3D"gmail_default">---</div><div style=3D"font-size:sma=
ll" class=3D"gmail_default"><br></div><div style=3D"font-size:small" class=
=3D"gmail_default">
<pre class=3D"gmail-perl6 gmail-highlighted_source"><span class=3D"gmail-co=
1"># Simple Vector implementation</span><br><span class=3D"gmail-kw2">multi=
</span> infix<span class=3D"gmail-sy0">:&lt;+&gt;</span><span class=3D"gmai=
l-br0">(</span><span class=3D"gmail-re0">@a</span><span class=3D"gmail-sy0"=
>,</span> <span class=3D"gmail-re0">@b</span><span class=3D"gmail-br0">)</s=
pan> <span class=3D"gmail-br0">{</span> <span class=3D"gmail-re0">@a</span>=
 <span class=3D"gmail-kw1">Z</span><span class=3D"gmail-sy0">+</span> <span=
 class=3D"gmail-re0">@b</span> <span class=3D"gmail-br0">}</span><br><span =
class=3D"gmail-kw2">multi</span> infix<span class=3D"gmail-sy0">:&lt;-&gt;<=
/span><span class=3D"gmail-br0">(</span><span class=3D"gmail-re0">@a</span>=
<span class=3D"gmail-sy0">,</span> <span class=3D"gmail-re0">@b</span><span=
 class=3D"gmail-br0">)</span> <span class=3D"gmail-br0">{</span> <span clas=
s=3D"gmail-re0">@a</span> Z<span class=3D"gmail-sy0">-</span> <span class=
=3D"gmail-re0">@b</span> <span class=3D"gmail-br0">}</span><br><span class=
=3D"gmail-kw2">multi</span> infix<span class=3D"gmail-sy0">:&lt;*&gt;</span=
><span class=3D"gmail-br0">(</span><span class=3D"gmail-re0">$r</span><span=
 class=3D"gmail-sy0">,</span> <span class=3D"gmail-re0">@a</span><span clas=
s=3D"gmail-br0">)</span> <span class=3D"gmail-br0">{</span> <span class=3D"=
gmail-re0">$r</span> <span class=3D"gmail-kw1">X</span><span class=3D"gmail=
-sy0">*</span> <span class=3D"gmail-re0">@a</span> <span class=3D"gmail-br0=
">}</span><br><span class=3D"gmail-kw2">multi</span> infix<span class=3D"gm=
ail-sy0">:&lt;/&gt;</span><span class=3D"gmail-br0">(</span><span class=3D"=
gmail-re0">@a</span><span class=3D"gmail-sy0">,</span> <span class=3D"gmail=
-re0">$r</span><span class=3D"gmail-br0">)</span> <span class=3D"gmail-br0"=
>{</span> <span class=3D"gmail-re0">@a</span> <span class=3D"gmail-kw1">X</=
span><span class=3D"gmail-sy0">/</span> <span class=3D"gmail-re0">$r</span>=
 <span class=3D"gmail-br0">}</span><br><span class=3D"gmail-kw2">sub</span>=
 norm <span class=3D"gmail-br0">{</span> <span class=3D"gmail-kw3">sqrt</sp=
an> <span class=3D"gmail-br0">[</span><span class=3D"gmail-sy0">+</span><sp=
an class=3D"gmail-br0">]</span> <span class=3D"gmail-re0">@_</span> <span c=
lass=3D"gmail-kw1">X</span><span class=3D"gmail-sy0">**</span> <span class=
=3D"gmail-nu0">2</span> <span class=3D"gmail-br0">}</span><br>=C2=A0<br><sp=
an class=3D"gmail-co1"># Runge-Kutta stuff</span><br><span class=3D"gmail-k=
w2">sub</span> runge<span class=3D"gmail-sy0">-</span>kutta<span class=3D"g=
mail-br0">(</span><span class=3D"gmail-re0">&amp;yp</span><span class=3D"gm=
ail-br0">)</span> <span class=3D"gmail-br0">{</span><br>    <span class=3D"=
gmail-kw1">return</span> <span class=3D"gmail-sy0">-&gt;</span> \t<span cla=
ss=3D"gmail-sy0">,</span> \y<span class=3D"gmail-sy0">,</span> \=CE=B4t <sp=
an class=3D"gmail-br0">{</span><br>        <span class=3D"gmail-kw1">my</sp=
an> <span class=3D"gmail-re0">$a</span> <span class=3D"gmail-sy0">=3D</span=
> =CE=B4t <span class=3D"gmail-sy0">*</span> yp<span class=3D"gmail-br0">(<=
/span> t<span class=3D"gmail-sy0">,</span> y <span class=3D"gmail-br0">)</s=
pan><span class=3D"gmail-sy0">;</span><br>        <span class=3D"gmail-kw1"=
>my</span> <span class=3D"gmail-re0">$b</span> <span class=3D"gmail-sy0">=
=3D</span> =CE=B4t <span class=3D"gmail-sy0">*</span> yp<span class=3D"gmai=
l-br0">(</span> t <span class=3D"gmail-sy0">+</span> =CE=B4t<span class=3D"=
gmail-sy0">/</span><span class=3D"gmail-nu0">2</span><span class=3D"gmail-s=
y0">,</span> y <span class=3D"gmail-sy0">+</span> <span class=3D"gmail-re0"=
>$a</span><span class=3D"gmail-sy0">/</span><span class=3D"gmail-nu0">2</sp=
an> <span class=3D"gmail-br0">)</span><span class=3D"gmail-sy0">;</span><br=
>        <span class=3D"gmail-kw1">my</span> <span class=3D"gmail-re0">$c</=
span> <span class=3D"gmail-sy0">=3D</span> =CE=B4t <span class=3D"gmail-sy0=
">*</span> yp<span class=3D"gmail-br0">(</span> t <span class=3D"gmail-sy0"=
>+</span> =CE=B4t<span class=3D"gmail-sy0">/</span><span class=3D"gmail-nu0=
">2</span><span class=3D"gmail-sy0">,</span> y <span class=3D"gmail-sy0">+<=
/span> <span class=3D"gmail-re0">$b</span><span class=3D"gmail-sy0">/</span=
><span class=3D"gmail-nu0">2</span> <span class=3D"gmail-br0">)</span><span=
 class=3D"gmail-sy0">;</span><br>        <span class=3D"gmail-kw1">my</span=
> <span class=3D"gmail-re0">$d</span> <span class=3D"gmail-sy0">=3D</span> =
=CE=B4t <span class=3D"gmail-sy0">*</span> yp<span class=3D"gmail-br0">(</s=
pan> t <span class=3D"gmail-sy0">+</span> =CE=B4t<span class=3D"gmail-sy0">=
,</span> y <span class=3D"gmail-sy0">+</span> <span class=3D"gmail-re0">$c<=
/span> <span class=3D"gmail-br0">)</span><span class=3D"gmail-sy0">;</span>=
<br>        <span class=3D"gmail-br0">(</span><span class=3D"gmail-re0">$a<=
/span> <span class=3D"gmail-sy0">+</span> <span class=3D"gmail-nu0">2</span=
><span class=3D"gmail-sy0">*</span><span class=3D"gmail-br0">(</span><span =
class=3D"gmail-re0">$b</span> <span class=3D"gmail-sy0">+</span> <span clas=
s=3D"gmail-re0">$c</span><span class=3D"gmail-br0">)</span> <span class=3D"=
gmail-sy0">+</span> <span class=3D"gmail-re0">$d</span><span class=3D"gmail=
-br0">)</span> <span class=3D"gmail-sy0">/</span> <span class=3D"gmail-nu0"=
>6</span><span class=3D"gmail-sy0">;</span><br>    <span class=3D"gmail-br0=
">}</span><br><span class=3D"gmail-br0">}</span><br>=C2=A0<br><span class=
=3D"gmail-co1"># gravitational constant</span><br><span class=3D"gmail-kw1"=
>constant</span> G <span class=3D"gmail-sy0">=3D</span> 6<span class=3D"gma=
il-sy0">.</span>674e<span class=3D"gmail-sy0">-</span>11<span class=3D"gmai=
l-sy0">;</span><br><span class=3D"gmail-co1"># astronomical unit</span><br>=
<span class=3D"gmail-kw1">constant</span> au <span class=3D"gmail-sy0">=3D<=
/span> 150e9<span class=3D"gmail-sy0">;</span><br>=C2=A0<br><span class=3D"=
gmail-co1"># time constants in seconds</span><br><span class=3D"gmail-kw1">=
constant</span> year <span class=3D"gmail-sy0">=3D</span> <span class=3D"gm=
ail-nu0">365.25</span><span class=3D"gmail-sy0">*</span><span class=3D"gmai=
l-nu0">24</span><span class=3D"gmail-sy0">*</span><span class=3D"gmail-nu0"=
>60</span><span class=3D"gmail-sy0">*</span><span class=3D"gmail-nu0">60</s=
pan><span class=3D"gmail-sy0">;</span><br><span class=3D"gmail-kw1">constan=
t</span> month <span class=3D"gmail-sy0">=3D</span> <span class=3D"gmail-nu=
0">21</span><span class=3D"gmail-sy0">*</span><span class=3D"gmail-nu0">24<=
/span><span class=3D"gmail-sy0">*</span><span class=3D"gmail-nu0">60</span>=
<span class=3D"gmail-sy0">*</span><span class=3D"gmail-nu0">60</span><span =
class=3D"gmail-sy0">;</span><br>=C2=A0<br><span class=3D"gmail-co1"># masse=
s in kg</span><br><span class=3D"gmail-kw1">constant</span> <span class=3D"=
gmail-re0">$ma</span> <span class=3D"gmail-sy0">=3D</span> 2e30<span class=
=3D"gmail-sy0">;</span>     <span class=3D"gmail-co1"># Sun</span><br><span=
 class=3D"gmail-kw1">constant</span> <span class=3D"gmail-re0">$mb</span> <=
span class=3D"gmail-sy0">=3D</span> 6e24<span class=3D"gmail-sy0">;</span> =
    <span class=3D"gmail-co1"># Earth</span><br><span class=3D"gmail-kw1">c=
onstant</span> <span class=3D"gmail-re0">$mc</span> <span class=3D"gmail-sy=
0">=3D</span> 7<span class=3D"gmail-sy0">.</span>34e22<span class=3D"gmail-=
sy0">;</span>  <span class=3D"gmail-co1"># Moon</span><br>=C2=A0<br><span c=
lass=3D"gmail-kw1">my</span> <span class=3D"gmail-re0">&amp;dABC</span> <sp=
an class=3D"gmail-sy0">=3D</span> runge<span class=3D"gmail-sy0">-</span>ku=
tta <span class=3D"gmail-kw1">my</span> <span class=3D"gmail-re0">&amp;f</s=
pan> <span class=3D"gmail-sy0">=3D</span> <span class=3D"gmail-kw2">sub</sp=
an> <span class=3D"gmail-br0">(</span> <span class=3D"gmail-re0">$t</span><=
span class=3D"gmail-sy0">,</span> <span class=3D"gmail-re0">@ABC</span> <sp=
an class=3D"gmail-br0">)</span> <span class=3D"gmail-br0">{</span><br>    <=
span class=3D"gmail-kw1">my</span> <span class=3D"gmail-re0">@a</span> <spa=
n class=3D"gmail-sy0">=3D</span> <span class=3D"gmail-re0">@ABC</span><span=
 class=3D"gmail-br0">[</span><span class=3D"gmail-nu0">0</span><span class=
=3D"gmail-sy0">..</span><span class=3D"gmail-nu0">2</span><span class=3D"gm=
ail-br0">]</span><span class=3D"gmail-sy0">;</span><br>    <span class=3D"g=
mail-kw1">my</span> <span class=3D"gmail-re0">@b</span> <span class=3D"gmai=
l-sy0">=3D</span> <span class=3D"gmail-re0">@ABC</span><span class=3D"gmail=
-br0">[</span><span class=3D"gmail-nu0">3</span><span class=3D"gmail-sy0">.=
..</span><span class=3D"gmail-nu0">5</span><span class=3D"gmail-br0">]</span=
><span class=3D"gmail-sy0">;</span><br>    <span class=3D"gmail-kw1">my</sp=
an> <span class=3D"gmail-re0">@c</span> <span class=3D"gmail-sy0">=3D</span=
> <span class=3D"gmail-re0">@ABC</span><span class=3D"gmail-br0">[</span><s=
pan class=3D"gmail-nu0">6</span><span class=3D"gmail-sy0">..</span><span cl=
ass=3D"gmail-nu0">8</span><span class=3D"gmail-br0">]</span><span class=3D"=
gmail-sy0">;</span><br>=C2=A0<br>    <span class=3D"gmail-kw1">my</span> <s=
pan class=3D"gmail-re0">$ab</span> <span class=3D"gmail-sy0">=3D</span> nor=
m<span class=3D"gmail-br0">(</span><span class=3D"gmail-re0">@a</span> <spa=
n class=3D"gmail-sy0">-</span> <span class=3D"gmail-re0">@b</span><span cla=
ss=3D"gmail-br0">)</span><span class=3D"gmail-sy0">;</span> <br>    <span c=
lass=3D"gmail-kw1">my</span> <span class=3D"gmail-re0">$ac</span> <span cla=
ss=3D"gmail-sy0">=3D</span> norm<span class=3D"gmail-br0">(</span><span cla=
ss=3D"gmail-re0">@a</span> <span class=3D"gmail-sy0">-</span> <span class=
=3D"gmail-re0">@c</span><span class=3D"gmail-br0">)</span><span class=3D"gm=
ail-sy0">;</span><br>    <span class=3D"gmail-kw1">my</span> <span class=3D=
"gmail-re0">$bc</span> <span class=3D"gmail-sy0">=3D</span> norm<span class=
=3D"gmail-br0">(</span><span class=3D"gmail-re0">@b</span> <span class=3D"g=
mail-sy0">-</span> <span class=3D"gmail-re0">@c</span><span class=3D"gmail-=
br0">)</span><span class=3D"gmail-sy0">;</span><br>=C2=A0<br>    <span clas=
s=3D"gmail-kw1">return</span> <span class=3D"gmail-br0">[</span><br>       =
 flat<br>        <span class=3D"gmail-re0">@ABC</span><span class=3D"gmail-=
br0">[</span><span class=3D"gmail-sy0">@</span><span class=3D"gmail-br0">(<=
/span><span class=3D"gmail-nu0">9</span><span class=3D"gmail-sy0">..</span>=
<span class=3D"gmail-nu0">17</span><span class=3D"gmail-br0">)</span><span =
class=3D"gmail-br0">]</span><span class=3D"gmail-sy0">,</span><br>        <=
span class=3D"gmail-kw3">map</span> G <span class=3D"gmail-sy0">*</span> <s=
pan class=3D"gmail-sy0">*,</span><br>        <span class=3D"gmail-re0">$mb<=
/span><span class=3D"gmail-sy0">/</span><span class=3D"gmail-re0">$ab</span=
><span class=3D"gmail-sy0">**</span><span class=3D"gmail-nu0">3</span> <spa=
n class=3D"gmail-sy0">*</span> <span class=3D"gmail-br0">(</span><span clas=
s=3D"gmail-re0">@b</span> <span class=3D"gmail-sy0">-</span> <span class=3D=
"gmail-re0">@a</span><span class=3D"gmail-br0">)</span> <span class=3D"gmai=
l-sy0">+</span> <span class=3D"gmail-re0">$mc</span><span class=3D"gmail-sy=
0">/</span><span class=3D"gmail-re0">$ac</span><span class=3D"gmail-sy0">**=
</span><span class=3D"gmail-nu0">3</span> <span class=3D"gmail-sy0">*</span=
> <span class=3D"gmail-br0">(</span><span class=3D"gmail-re0">@c</span> <sp=
an class=3D"gmail-sy0">-</span> <span class=3D"gmail-re0">@a</span><span cl=
ass=3D"gmail-br0">)</span><span class=3D"gmail-sy0">,</span><br>        <sp=
an class=3D"gmail-re0">$ma</span><span class=3D"gmail-sy0">/</span><span cl=
ass=3D"gmail-re0">$ab</span><span class=3D"gmail-sy0">**</span><span class=
=3D"gmail-nu0">3</span> <span class=3D"gmail-sy0">*</span> <span class=3D"g=
mail-br0">(</span><span class=3D"gmail-re0">@a</span> <span class=3D"gmail-=
sy0">-</span> <span class=3D"gmail-re0">@b</span><span class=3D"gmail-br0">=
)</span> <span class=3D"gmail-sy0">+</span> <span class=3D"gmail-re0">$mc</=
span><span class=3D"gmail-sy0">/</span><span class=3D"gmail-re0">$bc</span>=
<span class=3D"gmail-sy0">**</span><span class=3D"gmail-nu0">3</span> <span=
 class=3D"gmail-sy0">*</span> <span class=3D"gmail-br0">(</span><span class=
=3D"gmail-re0">@c</span> <span class=3D"gmail-sy0">-</span> <span class=3D"=
gmail-re0">@b</span><span class=3D"gmail-br0">)</span><span class=3D"gmail-=
sy0">,</span><br>        <span class=3D"gmail-re0">$ma</span><span class=3D=
"gmail-sy0">/</span><span class=3D"gmail-re0">$ac</span><span class=3D"gmai=
l-sy0">**</span><span class=3D"gmail-nu0">3</span> <span class=3D"gmail-sy0=
">*</span> <span class=3D"gmail-br0">(</span><span class=3D"gmail-re0">@a</=
span> <span class=3D"gmail-sy0">-</span> <span class=3D"gmail-re0">@c</span=
><span class=3D"gmail-br0">)</span> <span class=3D"gmail-sy0">+</span> <spa=
n class=3D"gmail-re0">$mb</span><span class=3D"gmail-sy0">/</span><span cla=
ss=3D"gmail-re0">$bc</span><span class=3D"gmail-sy0">**</span><span class=
=3D"gmail-nu0">3</span> <span class=3D"gmail-sy0">*</span> <span class=3D"g=
mail-br0">(</span><span class=3D"gmail-re0">@b</span> <span class=3D"gmail-=
sy0">-</span> <span class=3D"gmail-re0">@c</span><span class=3D"gmail-br0">=
)</span><span class=3D"gmail-sy0">;</span><br>    <span class=3D"gmail-br0"=
>]</span><span class=3D"gmail-sy0">;</span><br><span class=3D"gmail-br0">}<=
/span><br>=C2=A0<br><span class=3D"gmail-kw1">loop</span> <span class=3D"gm=
ail-br0">(</span><br>    <span class=3D"gmail-kw1">my</span> <span class=3D=
"gmail-br0">(</span><span class=3D"gmail-re0">$t</span><span class=3D"gmail=
-sy0">,</span> <span class=3D"gmail-re0">@ABC</span><span class=3D"gmail-br=
0">)</span> <span class=3D"gmail-sy0">=3D</span> <span class=3D"gmail-nu0">=
0</span><span class=3D"gmail-sy0">,</span><br>        <span class=3D"gmail-=
nu0">0</span><span class=3D"gmail-sy0">,</span> <span class=3D"gmail-nu0">0=
</span><span class=3D"gmail-sy0">,</span> <span class=3D"gmail-nu0">0</span=
><span class=3D"gmail-sy0">,</span>                                 <span c=
lass=3D"gmail-co1"># Sun position</span><br>        au<span class=3D"gmail-=
sy0">,</span> <span class=3D"gmail-nu0">0</span><span class=3D"gmail-sy0">,=
</span> <span class=3D"gmail-nu0">0</span><span class=3D"gmail-sy0">,</span=
>                                <span class=3D"gmail-co1"># Earth position=
</span><br>        <span class=3D"gmail-nu0">0.998</span><span class=3D"gma=
il-sy0">*</span>au<span class=3D"gmail-sy0">,</span> <span class=3D"gmail-n=
u0">0</span><span class=3D"gmail-sy0">,</span> <span class=3D"gmail-nu0">0<=
/span><span class=3D"gmail-sy0">,</span>                          <span cla=
ss=3D"gmail-co1"># Moon position</span><br>        <span class=3D"gmail-nu0=
">0</span><span class=3D"gmail-sy0">,</span> <span class=3D"gmail-nu0">0</s=
pan><span class=3D"gmail-sy0">,</span> <span class=3D"gmail-nu0">0</span><s=
pan class=3D"gmail-sy0">,</span>                                 <span clas=
s=3D"gmail-co1"># Sun speed</span><br>        <span class=3D"gmail-nu0">0</=
span><span class=3D"gmail-sy0">,</span> <span class=3D"gmail-nu0">2</span><=
span class=3D"gmail-sy0">*</span>pi<span class=3D"gmail-sy0">*</span>au<spa=
n class=3D"gmail-sy0">/</span>year<span class=3D"gmail-sy0">,</span> <span =
class=3D"gmail-nu0">0</span><span class=3D"gmail-sy0">,</span>             =
         <span class=3D"gmail-co1"># Earth speed</span><br>        <span cl=
ass=3D"gmail-nu0">0</span><span class=3D"gmail-sy0">,</span> <span class=3D=
"gmail-nu0">2</span><span class=3D"gmail-sy0">*</span>pi<span class=3D"gmai=
l-sy0">*</span><span class=3D"gmail-br0">(</span>au<span class=3D"gmail-sy0=
">/</span>year <span class=3D"gmail-sy0">+</span> <span class=3D"gmail-nu0"=
>0.002</span><span class=3D"gmail-sy0">*</span>au<span class=3D"gmail-sy0">=
/</span>month<span class=3D"gmail-br0">)</span><span class=3D"gmail-sy0">,<=
/span> <span class=3D"gmail-nu0">0</span>    <span class=3D"gmail-co1"># Mo=
on speed</span><br>    <span class=3D"gmail-sy0">;</span><br>    <span clas=
s=3D"gmail-re0">$t</span> <span class=3D"gmail-sy0">&lt;</span> <span class=
=3D"gmail-sy0">.</span>2<span class=3D"gmail-sy0">;</span><br>    <span cla=
ss=3D"gmail-br0">(</span><span class=3D"gmail-re0">$t</span><span class=3D"=
gmail-sy0">,</span> <span class=3D"gmail-re0">@ABC</span><span class=3D"gma=
il-br0">)</span>=C2=A0=C2=BB<span class=3D"gmail-sy0">+=3D</span>=C2=AB=C2=
=A0<span class=3D"gmail-br0">(</span><span class=3D"gmail-sy0">.</span>01<s=
pan class=3D"gmail-sy0">,</span> dABC<span class=3D"gmail-br0">(</span><spa=
n class=3D"gmail-re0">$t</span><span class=3D"gmail-sy0">,</span> <span cla=
ss=3D"gmail-re0">@ABC</span><span class=3D"gmail-sy0">,</span> <span class=
=3D"gmail-sy0">.</span>01<span class=3D"gmail-br0">)</span><span class=3D"g=
mail-br0">)</span><br><span class=3D"gmail-br0">)</span> <span class=3D"gma=
il-br0">{</span><br>    <span class=3D"gmail-kw3">printf</span> <span class=
=3D"gmail-st0">&quot;t =3D=C2=A0%.02f=C2=A0:=C2=A0%s<span class=3D"es0">\n<=
/span>&quot;</span><span class=3D"gmail-sy0">,</span> <span class=3D"gmail-=
re0">$t</span><span class=3D"gmail-sy0">,</span> <span class=3D"gmail-re0">=
@ABC</span><span class=3D"gmail-sy0">.</span><span class=3D"gmail-kw3">fmt<=
/span><span class=3D"gmail-br0">(</span><span class=3D"gmail-st0">&quot;%+.=
3e&quot;</span><span class=3D"gmail-br0">)</span><span class=3D"gmail-sy0">=
;</span><br><span class=3D"gmail-br0">}</span></pre>

</div><div style=3D"font-size:small" class=3D"gmail_default"><br></div><div=
 style=3D"font-size:small" class=3D"gmail_default">---</div><div style=3D"f=
ont-size:small" class=3D"gmail_default"><br></div><div style=3D"font-size:s=
mall" class=3D"gmail_default">I&#39;m having problem specially in the &quot=
;multi infix&quot; and even in the &quot;norm&quot; sub routine. The proble=
m is that I do not understand the construction of these in Perl 5 (otherwis=
e, I would translate this easely, and I wouldn&#39;t be asking for help...)=
</div><div style=3D"font-size:small" class=3D"gmail_default"><br></div><div=
 style=3D"font-size:small" class=3D"gmail_default">Any help is apreciated.<=
/div><div style=3D"font-size:small" class=3D"gmail_default"><br></div><div =
style=3D"font-size:small" class=3D"gmail_default">Clear skies</div><div sty=
le=3D"font-size:small" class=3D"gmail_default"><br></div><div style=3D"font=
-size:small" class=3D"gmail_default">Rui Fernandes<br></div></div>

--000000000000211cfc058fa09c83--
0
rui
8/8/2019 8:07:29 PM
perl.perl6.users 1235 articles. 0 followers. Follow

7 Replies
43 Views

Similar Articles

[PageSpeed] 28

--_000_BN7PR09MB2594C4BC11FA0E7E353032B9C0D70BN7PR09MB2594namp_
Content-Type: text/plain; charset="iso-8859-7"
Content-Transfer-Encoding: quoted-printable

Yes, Perl 5 and Perl 6 are quite different in many ways.  Some suggested th=
at Perl 6 be looked at as not the next iteration of Perl but a new language=
 that can be made backward compatible with Perl 5 (there are switches etc t=
hat let you run P5 code unchanged) but it is not the case of P5 being able =
to run P6 code.  You'll have to translate what the p6 code is doing into va=
lid syntax for p5.  Or find p6 for windows.  There is a lot of p6 info out =
there, but not so much on the Perl for Beginners list. See:
 https://docs.perl6.org/<https://docs.perl6.org/language/quoting>

and there is the p6 users list
perl6-users@perl.org

at:
https://lists.perl.org/all.html#p

________________________________
From: Rui Fernandes <rui.kepler@gmail.com>
Sent: Thursday, August 8, 2019 3:07 PM
To: Perl Beginners <beginners@perl.org>
Subject: Help with Perl 6 script

Greetings

I have this Perl 6 script from Rosetta, which I wanted to run on Perl 5 (du=
e to the Active Sate Perl and App version that I have). However, several sy=
ntax errors appear given the difference (some) in language.Here's the scrip=
t:

---


# Simple Vector implementation
multi infix:<+>(@a, @b) { @a Z+ @b }
multi infix:<->(@a, @b) { @a Z- @b }
multi infix:<*>($r, @a) { $r X* @a }
multi infix:</>(@a, $r) { @a X/ $r }
sub norm { sqrt [+] @_ X** 2 }

# Runge-Kutta stuff
sub runge-kutta(&yp) {
    return -> \t, \y, \=E4t {
        my $a =3D =E4t * yp( t, y );
        my $b =3D =E4t * yp( t + =E4t/2, y + $a/2 );
        my $c =3D =E4t * yp( t + =E4t/2, y + $b/2 );
        my $d =3D =E4t * yp( t + =E4t, y + $c );
        ($a + 2*($b + $c) + $d) / 6;
    }
}

# gravitational constant
constant G =3D 6.674e-11;
# astronomical unit
constant au =3D 150e9;

# time constants in seconds
constant year =3D 365.25*24*60*60;
constant month =3D 21*24*60*60;

# masses in kg
constant $ma =3D 2e30;     # Sun
constant $mb =3D 6e24;     # Earth
constant $mc =3D 7.34e22;  # Moon

my &dABC =3D runge-kutta my &f =3D sub ( $t, @ABC ) {
    my @a =3D @ABC[0..2];
    my @b =3D @ABC[3..5];
    my @c =3D @ABC[6..8];

    my $ab =3D norm(@a - @b);
    my $ac =3D norm(@a - @c);
    my $bc =3D norm(@b - @c);

    return [
        flat
        @ABC[@(9..17)],
        map G * *,
        $mb/$ab**3 * (@b - @a) + $mc/$ac**3 * (@c - @a),
        $ma/$ab**3 * (@a - @b) + $mc/$bc**3 * (@c - @b),
        $ma/$ac**3 * (@a - @c) + $mb/$bc**3 * (@b - @c);
    ];
}

loop (
    my ($t, @ABC) =3D 0,
        0, 0, 0,                                 # Sun position
        au, 0, 0,                                # Earth position
        0.998*au, 0, 0,                          # Moon position
        0, 0, 0,                                 # Sun speed
        0, 2*pi*au/year, 0,                      # Earth speed
        0, 2*pi*(au/year + 0.002*au/month), 0    # Moon speed
    ;
    $t < .2;
    ($t, @ABC) =BB+=3D=AB (.01, dABC($t, @ABC, .01))
) {
    printf "t =3D %.02f : %s\n", $t, @ABC.fmt("%+.3e");
}

---

I'm having problem specially in the "multi infix" and even in the "norm" su=
b routine. The problem is that I do not understand the construction of thes=
e in Perl 5 (otherwise, I would translate this easely, and I wouldn't be as=
king for help...)

Any help is apreciated.

Clear skies

Rui Fernandes

--_000_BN7PR09MB2594C4BC11FA0E7E353032B9C0D70BN7PR09MB2594namp_
Content-Type: text/html; charset="iso-8859-7"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=
7">
<style type=3D"text/css" style=3D"display:none;"> P {margin-top:0;margin-bo=
ttom:0;} </style>
</head>
<body dir=3D"ltr">
<div style=3D"font-family: &quot;Times New Roman&quot;, Times, serif; font-=
size: 12pt; color: rgb(0, 0, 0);">
Yes, Perl 5 and Perl 6 are quite different in many ways.&nbsp; Some suggest=
ed that Perl 6 be looked at as not the next iteration of Perl but a new lan=
guage that can be made backward compatible with Perl 5 (there are switches =
etc that let you run P5 code unchanged)
 but it is not the case of P5 being able to run P6 code.&nbsp; You'll have =
to translate what the p6 code is doing into valid syntax for p5.&nbsp; Or f=
ind p6 for windows.&nbsp; There is a lot of p6 info out there, but not so m=
uch on the Perl for Beginners list. See:</div>
<div style=3D"font-family: &quot;Times New Roman&quot;, Times, serif; font-=
size: 12pt; color: rgb(0, 0, 0);">
<span style=3D"color: rgb(32, 31, 30); font-family: &quot;Segoe UI&quot;, &=
quot;Segoe UI Web (West European)&quot;, &quot;Segoe UI&quot;, -apple-syste=
m, BlinkMacSystemFont, Roboto, &quot;Helvetica Neue&quot;, sans-serif; font=
-size: 15px; background-color: rgb(255, 255, 255); display: inline !importa=
nt">&nbsp;</span><a href=3D"https://docs.perl6.org/language/quoting" target=
=3D"_blank" rel=3D"noopener noreferrer" style=3D"margin: 0px; font-size: 15=
px; font-family: &quot;Segoe UI&quot;, &quot;Segoe UI Web (West European)&q=
uot;, &quot;Segoe UI&quot;, -apple-system, BlinkMacSystemFont, Roboto, &quo=
t;Helvetica Neue&quot;, sans-serif; background-color: rgb(255, 255, 255)">h=
ttps://docs.perl6.org/</a><br>
</div>
<div style=3D"font-family: &quot;Times New Roman&quot;, Times, serif; font-=
size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style=3D"font-family: &quot;Times New Roman&quot;, Times, serif; font-=
size: 12pt; color: rgb(0, 0, 0);">
and there is the p6 users list</div>
<div style=3D"font-family: &quot;Times New Roman&quot;, Times, serif; font-=
size: 12pt; color: rgb(0, 0, 0);">
perl6-users@perl.org<br>
</div>
<div style=3D"font-family: &quot;Times New Roman&quot;, Times, serif; font-=
size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style=3D"font-family: &quot;Times New Roman&quot;, Times, serif; font-=
size: 12pt; color: rgb(0, 0, 0);">
at:</div>
<div style=3D"font-family: &quot;Times New Roman&quot;, Times, serif; font-=
size: 12pt; color: rgb(0, 0, 0);">
<a href=3D"https://lists.perl.org/all.html#p">https://lists.perl.org/all.ht=
ml#p</a><br>
</div>
<div style=3D"font-family: &quot;Times New Roman&quot;, Times, serif; font-=
size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id=3D"appendonsend"></div>
<hr style=3D"display:inline-block;width:98%" tabindex=3D"-1">
<div id=3D"divRplyFwdMsg" dir=3D"ltr"><font face=3D"Calibri, sans-serif" st=
yle=3D"font-size:11pt" color=3D"#000000"><b>From:</b> Rui Fernandes &lt;rui=
..kepler@gmail.com&gt;<br>
<b>Sent:</b> Thursday, August 8, 2019 3:07 PM<br>
<b>To:</b> Perl Beginners &lt;beginners@perl.org&gt;<br>
<b>Subject:</b> Help with Perl 6 script</font>
<div>&nbsp;</div>
</div>
<div>
<div dir=3D"ltr">
<div class=3D"x_gmail_default" style=3D"font-size:small">Greetings</div>
<div class=3D"x_gmail_default" style=3D"font-size:small"><br>
</div>
<div class=3D"x_gmail_default" style=3D"font-size:small">I have this Perl 6=
 script from Rosetta, which I wanted to run on Perl 5 (due to the Active Sa=
te Perl and App version that I have). However, several syntax errors appear=
 given the difference (some) in language.Here's
 the script:</div>
<div class=3D"x_gmail_default" style=3D"font-size:small"><br>
</div>
<div class=3D"x_gmail_default" style=3D"font-size:small">---</div>
<div class=3D"x_gmail_default" style=3D"font-size:small"><br>
</div>
<div class=3D"x_gmail_default" style=3D"font-size:small">
<pre class=3D"x_gmail-perl6 x_gmail-highlighted_source"><span class=3D"x_gm=
ail-co1"># Simple Vector implementation</span><br><span class=3D"x_gmail-kw=
2">multi</span> infix<span class=3D"x_gmail-sy0">:&lt;&#43;&gt;</span><span=
 class=3D"x_gmail-br0">(</span><span class=3D"x_gmail-re0">@a</span><span c=
lass=3D"x_gmail-sy0">,</span> <span class=3D"x_gmail-re0">@b</span><span cl=
ass=3D"x_gmail-br0">)</span> <span class=3D"x_gmail-br0">{</span> <span cla=
ss=3D"x_gmail-re0">@a</span> <span class=3D"x_gmail-kw1">Z</span><span clas=
s=3D"x_gmail-sy0">&#43;</span> <span class=3D"x_gmail-re0">@b</span> <span =
class=3D"x_gmail-br0">}</span><br><span class=3D"x_gmail-kw2">multi</span> =
infix<span class=3D"x_gmail-sy0">:&lt;-&gt;</span><span class=3D"x_gmail-br=
0">(</span><span class=3D"x_gmail-re0">@a</span><span class=3D"x_gmail-sy0"=
>,</span> <span class=3D"x_gmail-re0">@b</span><span class=3D"x_gmail-br0">=
)</span> <span class=3D"x_gmail-br0">{</span> <span class=3D"x_gmail-re0">@=
a</span> Z<span class=3D"x_gmail-sy0">-</span> <span class=3D"x_gmail-re0">=
@b</span> <span class=3D"x_gmail-br0">}</span><br><span class=3D"x_gmail-kw=
2">multi</span> infix<span class=3D"x_gmail-sy0">:&lt;*&gt;</span><span cla=
ss=3D"x_gmail-br0">(</span><span class=3D"x_gmail-re0">$r</span><span class=
=3D"x_gmail-sy0">,</span> <span class=3D"x_gmail-re0">@a</span><span class=
=3D"x_gmail-br0">)</span> <span class=3D"x_gmail-br0">{</span> <span class=
=3D"x_gmail-re0">$r</span> <span class=3D"x_gmail-kw1">X</span><span class=
=3D"x_gmail-sy0">*</span> <span class=3D"x_gmail-re0">@a</span> <span class=
=3D"x_gmail-br0">}</span><br><span class=3D"x_gmail-kw2">multi</span> infix=
<span class=3D"x_gmail-sy0">:&lt;/&gt;</span><span class=3D"x_gmail-br0">(<=
/span><span class=3D"x_gmail-re0">@a</span><span class=3D"x_gmail-sy0">,</s=
pan> <span class=3D"x_gmail-re0">$r</span><span class=3D"x_gmail-br0">)</sp=
an> <span class=3D"x_gmail-br0">{</span> <span class=3D"x_gmail-re0">@a</sp=
an> <span class=3D"x_gmail-kw1">X</span><span class=3D"x_gmail-sy0">/</span=
> <span class=3D"x_gmail-re0">$r</span> <span class=3D"x_gmail-br0">}</span=
><br><span class=3D"x_gmail-kw2">sub</span> norm <span class=3D"x_gmail-br0=
">{</span> <span class=3D"x_gmail-kw3">sqrt</span> <span class=3D"x_gmail-b=
r0">[</span><span class=3D"x_gmail-sy0">&#43;</span><span class=3D"x_gmail-=
br0">]</span> <span class=3D"x_gmail-re0">@_</span> <span class=3D"x_gmail-=
kw1">X</span><span class=3D"x_gmail-sy0">**</span> <span class=3D"x_gmail-n=
u0">2</span> <span class=3D"x_gmail-br0">}</span><br>&nbsp;<br><span class=
=3D"x_gmail-co1"># Runge-Kutta stuff</span><br><span class=3D"x_gmail-kw2">=
sub</span> runge<span class=3D"x_gmail-sy0">-</span>kutta<span class=3D"x_g=
mail-br0">(</span><span class=3D"x_gmail-re0">&amp;yp</span><span class=3D"=
x_gmail-br0">)</span> <span class=3D"x_gmail-br0">{</span><br>    <span cla=
ss=3D"x_gmail-kw1">return</span> <span class=3D"x_gmail-sy0">-&gt;</span> \=
t<span class=3D"x_gmail-sy0">,</span> \y<span class=3D"x_gmail-sy0">,</span=
> \=E4t <span class=3D"x_gmail-br0">{</span><br>        <span class=3D"x_gm=
ail-kw1">my</span> <span class=3D"x_gmail-re0">$a</span> <span class=3D"x_g=
mail-sy0">=3D</span> =E4t <span class=3D"x_gmail-sy0">*</span> yp<span clas=
s=3D"x_gmail-br0">(</span> t<span class=3D"x_gmail-sy0">,</span> y <span cl=
ass=3D"x_gmail-br0">)</span><span class=3D"x_gmail-sy0">;</span><br>       =
 <span class=3D"x_gmail-kw1">my</span> <span class=3D"x_gmail-re0">$b</span=
> <span class=3D"x_gmail-sy0">=3D</span> =E4t <span class=3D"x_gmail-sy0">*=
</span> yp<span class=3D"x_gmail-br0">(</span> t <span class=3D"x_gmail-sy0=
">&#43;</span> =E4t<span class=3D"x_gmail-sy0">/</span><span class=3D"x_gma=
il-nu0">2</span><span class=3D"x_gmail-sy0">,</span> y <span class=3D"x_gma=
il-sy0">&#43;</span> <span class=3D"x_gmail-re0">$a</span><span class=3D"x_=
gmail-sy0">/</span><span class=3D"x_gmail-nu0">2</span> <span class=3D"x_gm=
ail-br0">)</span><span class=3D"x_gmail-sy0">;</span><br>        <span clas=
s=3D"x_gmail-kw1">my</span> <span class=3D"x_gmail-re0">$c</span> <span cla=
ss=3D"x_gmail-sy0">=3D</span> =E4t <span class=3D"x_gmail-sy0">*</span> yp<=
span class=3D"x_gmail-br0">(</span> t <span class=3D"x_gmail-sy0">&#43;</sp=
an> =E4t<span class=3D"x_gmail-sy0">/</span><span class=3D"x_gmail-nu0">2</=
span><span class=3D"x_gmail-sy0">,</span> y <span class=3D"x_gmail-sy0">&#4=
3;</span> <span class=3D"x_gmail-re0">$b</span><span class=3D"x_gmail-sy0">=
/</span><span class=3D"x_gmail-nu0">2</span> <span class=3D"x_gmail-br0">)<=
/span><span class=3D"x_gmail-sy0">;</span><br>        <span class=3D"x_gmai=
l-kw1">my</span> <span class=3D"x_gmail-re0">$d</span> <span class=3D"x_gma=
il-sy0">=3D</span> =E4t <span class=3D"x_gmail-sy0">*</span> yp<span class=
=3D"x_gmail-br0">(</span> t <span class=3D"x_gmail-sy0">&#43;</span> =E4t<s=
pan class=3D"x_gmail-sy0">,</span> y <span class=3D"x_gmail-sy0">&#43;</spa=
n> <span class=3D"x_gmail-re0">$c</span> <span class=3D"x_gmail-br0">)</spa=
n><span class=3D"x_gmail-sy0">;</span><br>        <span class=3D"x_gmail-br=
0">(</span><span class=3D"x_gmail-re0">$a</span> <span class=3D"x_gmail-sy0=
">&#43;</span> <span class=3D"x_gmail-nu0">2</span><span class=3D"x_gmail-s=
y0">*</span><span class=3D"x_gmail-br0">(</span><span class=3D"x_gmail-re0"=
>$b</span> <span class=3D"x_gmail-sy0">&#43;</span> <span class=3D"x_gmail-=
re0">$c</span><span class=3D"x_gmail-br0">)</span> <span class=3D"x_gmail-s=
y0">&#43;</span> <span class=3D"x_gmail-re0">$d</span><span class=3D"x_gmai=
l-br0">)</span> <span class=3D"x_gmail-sy0">/</span> <span class=3D"x_gmail=
-nu0">6</span><span class=3D"x_gmail-sy0">;</span><br>    <span class=3D"x_=
gmail-br0">}</span><br><span class=3D"x_gmail-br0">}</span><br>&nbsp;<br><s=
pan class=3D"x_gmail-co1"># gravitational constant</span><br><span class=3D=
"x_gmail-kw1">constant</span> G <span class=3D"x_gmail-sy0">=3D</span> 6<sp=
an class=3D"x_gmail-sy0">.</span>674e<span class=3D"x_gmail-sy0">-</span>11=
<span class=3D"x_gmail-sy0">;</span><br><span class=3D"x_gmail-co1"># astro=
nomical unit</span><br><span class=3D"x_gmail-kw1">constant</span> au <span=
 class=3D"x_gmail-sy0">=3D</span> 150e9<span class=3D"x_gmail-sy0">;</span>=
<br>&nbsp;<br><span class=3D"x_gmail-co1"># time constants in seconds</span=
><br><span class=3D"x_gmail-kw1">constant</span> year <span class=3D"x_gmai=
l-sy0">=3D</span> <span class=3D"x_gmail-nu0">365.25</span><span class=3D"x=
_gmail-sy0">*</span><span class=3D"x_gmail-nu0">24</span><span class=3D"x_g=
mail-sy0">*</span><span class=3D"x_gmail-nu0">60</span><span class=3D"x_gma=
il-sy0">*</span><span class=3D"x_gmail-nu0">60</span><span class=3D"x_gmail=
-sy0">;</span><br><span class=3D"x_gmail-kw1">constant</span> month <span c=
lass=3D"x_gmail-sy0">=3D</span> <span class=3D"x_gmail-nu0">21</span><span =
class=3D"x_gmail-sy0">*</span><span class=3D"x_gmail-nu0">24</span><span cl=
ass=3D"x_gmail-sy0">*</span><span class=3D"x_gmail-nu0">60</span><span clas=
s=3D"x_gmail-sy0">*</span><span class=3D"x_gmail-nu0">60</span><span class=
=3D"x_gmail-sy0">;</span><br>&nbsp;<br><span class=3D"x_gmail-co1"># masses=
 in kg</span><br><span class=3D"x_gmail-kw1">constant</span> <span class=3D=
"x_gmail-re0">$ma</span> <span class=3D"x_gmail-sy0">=3D</span> 2e30<span c=
lass=3D"x_gmail-sy0">;</span>     <span class=3D"x_gmail-co1"># Sun</span><=
br><span class=3D"x_gmail-kw1">constant</span> <span class=3D"x_gmail-re0">=
$mb</span> <span class=3D"x_gmail-sy0">=3D</span> 6e24<span class=3D"x_gmai=
l-sy0">;</span>     <span class=3D"x_gmail-co1"># Earth</span><br><span cla=
ss=3D"x_gmail-kw1">constant</span> <span class=3D"x_gmail-re0">$mc</span> <=
span class=3D"x_gmail-sy0">=3D</span> 7<span class=3D"x_gmail-sy0">.</span>=
34e22<span class=3D"x_gmail-sy0">;</span>  <span class=3D"x_gmail-co1"># Mo=
on</span><br>&nbsp;<br><span class=3D"x_gmail-kw1">my</span> <span class=3D=
"x_gmail-re0">&amp;dABC</span> <span class=3D"x_gmail-sy0">=3D</span> runge=
<span class=3D"x_gmail-sy0">-</span>kutta <span class=3D"x_gmail-kw1">my</s=
pan> <span class=3D"x_gmail-re0">&amp;f</span> <span class=3D"x_gmail-sy0">=
=3D</span> <span class=3D"x_gmail-kw2">sub</span> <span class=3D"x_gmail-br=
0">(</span> <span class=3D"x_gmail-re0">$t</span><span class=3D"x_gmail-sy0=
">,</span> <span class=3D"x_gmail-re0">@ABC</span> <span class=3D"x_gmail-b=
r0">)</span> <span class=3D"x_gmail-br0">{</span><br>    <span class=3D"x_g=
mail-kw1">my</span> <span class=3D"x_gmail-re0">@a</span> <span class=3D"x_=
gmail-sy0">=3D</span> <span class=3D"x_gmail-re0">@ABC</span><span class=3D=
"x_gmail-br0">[</span><span class=3D"x_gmail-nu0">0</span><span class=3D"x_=
gmail-sy0">..</span><span class=3D"x_gmail-nu0">2</span><span class=3D"x_gm=
ail-br0">]</span><span class=3D"x_gmail-sy0">;</span><br>    <span class=3D=
"x_gmail-kw1">my</span> <span class=3D"x_gmail-re0">@b</span> <span class=
=3D"x_gmail-sy0">=3D</span> <span class=3D"x_gmail-re0">@ABC</span><span cl=
ass=3D"x_gmail-br0">[</span><span class=3D"x_gmail-nu0">3</span><span class=
=3D"x_gmail-sy0">..</span><span class=3D"x_gmail-nu0">5</span><span class=
=3D"x_gmail-br0">]</span><span class=3D"x_gmail-sy0">;</span><br>    <span =
class=3D"x_gmail-kw1">my</span> <span class=3D"x_gmail-re0">@c</span> <span=
 class=3D"x_gmail-sy0">=3D</span> <span class=3D"x_gmail-re0">@ABC</span><s=
pan class=3D"x_gmail-br0">[</span><span class=3D"x_gmail-nu0">6</span><span=
 class=3D"x_gmail-sy0">..</span><span class=3D"x_gmail-nu0">8</span><span c=
lass=3D"x_gmail-br0">]</span><span class=3D"x_gmail-sy0">;</span><br>&nbsp;=
<br>    <span class=3D"x_gmail-kw1">my</span> <span class=3D"x_gmail-re0">$=
ab</span> <span class=3D"x_gmail-sy0">=3D</span> norm<span class=3D"x_gmail=
-br0">(</span><span class=3D"x_gmail-re0">@a</span> <span class=3D"x_gmail-=
sy0">-</span> <span class=3D"x_gmail-re0">@b</span><span class=3D"x_gmail-b=
r0">)</span><span class=3D"x_gmail-sy0">;</span> <br>    <span class=3D"x_g=
mail-kw1">my</span> <span class=3D"x_gmail-re0">$ac</span> <span class=3D"x=
_gmail-sy0">=3D</span> norm<span class=3D"x_gmail-br0">(</span><span class=
=3D"x_gmail-re0">@a</span> <span class=3D"x_gmail-sy0">-</span> <span class=
=3D"x_gmail-re0">@c</span><span class=3D"x_gmail-br0">)</span><span class=
=3D"x_gmail-sy0">;</span><br>    <span class=3D"x_gmail-kw1">my</span> <spa=
n class=3D"x_gmail-re0">$bc</span> <span class=3D"x_gmail-sy0">=3D</span> n=
orm<span class=3D"x_gmail-br0">(</span><span class=3D"x_gmail-re0">@b</span=
> <span class=3D"x_gmail-sy0">-</span> <span class=3D"x_gmail-re0">@c</span=
><span class=3D"x_gmail-br0">)</span><span class=3D"x_gmail-sy0">;</span><b=
r>&nbsp;<br>    <span class=3D"x_gmail-kw1">return</span> <span class=3D"x_=
gmail-br0">[</span><br>        flat<br>        <span class=3D"x_gmail-re0">=
@ABC</span><span class=3D"x_gmail-br0">[</span><span class=3D"x_gmail-sy0">=
@</span><span class=3D"x_gmail-br0">(</span><span class=3D"x_gmail-nu0">9</=
span><span class=3D"x_gmail-sy0">..</span><span class=3D"x_gmail-nu0">17</s=
pan><span class=3D"x_gmail-br0">)</span><span class=3D"x_gmail-br0">]</span=
><span class=3D"x_gmail-sy0">,</span><br>        <span class=3D"x_gmail-kw3=
">map</span> G <span class=3D"x_gmail-sy0">*</span> <span class=3D"x_gmail-=
sy0">*,</span><br>        <span class=3D"x_gmail-re0">$mb</span><span class=
=3D"x_gmail-sy0">/</span><span class=3D"x_gmail-re0">$ab</span><span class=
=3D"x_gmail-sy0">**</span><span class=3D"x_gmail-nu0">3</span> <span class=
=3D"x_gmail-sy0">*</span> <span class=3D"x_gmail-br0">(</span><span class=
=3D"x_gmail-re0">@b</span> <span class=3D"x_gmail-sy0">-</span> <span class=
=3D"x_gmail-re0">@a</span><span class=3D"x_gmail-br0">)</span> <span class=
=3D"x_gmail-sy0">&#43;</span> <span class=3D"x_gmail-re0">$mc</span><span c=
lass=3D"x_gmail-sy0">/</span><span class=3D"x_gmail-re0">$ac</span><span cl=
ass=3D"x_gmail-sy0">**</span><span class=3D"x_gmail-nu0">3</span> <span cla=
ss=3D"x_gmail-sy0">*</span> <span class=3D"x_gmail-br0">(</span><span class=
=3D"x_gmail-re0">@c</span> <span class=3D"x_gmail-sy0">-</span> <span class=
=3D"x_gmail-re0">@a</span><span class=3D"x_gmail-br0">)</span><span class=
=3D"x_gmail-sy0">,</span><br>        <span class=3D"x_gmail-re0">$ma</span>=
<span class=3D"x_gmail-sy0">/</span><span class=3D"x_gmail-re0">$ab</span><=
span class=3D"x_gmail-sy0">**</span><span class=3D"x_gmail-nu0">3</span> <s=
pan class=3D"x_gmail-sy0">*</span> <span class=3D"x_gmail-br0">(</span><spa=
n class=3D"x_gmail-re0">@a</span> <span class=3D"x_gmail-sy0">-</span> <spa=
n class=3D"x_gmail-re0">@b</span><span class=3D"x_gmail-br0">)</span> <span=
 class=3D"x_gmail-sy0">&#43;</span> <span class=3D"x_gmail-re0">$mc</span><=
span class=3D"x_gmail-sy0">/</span><span class=3D"x_gmail-re0">$bc</span><s=
pan class=3D"x_gmail-sy0">**</span><span class=3D"x_gmail-nu0">3</span> <sp=
an class=3D"x_gmail-sy0">*</span> <span class=3D"x_gmail-br0">(</span><span=
 class=3D"x_gmail-re0">@c</span> <span class=3D"x_gmail-sy0">-</span> <span=
 class=3D"x_gmail-re0">@b</span><span class=3D"x_gmail-br0">)</span><span c=
lass=3D"x_gmail-sy0">,</span><br>        <span class=3D"x_gmail-re0">$ma</s=
pan><span class=3D"x_gmail-sy0">/</span><span class=3D"x_gmail-re0">$ac</sp=
an><span class=3D"x_gmail-sy0">**</span><span class=3D"x_gmail-nu0">3</span=
> <span class=3D"x_gmail-sy0">*</span> <span class=3D"x_gmail-br0">(</span>=
<span class=3D"x_gmail-re0">@a</span> <span class=3D"x_gmail-sy0">-</span> =
<span class=3D"x_gmail-re0">@c</span><span class=3D"x_gmail-br0">)</span> <=
span class=3D"x_gmail-sy0">&#43;</span> <span class=3D"x_gmail-re0">$mb</sp=
an><span class=3D"x_gmail-sy0">/</span><span class=3D"x_gmail-re0">$bc</spa=
n><span class=3D"x_gmail-sy0">**</span><span class=3D"x_gmail-nu0">3</span>=
 <span class=3D"x_gmail-sy0">*</span> <span class=3D"x_gmail-br0">(</span><=
span class=3D"x_gmail-re0">@b</span> <span class=3D"x_gmail-sy0">-</span> <=
span class=3D"x_gmail-re0">@c</span><span class=3D"x_gmail-br0">)</span><sp=
an class=3D"x_gmail-sy0">;</span><br>    <span class=3D"x_gmail-br0">]</spa=
n><span class=3D"x_gmail-sy0">;</span><br><span class=3D"x_gmail-br0">}</sp=
an><br>&nbsp;<br><span class=3D"x_gmail-kw1">loop</span> <span class=3D"x_g=
mail-br0">(</span><br>    <span class=3D"x_gmail-kw1">my</span> <span class=
=3D"x_gmail-br0">(</span><span class=3D"x_gmail-re0">$t</span><span class=
=3D"x_gmail-sy0">,</span> <span class=3D"x_gmail-re0">@ABC</span><span clas=
s=3D"x_gmail-br0">)</span> <span class=3D"x_gmail-sy0">=3D</span> <span cla=
ss=3D"x_gmail-nu0">0</span><span class=3D"x_gmail-sy0">,</span><br>        =
<span class=3D"x_gmail-nu0">0</span><span class=3D"x_gmail-sy0">,</span> <s=
pan class=3D"x_gmail-nu0">0</span><span class=3D"x_gmail-sy0">,</span> <spa=
n class=3D"x_gmail-nu0">0</span><span class=3D"x_gmail-sy0">,</span>       =
                          <span class=3D"x_gmail-co1"># Sun position</span>=
<br>        au<span class=3D"x_gmail-sy0">,</span> <span class=3D"x_gmail-n=
u0">0</span><span class=3D"x_gmail-sy0">,</span> <span class=3D"x_gmail-nu0=
">0</span><span class=3D"x_gmail-sy0">,</span>                             =
   <span class=3D"x_gmail-co1"># Earth position</span><br>        <span cla=
ss=3D"x_gmail-nu0">0.998</span><span class=3D"x_gmail-sy0">*</span>au<span =
class=3D"x_gmail-sy0">,</span> <span class=3D"x_gmail-nu0">0</span><span cl=
ass=3D"x_gmail-sy0">,</span> <span class=3D"x_gmail-nu0">0</span><span clas=
s=3D"x_gmail-sy0">,</span>                          <span class=3D"x_gmail-=
co1"># Moon position</span><br>        <span class=3D"x_gmail-nu0">0</span>=
<span class=3D"x_gmail-sy0">,</span> <span class=3D"x_gmail-nu0">0</span><s=
pan class=3D"x_gmail-sy0">,</span> <span class=3D"x_gmail-nu0">0</span><spa=
n class=3D"x_gmail-sy0">,</span>                                 <span clas=
s=3D"x_gmail-co1"># Sun speed</span><br>        <span class=3D"x_gmail-nu0"=
>0</span><span class=3D"x_gmail-sy0">,</span> <span class=3D"x_gmail-nu0">2=
</span><span class=3D"x_gmail-sy0">*</span>pi<span class=3D"x_gmail-sy0">*<=
/span>au<span class=3D"x_gmail-sy0">/</span>year<span class=3D"x_gmail-sy0"=
>,</span> <span class=3D"x_gmail-nu0">0</span><span class=3D"x_gmail-sy0">,=
</span>                      <span class=3D"x_gmail-co1"># Earth speed</spa=
n><br>        <span class=3D"x_gmail-nu0">0</span><span class=3D"x_gmail-sy=
0">,</span> <span class=3D"x_gmail-nu0">2</span><span class=3D"x_gmail-sy0"=
>*</span>pi<span class=3D"x_gmail-sy0">*</span><span class=3D"x_gmail-br0">=
(</span>au<span class=3D"x_gmail-sy0">/</span>year <span class=3D"x_gmail-s=
y0">&#43;</span> <span class=3D"x_gmail-nu0">0.002</span><span class=3D"x_g=
mail-sy0">*</span>au<span class=3D"x_gmail-sy0">/</span>month<span class=3D=
"x_gmail-br0">)</span><span class=3D"x_gmail-sy0">,</span> <span class=3D"x=
_gmail-nu0">0</span>    <span class=3D"x_gmail-co1"># Moon speed</span><br>=
    <span class=3D"x_gmail-sy0">;</span><br>    <span class=3D"x_gmail-re0"=
>$t</span> <span class=3D"x_gmail-sy0">&lt;</span> <span class=3D"x_gmail-s=
y0">.</span>2<span class=3D"x_gmail-sy0">;</span><br>    <span class=3D"x_g=
mail-br0">(</span><span class=3D"x_gmail-re0">$t</span><span class=3D"x_gma=
il-sy0">,</span> <span class=3D"x_gmail-re0">@ABC</span><span class=3D"x_gm=
ail-br0">)</span>&nbsp;=BB<span class=3D"x_gmail-sy0">&#43;=3D</span>=AB&nb=
sp;<span class=3D"x_gmail-br0">(</span><span class=3D"x_gmail-sy0">.</span>=
01<span class=3D"x_gmail-sy0">,</span> dABC<span class=3D"x_gmail-br0">(</s=
pan><span class=3D"x_gmail-re0">$t</span><span class=3D"x_gmail-sy0">,</spa=
n> <span class=3D"x_gmail-re0">@ABC</span><span class=3D"x_gmail-sy0">,</sp=
an> <span class=3D"x_gmail-sy0">.</span>01<span class=3D"x_gmail-br0">)</sp=
an><span class=3D"x_gmail-br0">)</span><br><span class=3D"x_gmail-br0">)</s=
pan> <span class=3D"x_gmail-br0">{</span><br>    <span class=3D"x_gmail-kw3=
">printf</span> <span class=3D"x_gmail-st0">&quot;t =3D&nbsp;%.02f&nbsp;:&n=
bsp;%s<span class=3D"x_es0">\n</span>&quot;</span><span class=3D"x_gmail-sy=
0">,</span> <span class=3D"x_gmail-re0">$t</span><span class=3D"x_gmail-sy0=
">,</span> <span class=3D"x_gmail-re0">@ABC</span><span class=3D"x_gmail-sy=
0">.</span><span class=3D"x_gmail-kw3">fmt</span><span class=3D"x_gmail-br0=
">(</span><span class=3D"x_gmail-st0">&quot;%&#43;.3e&quot;</span><span cla=
ss=3D"x_gmail-br0">)</span><span class=3D"x_gmail-sy0">;</span><br><span cl=
ass=3D"x_gmail-br0">}</span></pre>
</div>
<div class=3D"x_gmail_default" style=3D"font-size:small"><br>
</div>
<div class=3D"x_gmail_default" style=3D"font-size:small">---</div>
<div class=3D"x_gmail_default" style=3D"font-size:small"><br>
</div>
<div class=3D"x_gmail_default" style=3D"font-size:small">I'm having problem=
 specially in the &quot;multi infix&quot; and even in the &quot;norm&quot; =
sub routine. The problem is that I do not understand the construction of th=
ese in Perl 5 (otherwise, I would translate this easely,
 and I wouldn't be asking for help...)</div>
<div class=3D"x_gmail_default" style=3D"font-size:small"><br>
</div>
<div class=3D"x_gmail_default" style=3D"font-size:small">Any help is apreci=
ated.</div>
<div class=3D"x_gmail_default" style=3D"font-size:small"><br>
</div>
<div class=3D"x_gmail_default" style=3D"font-size:small">Clear skies</div>
<div class=3D"x_gmail_default" style=3D"font-size:small"><br>
</div>
<div class=3D"x_gmail_default" style=3D"font-size:small">Rui Fernandes<br>
</div>
</div>
</div>
</body>
</html>

--_000_BN7PR09MB2594C4BC11FA0E7E353032B9C0D70BN7PR09MB2594namp_--
0
Andy_Bach
8/8/2019 8:39:29 PM
--Apple-Mail=_D58E3248-E2A5-4EB7-A63B-445A55D82362
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8

[ Executive Summary: Install Perl 6; it will not disturb your =
Activestate Perl 5 : https://rakudo.org/files ]


> On Aug 8, 2019, at 3:07 PM, Rui Fernandes <rui.kepler@gmail.com> =
wrote:
>=20
> Greetings

Hi Rui!

>=20
> I have this Perl 6 script from Rosetta, which I wanted to run on Perl =
5 (due to the Active Sate Perl and App version that I have).

I think you have an all-too-common misconception.=20
Perl 6 is not the next version of Perl 5; Perl 6 is a =E2=80=9Csister =
language=E2=80=9D; the first Perl language to completely break backwards =
compatibility with 1..5.

> However, several syntax errors appear given the difference (some) in =
language.

The compiler is only showing you the *initial* syntax errors; the total =
number of changes needed to make this run in Perl 5 will be many more =
than =E2=80=9Cseveral=E2=80=9D.
Translating from Perl 5 to Perl 6 often only requires minimal syntax =
changes. After that, you have the option to refactor the Perl 5 idioms =
in the converted code into more concise expressions.

When code has been written in idiomatic Perl 6 (as your code has been), =
translating back to Perl 5 can be quite effortful.
For example, just the first line that defines a plus operator for =
lists/arrays representing vectors:
	multi infix:<+>(@a, @b) { @a Z+ @b }
, which would be simply invoked in Perl 6 as:
	my @foo =3D @this + @that;
However, translated it into Perl 5, it would look something like this =
(untested):
	sub vector_add {
		die if @_ !=3D 2;
		my ($x_aref, $y_aref) =3D @_;
		# warn if @{$x_aref} !=3D @{$y_aref};
		my $r =3D [];
		for my $i ( keys @{$x_aref} ) {
			$r->[$i] =3D $x_aref->[$i] + $y_aref->[$i];
		}
		return $r;
	}
	my @foo =3D @{ vector_add( \@this, \@that };
Even `norm` takes 4 SLOCs:
	sub norm { sqrt [+] @_ X** 2 }
vs:
	sub norm {
		my $r =3D 0;
		$r +=3D $_ ** 2 for @_;
		return sqrt $r;
	}

I am curious as to why you need to use this Perl 6 code in Perl 5.
You could just run it in Perl 6, since the =E2=80=9CRakudo Star=E2=80=9D =
Perl 6 distribution co-exists just fine with Activestate; you can get it =
here: https://rakudo.org/files .
Or, you could use the Perl 5 version of runge_kutta from just above =
where you found the Perl 6 version, on RosettaCode: =
http://rosettacode.org/wiki/Runge-Kutta_method#Perl .
Or, you could use one of the CPAN modules that provides the same =
function for Perl 5, like Math::RungeKutta or PDL::RungeKutta .

BTW, I think your `month` constant is wrong; You have it as 21 days, =
where I usually see it as either 28 or 29.53 or 30.4375.
Also, I have no idea what the line `$t < .2;` is supposed to do; it =
looks like dead code.

(LATE EDIT)
Oh, I just saw that the entire code that you posted comes from =
https://rosettacode.org/wiki/N-body_problem#Perl_6 , and that no one has =
made a Perl 5 solution for that RosettaCode task.
If you are intending to translate the Perl 6 code to Perl 5 in order to =
start contributing to RosettaCode, please contact me directly and I will =
be glad to work with you on it. (This will be more than appropriate for =
=E2=80=9CPerl Beginners=E2=80=9D)
If you are wanting to play with it for your own purposes, definitely =
just install Perl 6 as linked above.

> Here's the script:
=E2=80=94code snipped--
> I'm having problem specially in the "multi infix" and even in the =
"norm" sub routine. The problem is that I do not understand the =
construction of these in Perl 5 (otherwise, I would translate this =
easely, and I wouldn't be asking for help...)
>=20
> Any help is apreciated.
>=20
> Clear skies
>=20
> Rui Fernandes


=E2=80=94=20
Hope this helps,
Bruce Gray (Util of PerlMonks)


--Apple-Mail=_D58E3248-E2A5-4EB7-A63B-445A55D82362
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=utf-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; =
charset=3Dutf-8"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; line-break: after-white-space;" class=3D"">[ =
Executive Summary: Install Perl 6; it will not disturb your Activestate =
Perl 5 :&nbsp;<a href=3D"https://rakudo.org/files" =
class=3D"">https://rakudo.org/files</a> ]<br class=3D""><div><br =
class=3D""></div><div><br class=3D""><blockquote type=3D"cite" =
class=3D""><div class=3D"">On Aug 8, 2019, at 3:07 PM, Rui Fernandes =
&lt;<a href=3D"mailto:rui.kepler@gmail.com" =
class=3D"">rui.kepler@gmail.com</a>&gt; wrote:</div><br =
class=3D"Apple-interchange-newline"><div class=3D""><div dir=3D"ltr" =
class=3D""><div style=3D"font-size:small" =
class=3D"gmail_default">Greetings</div></div></div></blockquote><div><br =
class=3D""></div><div>Hi Rui!</div><br class=3D""><blockquote =
type=3D"cite" class=3D""><div class=3D""><div dir=3D"ltr" class=3D""><div =
style=3D"font-size:small" class=3D"gmail_default"><br =
class=3D""></div><div style=3D"font-size:small" class=3D"gmail_default">I =
have this Perl 6 script from Rosetta, which I wanted to run on Perl 5 =
(due to the Active Sate Perl and App version that I =
have).</div></div></div></blockquote><div><br class=3D""></div><div>I =
think you have an all-too-common misconception.&nbsp;</div><div>Perl 6 =
is not the next version of Perl 5; Perl 6 is a =E2=80=9Csister =
language=E2=80=9D; the first Perl language to completely break backwards =
compatibility with 1..5.</div><br class=3D""><blockquote type=3D"cite" =
class=3D""><div class=3D""><div dir=3D"ltr" class=3D""><div =
style=3D"font-size:small" class=3D"gmail_default">However, several =
syntax errors appear given the difference (some) in =
language.</div></div></div></blockquote><div><br class=3D""></div><div>The=
 compiler is only showing you the *initial* syntax errors; the total =
number of changes needed to make this run in Perl 5 will be many more =
than =E2=80=9Cseveral=E2=80=9D.</div><div>Translating from Perl 5 to =
Perl 6 often only requires minimal syntax changes. After that, you have =
the option to refactor the Perl 5 idioms in the converted code into more =
concise expressions.</div><div><br class=3D""></div><div>When code has =
been written in idiomatic Perl 6 (as your code has been), translating =
back to Perl 5 can be quite effortful.</div><div>For example, just the =
first line that defines a plus operator for lists/arrays representing =
vectors:</div><div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	</span>multi infix:&lt;+&gt;(@a, @b) { =
@a Z+ @b }</div><div class=3D"">, which would be simply invoked in Perl =
6 as:</div></div><div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	</span>my @foo =3D @this + =
@that;</div><div>However, translated it into Perl 5, it would look =
something like this (untested):</div><div class=3D""><div class=3D""><span=
 class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>sub =
vector_add {</div><div class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">		</span>die if @_ !=3D =
2;</div><div class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">		</span>my ($x_aref, $y_aref) =3D =
@_;</div><div class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">		</span># warn if @{$x_aref} !=3D =
@{$y_aref};</div><div class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">		</span>my $r =3D [];</div><div =
class=3D""><span class=3D"Apple-tab-span" style=3D"white-space:pre">		=
</span>for my $i ( keys @{$x_aref} ) {</div><div class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">			=
</span>$r-&gt;[$i] =3D $x_aref-&gt;[$i] + $y_aref-&gt;[$i];</div><div =
class=3D""><span class=3D"Apple-tab-span" style=3D"white-space:pre">		=
</span>}</div><div class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">		</span>return $r;</div><div =
class=3D""><span class=3D"Apple-tab-span" style=3D"white-space:pre">	=
</span>}</div><div class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	</span>my @foo =3D @{ vector_add( =
\@this, \@that };</div></div><div class=3D"">Even `norm` takes 4 =
SLOCs:</div><div class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	</span>sub norm { sqrt [+] @_ X** 2 =
}</div><div class=3D"">vs:</div><div class=3D""><div class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>sub norm =
{</div><div class=3D""><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">		</span>my $r =3D 0;</div><div =
class=3D""><span class=3D"Apple-tab-span" style=3D"white-space:pre">		=
</span>$r +=3D $_ ** 2 for @_;</div><div class=3D""><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">		=
</span>return sqrt $r;</div><div class=3D""><span class=3D"Apple-tab-span"=
 style=3D"white-space:pre">	</span>}</div></div><div class=3D""><br =
class=3D""></div><div class=3D"">I am curious as to why you need to use =
this Perl 6 code in Perl 5.</div><div class=3D"">You could just run it =
in Perl 6, since the =E2=80=9CRakudo Star=E2=80=9D Perl 6 distribution =
co-exists just fine with Activestate; you can get it here:&nbsp;<a =
href=3D"https://rakudo.org/files" class=3D"">https://rakudo.org/files</a> =
..</div><div class=3D"">Or, you could use the Perl 5 version of =
runge_kutta from just above where you found the Perl 6 version, on =
RosettaCode: <a =
href=3D"http://rosettacode.org/wiki/Runge-Kutta_method#Perl" =
class=3D"">http://rosettacode.org/wiki/Runge-Kutta_method#Perl</a> =
..</div><div class=3D"">Or, you could use one of the CPAN modules that =
provides the same function for Perl 5, like&nbsp;Math::RungeKutta =
or&nbsp;PDL::RungeKutta .</div><div class=3D""><br =
class=3D""></div></div><div>BTW, I think your `month` constant is wrong; =
You have it as 21 days, where I usually see it as either 28 or 29.53 or =
30.4375.</div><div>Also, I have no idea what the line `$t &lt; .2;` is =
supposed to do; it looks like dead code.</div><div><br =
class=3D""></div><div>(LATE EDIT)</div><div>Oh, I just saw that the =
entire code that you posted comes from&nbsp;<a =
href=3D"https://rosettacode.org/wiki/N-body_problem#Perl_6" =
class=3D"">https://rosettacode.org/wiki/N-body_problem#Perl_6</a> , and =
that no one has made a Perl 5 solution for that RosettaCode =
task.</div><div>If you are intending to translate the Perl 6 code to =
Perl 5 in order to start contributing to RosettaCode, please contact me =
directly and I will be glad to work with you on it. (This will be more =
than appropriate for =E2=80=9CPerl Beginners=E2=80=9D)</div><div>If you =
are wanting to play with it for your own purposes, definitely just =
install Perl 6 as linked above.</div><br class=3D""><blockquote =
type=3D"cite" class=3D""><div class=3D""><div dir=3D"ltr" class=3D""><div =
style=3D"font-size:small" class=3D"gmail_default">Here's the =
script:</div><div style=3D"font-size:small" =
class=3D"gmail_default"></div></div></div></blockquote>=E2=80=94code =
snipped--<br class=3D""><blockquote type=3D"cite" class=3D""><div =
class=3D""><div dir=3D"ltr" class=3D""><div style=3D"font-size:small" =
class=3D"gmail_default">I'm having problem specially in the "multi =
infix" and even in the "norm" sub routine. The problem is that I do not =
understand the construction of these in Perl 5 (otherwise, I would =
translate this easely, and I wouldn't be asking for help...)</div><div =
style=3D"font-size:small" class=3D"gmail_default"><br =
class=3D""></div><div style=3D"font-size:small" =
class=3D"gmail_default">Any help is apreciated.</div><div =
style=3D"font-size:small" class=3D"gmail_default"><br =
class=3D""></div><div style=3D"font-size:small" =
class=3D"gmail_default">Clear skies</div><div style=3D"font-size:small" =
class=3D"gmail_default"><br class=3D""></div><div =
style=3D"font-size:small" class=3D"gmail_default">Rui Fernandes<br =
class=3D""></div></div>
</div></blockquote></div><br class=3D""><div class=3D""><br =
class=3D""></div><div class=3D"">=E2=80=94&nbsp;</div><div class=3D"">Hope=
 this helps,</div><div class=3D"">Bruce Gray (Util of =
PerlMonks)</div><div class=3D""><br class=3D""></div></body></html>=

--Apple-Mail=_D58E3248-E2A5-4EB7-A63B-445A55D82362--
0
robertbrucegray3
8/8/2019 9:20:50 PM
hello Rui,

> I have this Perl 6 script from Rosetta, which I wanted to run on Perl 5
> (due to the Active Sate Perl and App version that I have).

Perl6 and Perl5 are very different. you need to download a perl6
interpretor if you want to run perl6 code.

please check https://rakudo.org/.

regards
marc
0
eiro
8/9/2019 7:22:33 AM
  the > I have this Perl 6 script from Rosetta, which I wanted to run on Pe=
rl 5
> (due to the Active Sate Perl and App version that I have).

If ActiveState have packaged https://metacpan.org/pod/Inline::Perl6
then please install and use that. (If they haven't, please ask them to
do so.)

> However, several syntax errors appear given the difference (some) in lang=
uage.

For some simple examples P5 and P6 code is very similar and so your
"(some)" qualifier is about as appropriate as saying there's (some) differe=
nce
between Python 2 and Python 3. (There is, but not a lot.)

For code like you've picked the difference is halfway to the difference
between English and German (both are West Germanic languages but
saying there's (some) difference in language doesn't really do justice to
the difference).

With that understood...

> I'm having problem specially in the "multi infix" and even in the "norm" =
sub routine.

----

# Simple Vector implementation
multi infix:<+>(@a, @b) { @a Z+ @b }

multi is short for multiple dispatch.

In P5, perhaps using the multi features of https://metacpan.org/pod/Dios
is the way to go, or maybe there's some other P5 package that implements
multiple dispatch.

Alternatively you could manually write the logic for routing certain
argument combinations to particular code. (That would drive me crazy.)

If there's no sub or method after the multi then it's a sub.

Reminder before continuing:

# Simple Vector implementation
multi infix:<+>(@a, @b) { @a Z+ @b }

infix:<+> names the sub.
It requires two Positional arguments (@ as a parameter).
Positional is a role; the arguments must do that role.
(Sorta like a signature expecting two arrayrefs.)
It zips them by calling infix + on pairings of their elements.

For example:

    say infix:<+> (1,2), (3,4); # (4,6)

Because it's called infix:<+> the declaration also immediately
installs it in the grammar as an infix operator, so you can
instead just write:

    say (1,2) + (3,4); # (4,6)

Note that this means it's the same as:

    say (1,2) Z+ (3,4); # (4,6)

In this latter case the infix Z metaop means  to call
the + on pairings of its two lists, i.e. 1 + 3 and 2 + 4.
Because this latter call passes two *scalar* arguments
to the infix + the multiple dispatch doesn't recursively
call the infix:<+> we defined above but instead the built
in infix:<+> which is something vaguely like:

    multi infix:<+> ($a, $b) { ... treats args as two numbers ... }

----

[+] arg1, arg2, arg3, ...

Does the same as:

arg1 + arg2 + arg3 ...

which, if args are scalars, is same as:

sum arg1, arg2, arg3

----

    return -> \t, \y, \=CE=B4t {

-> ... { ... }

is similar to an anonymous sub routine.

The first ... is its parameter list.

\foo in a parameter list declares a sigil-free "single static binding varia=
ble",
a *run-time* constant value.

# gravitational constant
constant G =3D 6.674e-11;

That's a *compile-time* constant value.

The e-11 means the number is a floating point number.

constant year =3D 365.25*24*60*60;

The 365.25 (no trailing e) means the number is a rational number.

    my @a =3D @ABC[0..2];

sigils are "invariant". @ABC[0..2] is a slice, a list of the first
three elements of the Positional variable @ABC.

For convenience I'll call a Positional variable a "list" from now on.

    my $ab =3D norm(@a - @b);

Without a multi infix:<-> defined the above code would norm
the difference between the length (number of elements) of the
two lists.

        flat

P5 generally autoflattens sub lists into one long list. You have to
explicitly mark when you want an arrayref instead. In contrast P6
generally treats @foo as an arrayref. You have to explicitly flatten
if you want that.

        map G * *,

The first * is in infix operator position. It denotes the infix
multiply operator.

The second is in term position. It denotes a Whatever.

When a Whatever appears with an operator, the operator decides
whether it cares (by having a multi that includes it as a parameter).

If it doesn't care, the compiler converts the expression it's in into an
anonymous routine. So the above code fragment is the same as:

        map { G * $_ },

If you'd like to thank me, send love to Larry Wall and either install
Inline::Perl6 or ask ActiveState to package it.

love, ralph
0
ralphdjmellor
8/9/2019 1:39:09 PM
Oops, missed the ending.

loop with a parens argument is like a C for with
3 args, init, test, next.

The next bit is:

    ($t, @ABC) =C2=BB+=3D=C2=AB (.01, dABC($t, @ABC, .01))

The =C2=BB and =C2=AB opops (or metaops) pack a whole lot of power but
can also be used for relatively simple cases like this one in which
they're just distributing the +=3D to pairings of the left and right sides.

(But remember the infix + has also been redefined to distribute
over lists. All of =C2=BB and =C2=AB and Z and X in infix op slots are op o=
ps
or metaops that distribute their ops to pairings of (elements of)
their arguments.)

..fmt("%+.3e")

is a method call, like ->fmt in P5.

Here is its doc:

https://docs.perl6.org/routine/fmt
0
ralphdjmellor
8/9/2019 1:58:34 PM
Hi Rui, Have you considered just installing Perl 6 ?

https://rakudo.org
https://www.perl6.org

Spoiler alert: the Perl6 code you posted works with no errors on my
Perl6 install.

Best Regards, Bill.



On Thu, Aug 8, 2019 at 1:07 PM Rui Fernandes <rui.kepler@gmail.com> wrote:
>
> Greetings
>
> I have this Perl 6 script from Rosetta, which I wanted to run on Perl 5 (=
due to the Active Sate Perl and App version that I have). However, several =
syntax errors appear given the difference (some) in language.Here's the scr=
ipt:
>
> ---
>
> # Simple Vector implementation
> multi infix:<+>(@a, @b) { @a Z+ @b }
> multi infix:<->(@a, @b) { @a Z- @b }
> multi infix:<*>($r, @a) { $r X* @a }
> multi infix:</>(@a, $r) { @a X/ $r }
> sub norm { sqrt [+] @_ X** 2 }
>
> # Runge-Kutta stuff
> sub runge-kutta(&yp) {
>     return -> \t, \y, \=CE=B4t {
>         my $a =3D =CE=B4t * yp( t, y );
>         my $b =3D =CE=B4t * yp( t + =CE=B4t/2, y + $a/2 );
>         my $c =3D =CE=B4t * yp( t + =CE=B4t/2, y + $b/2 );
>         my $d =3D =CE=B4t * yp( t + =CE=B4t, y + $c );
>         ($a + 2*($b + $c) + $d) / 6;
>     }
> }
>
> # gravitational constant
> constant G =3D 6.674e-11;
> # astronomical unit
> constant au =3D 150e9;
>
> # time constants in seconds
> constant year =3D 365.25*24*60*60;
> constant month =3D 21*24*60*60;
>
> # masses in kg
> constant $ma =3D 2e30;     # Sun
> constant $mb =3D 6e24;     # Earth
> constant $mc =3D 7.34e22;  # Moon
>
> my &dABC =3D runge-kutta my &f =3D sub ( $t, @ABC ) {
>     my @a =3D @ABC[0..2];
>     my @b =3D @ABC[3..5];
>     my @c =3D @ABC[6..8];
>
>     my $ab =3D norm(@a - @b);
>     my $ac =3D norm(@a - @c);
>     my $bc =3D norm(@b - @c);
>
>     return [
>         flat
>         @ABC[@(9..17)],
>         map G * *,
>         $mb/$ab**3 * (@b - @a) + $mc/$ac**3 * (@c - @a),
>         $ma/$ab**3 * (@a - @b) + $mc/$bc**3 * (@c - @b),
>         $ma/$ac**3 * (@a - @c) + $mb/$bc**3 * (@b - @c);
>     ];
> }
>
> loop (
>     my ($t, @ABC) =3D 0,
>         0, 0, 0,                                 # Sun position
>         au, 0, 0,                                # Earth position
>         0.998*au, 0, 0,                          # Moon position
>         0, 0, 0,                                 # Sun speed
>         0, 2*pi*au/year, 0,                      # Earth speed
>         0, 2*pi*(au/year + 0.002*au/month), 0    # Moon speed
>     ;
>     $t < .2;
>     ($t, @ABC) =C2=BB+=3D=C2=AB (.01, dABC($t, @ABC, .01))
> ) {
>     printf "t =3D %.02f : %s\n", $t, @ABC.fmt("%+.3e");
> }
>
>
> ---
>
> I'm having problem specially in the "multi infix" and even in the "norm" =
sub routine. The problem is that I do not understand the construction of th=
ese in Perl 5 (otherwise, I would translate this easely, and I wouldn't be =
asking for help...)
>
> Any help is apreciated.
>
> Clear skies
>
> Rui Fernandes
0
perl6
8/10/2019 1:30:19 AM
me either. no error happens.

在 2019/8/10 9:30, William Michels via perl6-users 写道:
> Spoiler alert: the Perl6 code you posted works with no errors on my
> Perl6 install.
0
eli
8/12/2019 2:44:16 AM
Reply: