Re: This seems to be wrong

2016-09-19 Thread Timo Paulssen
On 19/09/16 15:56, Aaron Sherman wrote:> You can also use map, but it's
slightly clunkier: > > "for @inputs.map: .Int -> $i { ... }"
This also needs to have "*.Int" or "{ .Int }" otherwise you'll pass
$_.Int as the argument to map rather than telling map to call .Int on
things.


Re: This seems to be wrong

2016-09-19 Thread Aaron Sherman
"for @inputs.map( .prefix:<+> ) {...}"

That's spelled:

"for @inputs>>.Int -> $i { ... }"

You can also use map, but it's slightly clunkier:

"for @inputs.map: .Int -> $i { ... }"



Aaron Sherman, M.:
P: 617-440-4332 Google Talk, Email and Google Plus: a...@ajs.com
Toolsmith, developer, gamer and life-long student.


On Sun, Sep 18, 2016 at 6:06 PM, Trey Harris  wrote:

> Why does this:
>
> for @inputs.map( .prefix:<+> ) { ... }
>
> Not work? It results inMethod 'prefix:<+>' not found for invocant of
> class 'Any', but the docs
>  say it is defined as
> a multi on Any….
>
> Trey
> ​
>
> On Sun, Sep 18, 2016 at 4:37 PM Brandon Allbery 
> wrote:
>
>> On Sun, Sep 18, 2016 at 4:31 PM, Parrot Raiser <1parr...@gmail.com>
>> wrote:
>>
>>> but seems to have a problem with larger numbers:
>>>
>>> 7
>>> 3
>>> 21  <- This
>>> 2
>>> 1
>>> 0
>>> 4
>>> bamm-bamm
>>> barney
>>> (Any)  <--- Produces this
>>> betty
>>> fred
>>> 0 out of range 1..7
>>> dino
>>>
>>
>> [18 20:35]  m: say so "21" ~~ 1..7
>> [18 20:35]  rakudo-moar 34f950: OUTPUT«True␤
>> [18 20:35]  »
>>
>> It came from lines(), it is a Str. Numify it first.
>>
>> --
>> brandon s allbery kf8nh   sine nomine
>> associates
>> allber...@gmail.com
>> ballb...@sinenomine.net
>> unix, openafs, kerberos, infrastructure, xmonad
>> http://sinenomine.net
>>
>


Re: This seems to be wrong

2016-09-18 Thread Trey Harris
D’oh! I’m blind.

But I see there’s a multi method Str defined on Any, and you can’t do
@inputs.map( .Str ), either (Use of uninitialized value $_ of type Any in
string context). Why not? (There’s no multi method Num on Any, even though
the docs about Cool  seem to imply there
should be…)
​

On Sun, Sep 18, 2016 at 6:15 PM Brandon Allbery  wrote:

>
> On Sun, Sep 18, 2016 at 6:06 PM, Trey Harris  wrote:
>
>> Not work? It results inMethod 'prefix:<+>' not found for invocant of
>> class 'Any', but the docs
>> 
>>
>> say it is defined as a multi on Any….
>>
>>
> No, they say it's a multi sub, not a multi method on Any. And the prefix:
> syntax doesn't seem to work directly with the quick workaround for that, so
> it ends up being
>
> for @inputs.map({ .&prefix:<+> }) { ... }
>
>
>
>
> --
> brandon s allbery kf8nh   sine nomine
> associates
> allber...@gmail.com
> ballb...@sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>


Re: This seems to be wrong

2016-09-18 Thread Trey Harris
On Sun, Sep 18, 2016 at 6:30 PM Brandon Allbery allber...@gmail.com
 wrote:


> On Sun, Sep 18, 2016 at 6:29 PM, Trey Harris  wrote:
>
>> But I see there’s a multi method Str defined on Any, and you can’t do
>> @inputs.map( .Str ), either (Use of uninitialized value $_ of type Any
>> in string context). Why not? (There’s no multi method Num on Any, even
>> though the docs about Cool 
>>
>> seem to imply there should be…)
>>
>>
> Same reason I had to wrap it in a Block --- it's not recognizing .Str as a
> closure, it's running it immediately. Perhaps you wanted *.Str?
>
Right, got it.

Does not being defined on Any explain why the error for @input.map( .Str )
is different (Use of uninitialized value $_ of type Any in string context)
than the error for @input.map( .Num ) (Method 'Num' not found for invocant
of class 'Any'), but both*.Str and *.Num work in the .map?


