Is this a bug?

2016-09-18 Thread Parrot Raiser
This code:
1 #! /home/guru/bin/perl6
2
3 # Ask for some lines and output them in reverse
4 # Work out the appropriate EOF symbol for the OS
5
6 my $EOF = "CTRL-" ~ ($*DISTRO.is-win ?? "Z" !! "D");
7
8 say "Please enter some lines and end them with $EOF";
9
10 say { for reverse lines() {} };
11
12 # End
produces this:
Please enter some lines and end them with CTRL-D# obviously from line 8
-> ;; $_? is raw { #`(Block|170303864) ... }# but this?


Re: Is this a bug?

2016-09-18 Thread Elizabeth Mattijsen
I think you want:

  .say for reverse lines;

not sure what you are trying to achieve otherwise, but:

   say { }

producing something like

   -> ;; $_? is raw { #`(Block|170303864) … }

feels entirely correct to me.   :-)


Liz

> On 18 Sep 2016, at 21:52, Parrot Raiser <1parr...@gmail.com> wrote:
> 
> This code:
> 1 #! /home/guru/bin/perl6
> 2
> 3 # Ask for some lines and output them in reverse
> 4 # Work out the appropriate EOF symbol for the OS
> 5
> 6 my $EOF = "CTRL-" ~ ($*DISTRO.is-win ?? "Z" !! "D");
> 7
> 8 say "Please enter some lines and end them with $EOF";
> 9
> 10 say { for reverse lines() {} };
> 11
> 12 # End
> produces this:
> Please enter some lines and end them with CTRL-D# obviously from line 8
> -> ;; $_? is raw { #`(Block|170303864) ... }# but this?



This seems to be wrong

2016-09-18 Thread Parrot Raiser
This code:
#! /home/guru/bin/perl6

# Ask for some numbers from 1 - 7
# and verify that they are in range

my @names = < fred betty barney dino wilma pebbles bamm-bamm >;

my @inputs = lines();

for @inputs {
if $_ ~~ 1..7 {
say @names[$_-1];
}
else {
   say "$_ out of range 1..7";
}
}

# End

Works for single-digit values:
7
3
8
2
1
0
4
bamm-bamm
barney
8 out of range 1..7
betty
fred
0 out of range 1..7
dino

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

(Usage adopted from http://tinyurl.com/hd2bxyv ; am I misreading that?)


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


Re: Is this a bug?

2016-09-18 Thread Brent Laabs
Remember you can call a block with parentheses:

> say { 11 + 31 };
-> ;; $_? is raw { #`(Block|140268472711224) ... }
> say { 11 + 31 }();
42


On Sun, Sep 18, 2016 at 12:58 PM, Elizabeth Mattijsen 
wrote:

> I think you want:
>
>   .say for reverse lines;
>
> not sure what you are trying to achieve otherwise, but:
>
>say { }
>
> producing something like
>
>-> ;; $_? is raw { #`(Block|170303864) … }
>
> feels entirely correct to me.   :-)
>
>
> Liz
>
> > On 18 Sep 2016, at 21:52, Parrot Raiser <1parr...@gmail.com> wrote:
> >
> > This code:
> > 1 #! /home/guru/bin/perl6
> > 2
> > 3 # Ask for some lines and output them in reverse
> > 4 # Work out the appropriate EOF symbol for the OS
> > 5
> > 6 my $EOF = "CTRL-" ~ ($*DISTRO.is-win ?? "Z" !! "D");
> > 7
> > 8 say "Please enter some lines and end them with $EOF";
> > 9
> > 10 say { for reverse lines() {} };
> > 11
> > 12 # End
> > produces this:
> > Please enter some lines and end them with CTRL-D# obviously from
> line 8
> > -> ;; $_? is raw { #`(Block|170303864) ... }# but
> this?
>
>


Re: Is this a bug?

2016-09-18 Thread Parrot Raiser
say { $_ } was the correct thing to use there. (I'm trying to avoid
any mention of O-O for the moment.)
say {} was a "what happens if I do this" exercise.

What is this  -> ;; $_? is raw { #`(Block|170303864) … } output?

On 9/18/16, Brent Laabs  wrote:
> Remember you can call a block with parentheses:
>
>> say { 11 + 31 };
> -> ;; $_? is raw { #`(Block|140268472711224) ... }
>> say { 11 + 31 }();
> 42
>
>
> On Sun, Sep 18, 2016 at 12:58 PM, Elizabeth Mattijsen 
> wrote:
>
>> I think you want:
>>
>>   .say for reverse lines;
>>
>> not sure what you are trying to achieve otherwise, but:
>>
>>say { }
>>
>> producing something like
>>
>>-> ;; $_? is raw { #`(Block|170303864) … }
>>
>> feels entirely correct to me.   :-)
>>
>>
>> Liz
>>
>> > On 18 Sep 2016, at 21:52, Parrot Raiser <1parr...@gmail.com> wrote:
>> >
>> > This code:
>> > 1 #! /home/guru/bin/perl6
>> > 2
>> > 3 # Ask for some lines and output them in reverse
>> > 4 # Work out the appropriate EOF symbol for the OS
>> > 5
>> > 6 my $EOF = "CTRL-" ~ ($*DISTRO.is-win ?? "Z" !! "D");
>> > 7
>> > 8 say "Please enter some lines and end them with $EOF";
>> > 9
>> > 10 say { for reverse lines() {} };
>> > 11
>> > 12 # End
>> > produces this:
>> > Please enter some lines and end them with CTRL-D# obviously from
>> line 8
>> > -> ;; $_? is raw { #`(Block|170303864) ... }# but
>> this?
>>
>>
>


Re: Is this a bug?

2016-09-18 Thread Elizabeth Mattijsen
It is the .perl representation of a Block.

> On 18 Sep 2016, at 22:49, Parrot Raiser <1parr...@gmail.com> wrote:
> 
> say { $_ } was the correct thing to use there. (I'm trying to avoid
> any mention of O-O for the moment.)
> say {} was a "what happens if I do this" exercise.
> 
> What is this  -> ;; $_? is raw { #`(Block|170303864) … } output?
> 
> On 9/18/16, Brent Laabs  wrote:
>> Remember you can call a block with parentheses:
>> 
>>> say { 11 + 31 };
>> -> ;; $_? is raw { #`(Block|140268472711224) ... }
>>> say { 11 + 31 }();
>> 42
>> 
>> 
>> On Sun, Sep 18, 2016 at 12:58 PM, Elizabeth Mattijsen 
>> wrote:
>> 
>>> I think you want:
>>> 
>>>  .say for reverse lines;
>>> 
>>> not sure what you are trying to achieve otherwise, but:
>>> 
>>>   say { }
>>> 
>>> producing something like
>>> 
>>>   -> ;; $_? is raw { #`(Block|170303864) … }
>>> 
>>> feels entirely correct to me.   :-)
>>> 
>>> 
>>> Liz
>>> 
 On 18 Sep 2016, at 21:52, Parrot Raiser <1parr...@gmail.com> wrote:
 
 This code:
 1 #! /home/guru/bin/perl6
 2
 3 # Ask for some lines and output them in reverse
 4 # Work out the appropriate EOF symbol for the OS
 5
 6 my $EOF = "CTRL-" ~ ($*DISTRO.is-win ?? "Z" !! "D");
 7
 8 say "Please enter some lines and end them with $EOF";
 9
 10 say { for reverse lines() {} };
 11
 12 # End
 produces this:
 Please enter some lines and end them with CTRL-D# obviously from
>>> line 8
 -> ;; $_? is raw { #`(Block|170303864) ... }# but
>>> this?
>>> 
>>> 
>> 



Re: Is this a bug?

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

> What is this  -> ;; $_? is raw { #`(Block|170303864) … } output?


It's the gist of a Block, which is what you asked for when you did a `say`
on an executable block.
Why do you believe `say { $_ }` is the right thing there? What were you
expecting it to do?

-- 
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 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 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: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: Is this a bug?

2016-09-18 Thread Trey Harris
On Sun, Sep 18, 2016 at 16:49 Parrot Raiser <1parr...@gmail.com> wrote:

say { $_ } was the correct thing to use there. (I'm trying to avoid
> any mention of O-O for the moment.)
>
“Trying to avoid any mention of O-O” seems like a Perl 6 obfuscation or
golf constraint, not a desirable development or learning goal. Perl 6
doesn’t *force* you to write programs in an object-oriented style; you can
do it in functional or procedural or whatever style suits you. But you’re
going to have a bad time if you try to deny Perl 6’s fully OO nature. This
is in stark contrast to Perl 5, where OO was bolted on, and you could say
that the non-OO core was more “real” than the object-oriented sugar found
in modules you had to use.

Writing something like say($_) for reverse lines — which is what I think is
closest to what you wanted — isn’t any more or less “object-oriented” than
the more idiomatic .say for reverse lines;. In Perl 5, some rather
byzantine rules governed the use of the implicit $_; almost all of the
convenience afforded by those rules can be gained through the use of
topicalized objects, so the byzantine rules are gone — but the convenience
is gone too unless you’re willing to use the topic in the .foo style.

I think perhaps you see a dot, and dot signifies OO, so the .say... version
might *look* more OO than the say(... version in some sense, but that’s
pretty much cosmetic. You’re *using* some objects by interacting with the
Perl 6 core either way. It’s your choice not to write your logic in an OO
style, but you can’t prevent OO from happening during execution.

(This really isn’t some half-hearted attempt to force you into OO through
the backdoor; you really can skip OO for all *your* logic. You just can’t
pretend you’re not using an object-oriented language when you have to touch
code you’re not in control of, whether an OO library or the Perl 6 core.
But pretty much the entirety of what you need to know about OO if you
choose to do that is various syntax and some desiderata about the calling
semantics.)

say {} was a "what happens if I do this" exercise.
>
> What is this  -> ;; $_? is raw { #`(Block|170303864) … } output?
>
> On 9/18/16, Brent Laabs  wrote:
> > Remember you can call a block with parentheses:
> >
> >> say { 11 + 31 };
> > -> ;; $_? is raw { #`(Block|140268472711224) ... }
> >> say { 11 + 31 }();
> > 42
> >
> >
> > On Sun, Sep 18, 2016 at 12:58 PM, Elizabeth Mattijsen 
> > wrote:
> >
> >> I think you want:
> >>
> >>   .say for reverse lines;
> >>
> >> not sure what you are trying to achieve otherwise, but:
> >>
> >>say { }
> >>
> >> producing something like
> >>
> >>-> ;; $_? is raw { #`(Block|170303864) … }
> >>
> >> feels entirely correct to me.   :-)
> >>
> >>
> >> Liz
> >>
> >> > On 18 Sep 2016, at 21:52, Parrot Raiser <1parr...@gmail.com> wrote:
> >> >
> >> > This code:
> >> > 1 #! /home/guru/bin/perl6
> >> > 2
> >> > 3 # Ask for some lines and output them in reverse
> >> > 4 # Work out the appropriate EOF symbol for the OS
> >> > 5
> >> > 6 my $EOF = "CTRL-" ~ ($*DISTRO.is-win ?? "Z" !! "D");
> >> > 7
> >> > 8 say "Please enter some lines and end them with $EOF";
> >> > 9
> >> > 10 say { for reverse lines() {} };
> >> > 11
> >> > 12 # End
> >> > produces this:
> >> > Please enter some lines and end them with CTRL-D# obviously from
> >> line 8
> >> > -> ;; $_? is raw { #`(Block|170303864) ... }# but
> >> this?
> >>
> >>
> >
>
​


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 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 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
>