>
>
> --
> brandon s allbery kf8nh   sine nomine
> associates
> allber...@gmail.com
> ballb...@sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>
​


Re: This seems to be wrong

2016-09-18 Thread Brandon Allbery
On Sun, Sep 18, 2016 at 6:36 PM, Trey Harris  wrote:

> Does not being defined on Any explain why the error for @input.map( .Str )
> is different (Use of uninitialized value $_ of type Any in string context)
> than the error for @input.map( .Num ) (Method 'Num' not found for
> invocant of class 'Any'), but both*.Str and *.Num work in the .map?
>
Yes. Without the *, it's doing $_.Str or $_.Num when $_ is the one
*outside* the map call, which has no current value (and so is (Any)); in
the Str case it is invoking Any.Str and failing on the undefined value, in
the Num case it can't find the method for Any. With the *, it's a closure
and applies to the $_ current for each iteration of map; the invocant is a
defined Str.



-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


Re: This seems to be wrong

2016-09-18 Thread Brandon Allbery
On Sun, Sep 18, 2016 at 6:29 PM, Trey Harris  wrote:

> But I see there’s a multi method Str defined on Any, and you can’t do
> @inputs.map( .Str ), either (Use of uninitialized value $_ of type Any in
> string context). Why not? (There’s no multi method Num on Any, even
> though the docs about Cool 
>
> seem to imply there should be…)
>
>
Same reason I had to wrap it in a Block --- it's not recognizing .Str as a
closure, it's running it immediately. Perhaps you wanted *.Str?


-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


Re: This seems to be wrong

2016-09-18 Thread Trey Harris
Why does this:

for @inputs.map( .prefix:<+> ) { ... }

Not work? It results inMethod 'prefix:<+>' not found for invocant of class
'Any', but the docs 
say it is defined as a multi on Any….

Trey
​

On Sun, Sep 18, 2016 at 4:37 PM Brandon Allbery  wrote:

> On Sun, Sep 18, 2016 at 4:31 PM, Parrot Raiser <1parr...@gmail.com> wrote:
>
>> but seems to have a problem with larger numbers:
>>
>> 7
>> 3
>> 21  <- This
>> 2
>> 1
>> 0
>> 4
>> bamm-bamm
>> barney
>> (Any)  <--- Produces this
>> betty
>> fred
>> 0 out of range 1..7
>> dino
>>
>
> [18 20:35]  m: say so "21" ~~ 1..7
> [18 20:35]  rakudo-moar 34f950: OUTPUT«True␤
> [18 20:35]  »
>
> It came from lines(), it is a Str. Numify it first.
>
> --
> brandon s allbery kf8nh   sine nomine
> associates
> allber...@gmail.com
> ballb...@sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>


Re: This seems to be wrong

2016-09-18 Thread Brandon Allbery
On Sun, Sep 18, 2016 at 6:15 PM, Brandon Allbery 
wrote:

> for @inputs.map({ .&prefix:<+> }) { ... }


Which means the shorter way is:

for @inputs.map(+*) { ... }


-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


Re: This seems to be wrong

2016-09-18 Thread Brandon Allbery
On Sun, Sep 18, 2016 at 6:06 PM, Trey Harris  wrote:

> Not work? It results inMethod 'prefix:<+>' not found for invocant of
> class 'Any', but the docs
> 
>
> say it is defined as a multi on Any….
>
>
No, they say it's a multi sub, not a multi method on Any. And the prefix:
syntax doesn't seem to work directly with the quick workaround for that, so
it ends up being

for @inputs.map({ .&prefix:<+> }) { ... }




-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


Re: This seems to be wrong

2016-09-18 Thread Brandon Allbery
On Sun, Sep 18, 2016 at 4:31 PM, Parrot Raiser <1parr...@gmail.com> wrote:

> but seems to have a problem with larger numbers:
>
> 7
> 3
> 21  <- This
> 2
> 1
> 0
> 4
> bamm-bamm
> barney
> (Any)  <--- Produces this
> betty
> fred
> 0 out of range 1..7
> dino
>

[18 20:35]  m: say so "21" ~~ 1..7
[18 20:35]  rakudo-moar 34f950: OUTPUT«True␤
[18 20:35]  »

It came from lines(), it is a Str. Numify it first.

-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net