Re: How do I contact the moderator?

2020-02-11 Thread ToddAndMargo via perl6-users

On 2020-02-11 00:44, Shlomi Fish wrote:

Hi Todd,

On Mon, 10 Feb 2020 19:25:50 -0800
ToddAndMargo via perl6-users  wrote:


Hi All,

I have been getting a strange eMail on this group.
How do I contact the moderator to check and see
if it is a scam?



I think you should send an email to perl6-users-ow...@perl.org .


Many thanks,
-T


Thank you!


Re: How do I contact the moderator?

2020-02-11 Thread Shlomi Fish
Hi Todd,

On Mon, 10 Feb 2020 19:25:50 -0800
ToddAndMargo via perl6-users  wrote:

> Hi All,
> 
> I have been getting a strange eMail on this group.
> How do I contact the moderator to check and see
> if it is a scam?
> 

I think you should send an email to perl6-users-ow...@perl.org .

> Many thanks,
> -T



-- 

Shlomi Fish   https://www.shlomifish.org/
https://github.com/shlomif/Freenode-programming-channel-FAQ

  Khisanth =~ s/must sleep/must give Botje all my money/ .
— Freenode’s #perl

Please reply to list if it's a mailing list post - http://shlom.in/reply .


Re: printf question

2020-02-11 Thread WFB
Interesting stuff.
I would like to take the change and ask one question:
One thing, I had to get used to is the MAIN handling of parameters.
On the command line it is important to write then named parameter in front
of the positional ones:
MAIN('compile', :$verbose, :$test-only)
needs to write:
builder.raku --verbose compile
Its not possible to write
builder.raku compile --verbose.
That is not intuitive, at least for me because that breaks with the other
unix command line tools and is annoying if you have to change the script
call several times.

Why is that so? And is there a workaround for that?
Thanks
Wolfgang

On Mon, 10 Feb 2020 at 12:18, Timo Paulssen  wrote:

> Hi Paul and Todd,
>
> just a little extra info: the limitation for nameds to come after
> positionals is only for declarations of signatures.
>
> Usage of subs/methods as well as capture literals (which you don't use
> often, i imagine, so feel free to disregard) allow you to mix nameds and
> positionals freely; it will handle named parameters that are put between
> positionals as if they were after the positional parameters.
>
> > sub abcdefg($b, $f, $g, :$a, :$c, :$e) { say $a, $b, $c, $e }
> &abcdefg
> > abcdefg(1, a => 5, 2, c => 99, 100, e => 1024)
> 51991024
>
> Most cases where I wanted named parameters early in the call was when
> there was something big in the call, for example if a sub takes a block and
> a few options, i prefer to put the options before the block, so they are
> visible at a glance rather than after scrolling. I suppose this mirrors how
> regex modifiers (like :ignorecase / :i, :global, etc) have been moved to
> the front of regexes.
>
> Hope that's interesting
>   - Timo
> On 10/02/2020 07:48, Paul Procacci wrote:
>
> Named parameters must come after all positional parameters.
> Your example subroutine is invalid for this reason, while the following
> would be fine:
>
> sub abcdefg( $b, $f, $g, :$a, :$c, :$e)
>
> abcdefg("position1", "position2", "position3", :e("named_e"),
> :a("named_a"), :c("named_c"));
>
>
>
> On Sun, Feb 9, 2020 at 6:24 PM ToddAndMargo via perl6-users <
> perl6-us...@perl.org> wrote:
>
>> On 2020-02-09 14:53, Paul Procacci wrote:
>> > subchdir(IO() $path, :$d=True, :$r, :$w, :$x-->IO::Path:D)
>>
>> Hi Paul,
>>
>> What I wanted to see is how something liek
>>
>> sub abcdefg( :$a, $b, :$c, :$e, $f, $g )
>>
>> would be called
>>
>> -T
>>
>
>
> --
> __
>
> :(){ :|:& };:
>
>


Re: variable as subroutine?

2020-02-11 Thread Simon Proctor
If you can store a subroutine in a variable then you can pass said
subroutine to another one as an argument.

This leads us into the joys of functional programming.

And you may have used it already and not even realised.

The .map and .grep methods (and .reduce and bunch of others) all expect a
callable code block (that might be a subroutine) as a function.

This :

my @a = (1..10).map( * ** 2 )

and this :

my &sq = sub ($v) { $v ** 2 };
my @a = (1..10).map( &sq );

are doing the same thing. Except the second one has the &sq function
available for other things.

(A Note on Marc's comment * * * is not the same as -> $x { $x * $x } it is
the same  as -> $x, $y { $x * $y } )

You can then start doing things like storing functions as values in hashes
and doing all *kinds* of fun stuff.

Welcome to the tip of the iceberg.

Simon


On Tue, 11 Feb 2020 at 03:21, ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
> Is Larry using his magic powder again?
>
> Can I declare a subroutine as a variable?
>
>  my $abc = my sub (UInt $u, Str $s, Int $I) {
>
> How would I use it?
>
> And why would do such a thing?
>
> -T
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: printf question

2020-02-11 Thread Kevin Pye
The "workaround" is well documented:
https://docs.raku.org/language/create-cli#%*SUB-MAIN-OPTS

It's just a matter of setting named-anywhere option in the %*SUB-MAIN-OPTS
hash, which you will also need to create. There's an example in that doc
page.

Kevin.

On Tue, 11 Feb 2020 at 20:07, WFB  wrote:

> Interesting stuff.
> I would like to take the change and ask one question:
> One thing, I had to get used to is the MAIN handling of parameters.
> On the command line it is important to write then named parameter in front
> of the positional ones:
> MAIN('compile', :$verbose, :$test-only)
> needs to write:
> builder.raku --verbose compile
> Its not possible to write
> builder.raku compile --verbose.
> That is not intuitive, at least for me because that breaks with the other
> unix command line tools and is annoying if you have to change the script
> call several times.
>
> Why is that so? And is there a workaround for that?
> Thanks
> Wolfgang
>
> On Mon, 10 Feb 2020 at 12:18, Timo Paulssen  wrote:
>
>> Hi Paul and Todd,
>>
>> just a little extra info: the limitation for nameds to come after
>> positionals is only for declarations of signatures.
>>
>> Usage of subs/methods as well as capture literals (which you don't use
>> often, i imagine, so feel free to disregard) allow you to mix nameds and
>> positionals freely; it will handle named parameters that are put between
>> positionals as if they were after the positional parameters.
>>
>> > sub abcdefg($b, $f, $g, :$a, :$c, :$e) { say $a, $b, $c, $e }
>> &abcdefg
>> > abcdefg(1, a => 5, 2, c => 99, 100, e => 1024)
>> 51991024
>>
>> Most cases where I wanted named parameters early in the call was when
>> there was something big in the call, for example if a sub takes a block and
>> a few options, i prefer to put the options before the block, so they are
>> visible at a glance rather than after scrolling. I suppose this mirrors how
>> regex modifiers (like :ignorecase / :i, :global, etc) have been moved to
>> the front of regexes.
>>
>> Hope that's interesting
>>   - Timo
>> On 10/02/2020 07:48, Paul Procacci wrote:
>>
>> Named parameters must come after all positional parameters.
>> Your example subroutine is invalid for this reason, while the following
>> would be fine:
>>
>> sub abcdefg( $b, $f, $g, :$a, :$c, :$e)
>>
>> abcdefg("position1", "position2", "position3", :e("named_e"),
>> :a("named_a"), :c("named_c"));
>>
>>
>>
>> On Sun, Feb 9, 2020 at 6:24 PM ToddAndMargo via perl6-users <
>> perl6-us...@perl.org> wrote:
>>
>>> On 2020-02-09 14:53, Paul Procacci wrote:
>>> > subchdir(IO() $path, :$d=True, :$r, :$w, :$x-->IO::Path:D)
>>>
>>> Hi Paul,
>>>
>>> What I wanted to see is how something liek
>>>
>>> sub abcdefg( :$a, $b, :$c, :$e, $f, $g )
>>>
>>> would be called
>>>
>>> -T
>>>
>>
>>
>> --
>> __
>>
>> :(){ :|:& };:
>>
>>


Question about Blob and Buf

2020-02-11 Thread David Santiago
A 11 de fevereiro de 2020 10:47:34 CET, David Santiago  
escreveu:
>A 11 de fevereiro de 2020 09:46:06 CET, David Santiago  
>escreveu:
>>
>>Hi!
>>
>>Can someone explain me why this doesn't work:
>>
>>my Blob $read;
>>$read ~= $socket.read(1024);
>>
>>Dies with error:
>>
>>X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy 
>>method on it
>>
>>This also doesn't work:
>>
>>my Buf $read;
>>$read ~= $socket.read(1024);
>>
>>Dies with the same error as above.
>>
>>
>>But this works?
>>
>>my Blob $read = Buf.new;
>>$read ~= $socket.read(1024);
>>
>>
>>Best regards,
>>David Santiago
>
>
>Hi!
>
>Can someone explain me why this doesn't work:
>
>my Blob $read;
>$read ~= $socket.read(1024);
>
>Dies with error:
>
>X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy method 
>on it
>
>This also doesn't work:
>
>my Buf $read;
>$read ~= $socket.read(1024);
>
>Dies with the same error as above.
>
>
>But this works?
>
>my Blob $read = Buf.new;
>$read ~= $socket.read(1024);
>
>
>Best regards,
>David Santiago


Hi!

Can someone explain me why this doesn't work:

my Blob $read;
$read ~= $socket.read(1024);

Dies with error:

X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy method 
on it

This also doesn't work:

my Buf $read;
$read ~= $socket.read(1024);

Dies with the same error as above.


But this works?

my Blob $read = Buf.new;
$read ~= $socket.read(1024);


Best regards,
David Santiago

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


Re: Question about Blob and Buf

2020-02-11 Thread JJ Merelo
You are using ~, which stringifies. Bufs are not strings: you need to
decode them to concatenate it to a string. If what you want is to
concatenate the buffer, probably ,= will work (not sure about this, would
have to check), or any other operator that works on Positionals.

JJ

El mar., 11 feb. 2020 a las 10:56, David Santiago ()
escribió:

> A 11 de fevereiro de 2020 10:47:34 CET, David Santiago 
> escreveu:
> >A 11 de fevereiro de 2020 09:46:06 CET, David Santiago <
> deman...@gmail.com> escreveu:
> >>
> >>Hi!
> >>
> >>Can someone explain me why this doesn't work:
> >>
> >>my Blob $read;
> >>$read ~= $socket.read(1024);
> >>
> >>Dies with error:
> >>
> >>X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
> method on it
> >>
> >>This also doesn't work:
> >>
> >>my Buf $read;
> >>$read ~= $socket.read(1024);
> >>
> >>Dies with the same error as above.
> >>
> >>
> >>But this works?
> >>
> >>my Blob $read = Buf.new;
> >>$read ~= $socket.read(1024);
> >>
> >>
> >>Best regards,
> >>David Santiago
> >
> >
> >Hi!
> >
> >Can someone explain me why this doesn't work:
> >
> >my Blob $read;
> >$read ~= $socket.read(1024);
> >
> >Dies with error:
> >
> >X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
> method on it
> >
> >This also doesn't work:
> >
> >my Buf $read;
> >$read ~= $socket.read(1024);
> >
> >Dies with the same error as above.
> >
> >
> >But this works?
> >
> >my Blob $read = Buf.new;
> >$read ~= $socket.read(1024);
> >
> >
> >Best regards,
> >David Santiago
>
>
> Hi!
>
> Can someone explain me why this doesn't work:
>
> my Blob $read;
> $read ~= $socket.read(1024);
>
> Dies with error:
>
> X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
> method on it
>
> This also doesn't work:
>
> my Buf $read;
> $read ~= $socket.read(1024);
>
> Dies with the same error as above.
>
>
> But this works?
>
> my Blob $read = Buf.new;
> $read ~= $socket.read(1024);
>
>
> Best regards,
> David Santiago
>
> --
> Sent from my Android device with K-9 Mail. Please excuse my brevity.
>


-- 
JJ


Re: printf question

2020-02-11 Thread WFB
Awesome, thanks!
That is exactly what I was looking for.


On Tue, 11 Feb 2020 at 10:23, Kevin Pye  wrote:

> The "workaround" is well documented:
> https://docs.raku.org/language/create-cli#%*SUB-MAIN-OPTS
>
> It's just a matter of setting named-anywhere option in the %*SUB-MAIN-OPTS
> hash, which you will also need to create. There's an example in that doc
> page.
>
> Kevin.
>
> On Tue, 11 Feb 2020 at 20:07, WFB  wrote:
>
>> Interesting stuff.
>> I would like to take the change and ask one question:
>> One thing, I had to get used to is the MAIN handling of parameters.
>> On the command line it is important to write then named parameter in
>> front of the positional ones:
>> MAIN('compile', :$verbose, :$test-only)
>> needs to write:
>> builder.raku --verbose compile
>> Its not possible to write
>> builder.raku compile --verbose.
>> That is not intuitive, at least for me because that breaks with the other
>> unix command line tools and is annoying if you have to change the script
>> call several times.
>>
>> Why is that so? And is there a workaround for that?
>> Thanks
>> Wolfgang
>>
>> On Mon, 10 Feb 2020 at 12:18, Timo Paulssen  wrote:
>>
>>> Hi Paul and Todd,
>>>
>>> just a little extra info: the limitation for nameds to come after
>>> positionals is only for declarations of signatures.
>>>
>>> Usage of subs/methods as well as capture literals (which you don't use
>>> often, i imagine, so feel free to disregard) allow you to mix nameds and
>>> positionals freely; it will handle named parameters that are put between
>>> positionals as if they were after the positional parameters.
>>>
>>> > sub abcdefg($b, $f, $g, :$a, :$c, :$e) { say $a, $b, $c, $e }
>>> &abcdefg
>>> > abcdefg(1, a => 5, 2, c => 99, 100, e => 1024)
>>> 51991024
>>>
>>> Most cases where I wanted named parameters early in the call was when
>>> there was something big in the call, for example if a sub takes a block and
>>> a few options, i prefer to put the options before the block, so they are
>>> visible at a glance rather than after scrolling. I suppose this mirrors how
>>> regex modifiers (like :ignorecase / :i, :global, etc) have been moved to
>>> the front of regexes.
>>>
>>> Hope that's interesting
>>>   - Timo
>>> On 10/02/2020 07:48, Paul Procacci wrote:
>>>
>>> Named parameters must come after all positional parameters.
>>> Your example subroutine is invalid for this reason, while the following
>>> would be fine:
>>>
>>> sub abcdefg( $b, $f, $g, :$a, :$c, :$e)
>>>
>>> abcdefg("position1", "position2", "position3", :e("named_e"),
>>> :a("named_a"), :c("named_c"));
>>>
>>>
>>>
>>> On Sun, Feb 9, 2020 at 6:24 PM ToddAndMargo via perl6-users <
>>> perl6-us...@perl.org> wrote:
>>>
 On 2020-02-09 14:53, Paul Procacci wrote:
 > subchdir(IO() $path, :$d=True, :$r, :$w, :$x-->IO::Path:D)

 Hi Paul,

 What I wanted to see is how something liek

 sub abcdefg( :$a, $b, :$c, :$e, $f, $g )

 would be called

 -T

>>>
>>>
>>> --
>>> __
>>>
>>> :(){ :|:& };:
>>>
>>>


Re: Question about Blob and Buf

2020-02-11 Thread Kevin Pye
~ works fine for concatenating Bufs; For example:

my $a = Buf.new(1,2,3);
my $b = $a ~ Buf.new(4,5,6)

will assign correctly to $b.

I can't work out what the problem is here, despite trying various
combinations. Perhaps socket isn't really returning a Blob?

Kevin.

On Tue, 11 Feb 2020 at 21:01, JJ Merelo  wrote:

> You are using ~, which stringifies. Bufs are not strings: you need to
> decode them to concatenate it to a string. If what you want is to
> concatenate the buffer, probably ,= will work (not sure about this, would
> have to check), or any other operator that works on Positionals.
>
> JJ
>
> El mar., 11 feb. 2020 a las 10:56, David Santiago ()
> escribió:
>
>> A 11 de fevereiro de 2020 10:47:34 CET, David Santiago <
>> deman...@gmail.com> escreveu:
>> >A 11 de fevereiro de 2020 09:46:06 CET, David Santiago <
>> deman...@gmail.com> escreveu:
>> >>
>> >>Hi!
>> >>
>> >>Can someone explain me why this doesn't work:
>> >>
>> >>my Blob $read;
>> >>$read ~= $socket.read(1024);
>> >>
>> >>Dies with error:
>> >>
>> >>X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
>> method on it
>> >>
>> >>This also doesn't work:
>> >>
>> >>my Buf $read;
>> >>$read ~= $socket.read(1024);
>> >>
>> >>Dies with the same error as above.
>> >>
>> >>
>> >>But this works?
>> >>
>> >>my Blob $read = Buf.new;
>> >>$read ~= $socket.read(1024);
>> >>
>> >>
>> >>Best regards,
>> >>David Santiago
>> >
>> >
>> >Hi!
>> >
>> >Can someone explain me why this doesn't work:
>> >
>> >my Blob $read;
>> >$read ~= $socket.read(1024);
>> >
>> >Dies with error:
>> >
>> >X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
>> method on it
>> >
>> >This also doesn't work:
>> >
>> >my Buf $read;
>> >$read ~= $socket.read(1024);
>> >
>> >Dies with the same error as above.
>> >
>> >
>> >But this works?
>> >
>> >my Blob $read = Buf.new;
>> >$read ~= $socket.read(1024);
>> >
>> >
>> >Best regards,
>> >David Santiago
>>
>>
>> Hi!
>>
>> Can someone explain me why this doesn't work:
>>
>> my Blob $read;
>> $read ~= $socket.read(1024);
>>
>> Dies with error:
>>
>> X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
>> method on it
>>
>> This also doesn't work:
>>
>> my Buf $read;
>> $read ~= $socket.read(1024);
>>
>> Dies with the same error as above.
>>
>>
>> But this works?
>>
>> my Blob $read = Buf.new;
>> $read ~= $socket.read(1024);
>>
>>
>> Best regards,
>> David Santiago
>>
>> --
>> Sent from my Android device with K-9 Mail. Please excuse my brevity.
>>
>
>
> --
> JJ
>


Re: Question about Blob and Buf

2020-02-11 Thread Simon Proctor
I think the problem is IO::Socket.read() returns a Blob not a Buf.

~ has a Buf, Buf variant : https://docs.raku.org/language/operators#infix_~

But not a Blob one. Buf does Blob but not vice versa.

I think you need to transform the output from .read into a Buf if you want
to use the ~= how you want to.

Would this work?
my Blob $read = Buf.new;
$read ~= Buf.new( $socket.read(1024) );


On Tue, 11 Feb 2020 at 10:46, Kevin Pye  wrote:

>
> ~ works fine for concatenating Bufs; For example:
>
> my $a = Buf.new(1,2,3);
> my $b = $a ~ Buf.new(4,5,6)
>
> will assign correctly to $b.
>
> I can't work out what the problem is here, despite trying various
> combinations. Perhaps socket isn't really returning a Blob?
>
> Kevin.
>
> On Tue, 11 Feb 2020 at 21:01, JJ Merelo  wrote:
>
>> You are using ~, which stringifies. Bufs are not strings: you need to
>> decode them to concatenate it to a string. If what you want is to
>> concatenate the buffer, probably ,= will work (not sure about this, would
>> have to check), or any other operator that works on Positionals.
>>
>> JJ
>>
>> El mar., 11 feb. 2020 a las 10:56, David Santiago ()
>> escribió:
>>
>>> A 11 de fevereiro de 2020 10:47:34 CET, David Santiago <
>>> deman...@gmail.com> escreveu:
>>> >A 11 de fevereiro de 2020 09:46:06 CET, David Santiago <
>>> deman...@gmail.com> escreveu:
>>> >>
>>> >>Hi!
>>> >>
>>> >>Can someone explain me why this doesn't work:
>>> >>
>>> >>my Blob $read;
>>> >>$read ~= $socket.read(1024);
>>> >>
>>> >>Dies with error:
>>> >>
>>> >>X::Buf::AsStr: Cannot use a Buf as a string, but you called the
>>> Stringy method on it
>>> >>
>>> >>This also doesn't work:
>>> >>
>>> >>my Buf $read;
>>> >>$read ~= $socket.read(1024);
>>> >>
>>> >>Dies with the same error as above.
>>> >>
>>> >>
>>> >>But this works?
>>> >>
>>> >>my Blob $read = Buf.new;
>>> >>$read ~= $socket.read(1024);
>>> >>
>>> >>
>>> >>Best regards,
>>> >>David Santiago
>>> >
>>> >
>>> >Hi!
>>> >
>>> >Can someone explain me why this doesn't work:
>>> >
>>> >my Blob $read;
>>> >$read ~= $socket.read(1024);
>>> >
>>> >Dies with error:
>>> >
>>> >X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
>>> method on it
>>> >
>>> >This also doesn't work:
>>> >
>>> >my Buf $read;
>>> >$read ~= $socket.read(1024);
>>> >
>>> >Dies with the same error as above.
>>> >
>>> >
>>> >But this works?
>>> >
>>> >my Blob $read = Buf.new;
>>> >$read ~= $socket.read(1024);
>>> >
>>> >
>>> >Best regards,
>>> >David Santiago
>>>
>>>
>>> Hi!
>>>
>>> Can someone explain me why this doesn't work:
>>>
>>> my Blob $read;
>>> $read ~= $socket.read(1024);
>>>
>>> Dies with error:
>>>
>>> X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
>>> method on it
>>>
>>> This also doesn't work:
>>>
>>> my Buf $read;
>>> $read ~= $socket.read(1024);
>>>
>>> Dies with the same error as above.
>>>
>>>
>>> But this works?
>>>
>>> my Blob $read = Buf.new;
>>> $read ~= $socket.read(1024);
>>>
>>>
>>> Best regards,
>>> David Santiago
>>>
>>> --
>>> Sent from my Android device with K-9 Mail. Please excuse my brevity.
>>>
>>
>>
>> --
>> JJ
>>
>

-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: Question about Blob and Buf

2020-02-11 Thread Simon Proctor
Ok I 100% don't know after trying this out :

my Buf $a = Buf.new(1,2,3);
my Blob $b = Blob.new(4,5,6);
$a ~= $b;
say $a

And it worked fine so... I dunno.


On Tue, 11 Feb 2020 at 11:00, Simon Proctor  wrote:

> I think the problem is IO::Socket.read() returns a Blob not a Buf.
>
> ~ has a Buf, Buf variant :
> https://docs.raku.org/language/operators#infix_~
>
> But not a Blob one. Buf does Blob but not vice versa.
>
> I think you need to transform the output from .read into a Buf if you want
> to use the ~= how you want to.
>
> Would this work?
> my Blob $read = Buf.new;
> $read ~= Buf.new( $socket.read(1024) );
>
>
> On Tue, 11 Feb 2020 at 10:46, Kevin Pye  wrote:
>
>>
>> ~ works fine for concatenating Bufs; For example:
>>
>> my $a = Buf.new(1,2,3);
>> my $b = $a ~ Buf.new(4,5,6)
>>
>> will assign correctly to $b.
>>
>> I can't work out what the problem is here, despite trying various
>> combinations. Perhaps socket isn't really returning a Blob?
>>
>> Kevin.
>>
>> On Tue, 11 Feb 2020 at 21:01, JJ Merelo  wrote:
>>
>>> You are using ~, which stringifies. Bufs are not strings: you need to
>>> decode them to concatenate it to a string. If what you want is to
>>> concatenate the buffer, probably ,= will work (not sure about this, would
>>> have to check), or any other operator that works on Positionals.
>>>
>>> JJ
>>>
>>> El mar., 11 feb. 2020 a las 10:56, David Santiago ()
>>> escribió:
>>>
 A 11 de fevereiro de 2020 10:47:34 CET, David Santiago <
 deman...@gmail.com> escreveu:
 >A 11 de fevereiro de 2020 09:46:06 CET, David Santiago <
 deman...@gmail.com> escreveu:
 >>
 >>Hi!
 >>
 >>Can someone explain me why this doesn't work:
 >>
 >>my Blob $read;
 >>$read ~= $socket.read(1024);
 >>
 >>Dies with error:
 >>
 >>X::Buf::AsStr: Cannot use a Buf as a string, but you called the
 Stringy method on it
 >>
 >>This also doesn't work:
 >>
 >>my Buf $read;
 >>$read ~= $socket.read(1024);
 >>
 >>Dies with the same error as above.
 >>
 >>
 >>But this works?
 >>
 >>my Blob $read = Buf.new;
 >>$read ~= $socket.read(1024);
 >>
 >>
 >>Best regards,
 >>David Santiago
 >
 >
 >Hi!
 >
 >Can someone explain me why this doesn't work:
 >
 >my Blob $read;
 >$read ~= $socket.read(1024);
 >
 >Dies with error:
 >
 >X::Buf::AsStr: Cannot use a Buf as a string, but you called the
 Stringy method on it
 >
 >This also doesn't work:
 >
 >my Buf $read;
 >$read ~= $socket.read(1024);
 >
 >Dies with the same error as above.
 >
 >
 >But this works?
 >
 >my Blob $read = Buf.new;
 >$read ~= $socket.read(1024);
 >
 >
 >Best regards,
 >David Santiago


 Hi!

 Can someone explain me why this doesn't work:

 my Blob $read;
 $read ~= $socket.read(1024);

 Dies with error:

 X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
 method on it

 This also doesn't work:

 my Buf $read;
 $read ~= $socket.read(1024);

 Dies with the same error as above.


 But this works?

 my Blob $read = Buf.new;
 $read ~= $socket.read(1024);


 Best regards,
 David Santiago

 --
 Sent from my Android device with K-9 Mail. Please excuse my brevity.

>>>
>>>
>>> --
>>> JJ
>>>
>>
>
> --
> Simon Proctor
> Cognoscite aliquid novum cotidie
>
> http://www.khanate.co.uk/
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: Question about Blob and Buf

2020-02-11 Thread David Santiago
A 11 de fevereiro de 2020 12:03:19 CET, Simon Proctor  
escreveu:
>Ok I 100% don't know after trying this out :
>
>my Buf $a = Buf.new(1,2,3);
>my Blob $b = Blob.new(4,5,6);
>$a ~= $b;
>say $a
>
>And it worked fine so... I dunno.
>
>
>On Tue, 11 Feb 2020 at 11:00, Simon Proctor  wrote:
>
>> I think the problem is IO::Socket.read() returns a Blob not a Buf.
>>
>> ~ has a Buf, Buf variant :
>> https://docs.raku.org/language/operators#infix_~
>>
>> But not a Blob one. Buf does Blob but not vice versa.
>>
>> I think you need to transform the output from .read into a Buf if you want
>> to use the ~= how you want to.
>>
>> Would this work?
>> my Blob $read = Buf.new;
>> $read ~= Buf.new( $socket.read(1024) );
>>
>>
>> On Tue, 11 Feb 2020 at 10:46, Kevin Pye  wrote:
>>
>>>
>>> ~ works fine for concatenating Bufs; For example:
>>>
>>> my $a = Buf.new(1,2,3);
>>> my $b = $a ~ Buf.new(4,5,6)
>>>
>>> will assign correctly to $b.
>>>
>>> I can't work out what the problem is here, despite trying various
>>> combinations. Perhaps socket isn't really returning a Blob?
>>>
>>> Kevin.
>>>
>>> On Tue, 11 Feb 2020 at 21:01, JJ Merelo  wrote:
>>>
 You are using ~, which stringifies. Bufs are not strings: you need to
 decode them to concatenate it to a string. If what you want is to
 concatenate the buffer, probably ,= will work (not sure about this, would
 have to check), or any other operator that works on Positionals.

 JJ

 El mar., 11 feb. 2020 a las 10:56, David Santiago ()
 escribió:

> A 11 de fevereiro de 2020 10:47:34 CET, David Santiago <
> deman...@gmail.com> escreveu:
> >A 11 de fevereiro de 2020 09:46:06 CET, David Santiago <
> deman...@gmail.com> escreveu:
> >>
> >>Hi!
> >>
> >>Can someone explain me why this doesn't work:
> >>
> >>my Blob $read;
> >>$read ~= $socket.read(1024);
> >>
> >>Dies with error:
> >>
> >>X::Buf::AsStr: Cannot use a Buf as a string, but you called the
> Stringy method on it
> >>
> >>This also doesn't work:
> >>
> >>my Buf $read;
> >>$read ~= $socket.read(1024);
> >>
> >>Dies with the same error as above.
> >>
> >>
> >>But this works?
> >>
> >>my Blob $read = Buf.new;
> >>$read ~= $socket.read(1024);
> >>
> >>
> >>Best regards,
> >>David Santiago
> >
> >
> >Hi!
> >
> >Can someone explain me why this doesn't work:
> >
> >my Blob $read;
> >$read ~= $socket.read(1024);
> >
> >Dies with error:
> >
> >X::Buf::AsStr: Cannot use a Buf as a string, but you called the
> Stringy method on it
> >
> >This also doesn't work:
> >
> >my Buf $read;
> >$read ~= $socket.read(1024);
> >
> >Dies with the same error as above.
> >
> >
> >But this works?
> >
> >my Blob $read = Buf.new;
> >$read ~= $socket.read(1024);
> >
> >
> >Best regards,
> >David Santiago
>
>
> Hi!
>
> Can someone explain me why this doesn't work:
>
> my Blob $read;
> $read ~= $socket.read(1024);
>
> Dies with error:
>
> X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
> method on it
>
> This also doesn't work:
>
> my Buf $read;
> $read ~= $socket.read(1024);
>
> Dies with the same error as above.
>
>
> But this works?
>
> my Blob $read = Buf.new;
> $read ~= $socket.read(1024);
>
>
> Best regards,
> David Santiago
>
> --
> Sent from my Android device with K-9 Mail. Please excuse my brevity.
>


 --
 JJ

>>>
>>
>> --
>> Simon Proctor
>> Cognoscite aliquid novum cotidie
>>
>> http://www.khanate.co.uk/
>>
>
>

Hi!

I'm still confused.
The read returns a blob, and ~ can be used with strings and Buf. I get this.

>my Blob $read = Buf.new

Does  this means that Blob will do Buf role as well?

>my Buf $a = Buf.new(1,2,3);
>my Blob $b = Blob.new(4,5,6);
>$a ~= $b;

Since this is allowed, does it means that Blob does Buf role by being 
coerced(?) as well? But then shouldn't this be allowed as well?

>my Blob $read;
>$read ~= $socket.read(1024)

Best regards,
David Santiago


-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


Re: How do I contact the moderator?

2020-02-11 Thread ToddAndMargo via perl6-users

On 2020-02-11 01:03, ToddAndMargo via perl6-users wrote:

On 2020-02-11 00:44, Shlomi Fish wrote:

Hi Todd,

On Mon, 10 Feb 2020 19:25:50 -0800
ToddAndMargo via perl6-users  wrote:


Hi All,

I have been getting a strange eMail on this group.
How do I contact the moderator to check and see
if it is a scam?



I think you should send an email to perl6-users-ow...@perl.org .


Many thanks,
-T


Thank you!


That was it.  It created an automatic trouble ticket.


Re: Question about Blob and Buf

2020-02-11 Thread Timo Paulssen
On 11/02/2020 10:56, David Santiago wrote:
> Hi!
>
> Can someone explain me why this doesn't work:
>
> my Blob $read;
> $read ~= $socket.read(1024);
>
> Dies with error:
>
> X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy 
> method on it
>
> This also doesn't work:
>
> my Buf $read;
> $read ~= $socket.read(1024);
>
> Dies with the same error as above.
>
>
> But this works?
>
> my Blob $read = Buf.new;
> $read ~= $socket.read(1024);
>
>
> Best regards,
> David Santiago


Hi David,

the important difference is that in the first two examples $read
contains an undefined object, either Blob or Buf. In the last one it
contains an instance.

The operator ~= uses the one-argument form of ~ to build an initial
value to calculate with. The reason is that with *= you want to start
with 1, but with += you want to start with 0, and so on.

However, ~ being called with no options doesn't realize you really want
a Buf or Blob, it just gives the empty string by default, and then the
next thing that happens is you get "" ~ $socket.read(1024) and that
complains that you're mixing strings and bufs.

I'm not sure if there is a good solution for inside rakudo or the raku
language. Setting an initial value for the variable is one correct way
to do this, though.

Hope that helps!
  - Timo


Re: Question about Blob and Buf

2020-02-11 Thread David Santiago


Awesome explanation! Thank you!

BTW, 
> my Blob $read = Buf.new;

Is it creating either a Blob or a Buf?

Regards,
David Santiago


-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


Re: Question about Blob and Buf

2020-02-11 Thread Timo Paulssen
On 11/02/2020 14:14, David Santiago wrote:
> Awesome explanation! Thank you!
>
> BTW, 
>> my Blob $read = Buf.new;
> Is it creating either a Blob or a Buf?
>
> Regards,
> David Santiago


Hi David,

"my Blob $read" will define the variable $read to 1) only accept things
that typecheck against Blob, and 2) has the starting value of Blob (the
Blob type object). Assigning Buf.new to it will assign the newly created
Buf object to the variable, because a Buf Is-A Blob (by the liskov
substitution principle, everywhere you can use a Blob, you can also use
a Buf, but not the other way around).

BTW, assigning to a variable with a % or @ sigil behaves differently.
That is called "list assignment" and will actually use whatever type the
% or @ variable is defined to use (Hash and Array by default) and store
the values from the right-hand side of the assignment into the existing
object. This is why "my %foo = SetHash.new()" will result in a
Hash. For this example, you would want "my %foo is SetHash = "
instead.

Hope that clears things up
  - Timo


Re: Question about Blob and Buf

2020-02-11 Thread Brad Gilbert
The problem is that you are using ~ with an uninitialized Buf/Blob

my Buf $read;
$read ~ Buf.new;
# Use of uninitialized value element of type Buf in string context.

Note that it is not complaining about it being a Buf. It is complaining
about it being uninitialized.

If you initialize it then it works just fine.

my Buf $read .= new;
$read ~ Buf.new;

It will also work with ~=

my Buf $read .= new;
$read ~= Buf.new( 'a'.ord, 'b'.ord );
$read ~= Blob.new( 'c'.ord, 'd'.ord );
say $read.decode; # abcd

It also works with Blob, but you may not want to do that if you plan on
modifying the contents with something like `.subbuf-rw()`.

On Tue, Feb 11, 2020 at 3:56 AM David Santiago  wrote:

> A 11 de fevereiro de 2020 10:47:34 CET, David Santiago 
> escreveu:
> >A 11 de fevereiro de 2020 09:46:06 CET, David Santiago <
> deman...@gmail.com> escreveu:
> >>
> >>Hi!
> >>
> >>Can someone explain me why this doesn't work:
> >>
> >>my Blob $read;
> >>$read ~= $socket.read(1024);
> >>
> >>Dies with error:
> >>
> >>X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
> method on it
> >>
> >>This also doesn't work:
> >>
> >>my Buf $read;
> >>$read ~= $socket.read(1024);
> >>
> >>Dies with the same error as above.
> >>
> >>
> >>But this works?
> >>
> >>my Blob $read = Buf.new;
> >>$read ~= $socket.read(1024);
> >>
> >>
> >>Best regards,
> >>David Santiago
> >
> >
> >Hi!
> >
> >Can someone explain me why this doesn't work:
> >
> >my Blob $read;
> >$read ~= $socket.read(1024);
> >
> >Dies with error:
> >
> >X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
> method on it
> >
> >This also doesn't work:
> >
> >my Buf $read;
> >$read ~= $socket.read(1024);
> >
> >Dies with the same error as above.
> >
> >
> >But this works?
> >
> >my Blob $read = Buf.new;
> >$read ~= $socket.read(1024);
> >
> >
> >Best regards,
> >David Santiago
>
>
> Hi!
>
> Can someone explain me why this doesn't work:
>
> my Blob $read;
> $read ~= $socket.read(1024);
>
> Dies with error:
>
> X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
> method on it
>
> This also doesn't work:
>
> my Buf $read;
> $read ~= $socket.read(1024);
>
> Dies with the same error as above.
>
>
> But this works?
>
> my Blob $read = Buf.new;
> $read ~= $socket.read(1024);
>
>
> Best regards,
> David Santiago
>
> --
> Sent from my Android device with K-9 Mail. Please excuse my brevity.
>


Re: variable as subroutine?

2020-02-11 Thread Andy Bach
I have a few less related questions
>> those are 3 ways to write the same sub:

sub foo ($x) { $x * $x }
my &foo = -> $x { $x * $x }
my &foo = * * *;

> A Note on Marc's comment:
my &foo = * * *
is not the same as:
my &foo = -> $x { $x * $x }
it is the same  as:
my &foo = -> $x, $y { $x * $y }

Okay, "* * *" - how does that work?  How is it different than
-> $x { $x * $x }
?  It needs two params?

I followed the callable link but that left me with more questions:

method CALL-ME
method CALL-ME(Callable:D $self: |arguments)
This method is required for postfix:«( )» and postfix:«.( )». It's what makes 
an object actually call-able and needs to be overloaded to let a given object 
act like a routine. If the object needs to be stored in a &-sigiled container, 
is has to implement Callable.

class A does Callable {
submethod CALL-ME(|c){ 'called' }
}
my &a = A;
say a(); # OUTPUT: «called␤»

That second "postfix" operator, means
say a.();  # also outputs "called"

but what is the "pipe c" signature doing for the submethod?

From: Simon Proctor 
Sent: Tuesday, February 11, 2020 3:17 AM
To: ToddAndMargo 
Cc: perl6-users 
Subject: Re: variable as subroutine?

If you can store a subroutine in a variable then you can pass said subroutine 
to another one as an argument.

This leads us into the joys of functional programming.

And you may have used it already and not even realised.

The .map and .grep methods (and .reduce and bunch of others) all expect a 
callable code block (that might be a subroutine) as a function.

This :

my @a = (1..10).map( * ** 2 )

and this :

my &sq = sub ($v) { $v ** 2 };
my @a = (1..10).map( &sq );

are doing the same thing. Except the second one has the &sq function available 
for other things.

(A Note on Marc's comment * * * is not the same as -> $x { $x * $x } it is the 
same  as -> $x, $y { $x * $y } )

You can then start doing things like storing functions as values in hashes and 
doing all *kinds* of fun stuff.

Welcome to the tip of the iceberg.

Simon


On Tue, 11 Feb 2020 at 03:21, ToddAndMargo via perl6-users 
mailto:perl6-us...@perl.org>> wrote:
Hi All,

Is Larry using his magic powder again?

Can I declare a subroutine as a variable?

 my $abc = my sub (UInt $u, Str $s, Int $I) {

How would I use it?

And why would do such a thing?

-T


--
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: variable as subroutine?

2020-02-11 Thread Simon Proctor
The * * * call generates a WhateverCode block. This is expecting 2
arguments.

-> $x { $x * $x } is taking one argument.

The best documentation would probably be :
https://docs.raku.org/type/Whatever

Hope that helps.

(For giggles earlier I made this dumb example of functional programming)


my &ident = {$_};
my &sq = {$_ * $_};
sub trinar( &test, &true, &false, *@values ) { @values.map( -> $v {
&test($v) ?? &true($v) !! &false($v) } ) };
trinar( *.is-prime, &sq,&ident, ^30 ).say

Enjoy. ;)

On Tue, 11 Feb 2020 at 15:22, Andy Bach  wrote:

> I have a few less related questions
> >> those are 3 ways to write the same sub:
>
> sub foo ($x) { $x * $x }
> my &foo = -> $x { $x * $x }
> my &foo = * * *;
>
> > A Note on Marc's comment:
> my &foo = * * *
> is not the same as:
> my &foo = -> $x { $x * $x }
> it is the same  as:
> my &foo = -> $x, $y { $x * $y }
>
> Okay, "* * *" - how does that work?  How is it different than
> -> $x { $x * $x }
> ?  It needs two params?
>
> I followed the callable link but that left me with more questions:
>
> method CALL-ME
> method CALL-ME(Callable:D $self: |arguments)
> This method is required for postfix:«( )» and postfix:«.( )». It's what
> makes an object actually call-able and needs to be overloaded to let a
> given object act like a routine. If the object needs to be stored in a
> &-sigiled container, is has to implement Callable.
>
> class A does Callable {
> submethod CALL-ME(|c){ 'called' }
> }
> my &a = A;
> say a(); # OUTPUT: «called␤»
>
> That second "postfix" operator, means
> say a.();  # also outputs "called"
>
> but what is the "pipe c" signature doing for the submethod?
> --
> *From:* Simon Proctor 
> *Sent:* Tuesday, February 11, 2020 3:17 AM
> *To:* ToddAndMargo 
> *Cc:* perl6-users 
> *Subject:* Re: variable as subroutine?
>
> If you can store a subroutine in a variable then you can pass said
> subroutine to another one as an argument.
>
> This leads us into the joys of functional programming.
>
> And you may have used it already and not even realised.
>
> The .map and .grep methods (and .reduce and bunch of others) all expect a
> callable code block (that might be a subroutine) as a function.
>
> This :
>
> my @a = (1..10).map( * ** 2 )
>
> and this :
>
> my &sq = sub ($v) { $v ** 2 };
> my @a = (1..10).map( &sq );
>
> are doing the same thing. Except the second one has the &sq function
> available for other things.
>
> (A Note on Marc's comment * * * is not the same as -> $x { $x * $x } it is
> the same  as -> $x, $y { $x * $y } )
>
> You can then start doing things like storing functions as values in hashes
> and doing all *kinds* of fun stuff.
>
> Welcome to the tip of the iceberg.
>
> Simon
>
>
> On Tue, 11 Feb 2020 at 03:21, ToddAndMargo via perl6-users <
> perl6-us...@perl.org> wrote:
>
> Hi All,
>
> Is Larry using his magic powder again?
>
> Can I declare a subroutine as a variable?
>
>  my $abc = my sub (UInt $u, Str $s, Int $I) {
>
> How would I use it?
>
> And why would do such a thing?
>
> -T
>
>
>
> --
> Simon Proctor
> Cognoscite aliquid novum cotidie
>
> http://www.khanate.co.uk/
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: Question about Blob and Buf

2020-02-11 Thread David Santiago
Hi Timo,

Thanks for the answer:

> the liskov substitution principle
I didn't knew about this principle. I'm now going down the rabbit hole.
Is this always the case for all the derived classes in Raku?

Best regards,
David Santiago

Timo Paulssen  escreveu no dia terça, 11/02/2020 à(s) 13:32:
>
> On 11/02/2020 14:14, David Santiago wrote:
> > Awesome explanation! Thank you!
> >
> > BTW,
> >> my Blob $read = Buf.new;
> > Is it creating either a Blob or a Buf?
> >
> > Regards,
> > David Santiago
>
>
> Hi David,
>
> "my Blob $read" will define the variable $read to 1) only accept things
> that typecheck against Blob, and 2) has the starting value of Blob (the
> Blob type object). Assigning Buf.new to it will assign the newly created
> Buf object to the variable, because a Buf Is-A Blob (by the liskov
> substitution principle, everywhere you can use a Blob, you can also use
> a Buf, but not the other way around).
>
> BTW, assigning to a variable with a % or @ sigil behaves differently.
> That is called "list assignment" and will actually use whatever type the
> % or @ variable is defined to use (Hash and Array by default) and store
> the values from the right-hand side of the assignment into the existing
> object. This is why "my %foo = SetHash.new()" will result in a
> Hash. For this example, you would want "my %foo is SetHash = "
> instead.
>
> Hope that clears things up
>   - Timo
>


Re: variable as subroutine?

2020-02-11 Thread Andy Bach
>The * * * call generates a WhateverCode block. This is expecting 2 arguments.

-> $x { $x * $x } is taking one argument.

> The best documentation would probably be : https://docs.raku.org/type/Whatever

so, from:
Multiple * in one expression generate closures with as many arguments:

my $c = * + *;  # same as   -> $x, $y { $x + $y }
Using * in complex expressions will also generate closures:

my $c = 4 * * + 5;  # same as   -> $x { 4 * $x + 5 }

The * *  * the parser says "one whatever, one math op (*) and one more whatever"
my $foo =  $x, $y { $x + $y };

so,
my $foo = *  **2;
should do $x * $x? Though I see

> my $foo = * **2;
{ ... }
say foo(4);
===SORRY!=== Error while compiling:
Undeclared routine:
foo used at line 1

but '&' works
> my &foo = * **2;
{ ... }
> foo(4);
16
> my &c = * **2;
{ ... }
> say c(4);
16






From: Simon Proctor 
Sent: Tuesday, February 11, 2020 9:27 AM
To: Andy Bach 
Cc: perl6-users 
Subject: Re: variable as subroutine?

The * * * call generates a WhateverCode block. This is expecting 2 arguments.

-> $x { $x * $x } is taking one argument.

The best documentation would probably be : https://docs.raku.org/type/Whatever

Hope that helps.

(For giggles earlier I made this dumb example of functional programming)


my &ident = {$_};
my &sq = {$_ * $_};
sub trinar( &test, &true, &false, *@values ) { @values.map( -> $v { &test($v) 
?? &true($v) !! &false($v) } ) };
trinar( *.is-prime, &sq,&ident, ^30 ).say

Enjoy. ;)

On Tue, 11 Feb 2020 at 15:22, Andy Bach 
mailto:andy_b...@wiwb.uscourts.gov>> wrote:
I have a few less related questions
>> those are 3 ways to write the same sub:

sub foo ($x) { $x * $x }
my &foo = -> $x { $x * $x }
my &foo = * * *;

> A Note on Marc's comment:
my &foo = * * *
is not the same as:
my &foo = -> $x { $x * $x }
it is the same  as:
my &foo = -> $x, $y { $x * $y }

Okay, "* * *" - how does that work?  How is it different than
-> $x { $x * $x }
?  It needs two params?

I followed the callable link but that left me with more questions:

method CALL-ME
method CALL-ME(Callable:D $self: |arguments)
This method is required for postfix:«( )» and postfix:«.( )». It's what makes 
an object actually call-able and needs to be overloaded to let a given object 
act like a routine. If the object needs to be stored in a &-sigiled container, 
is has to implement Callable.

class A does Callable {
submethod CALL-ME(|c){ 'called' }
}
my &a = A;
say a(); # OUTPUT: «called␤»

That second "postfix" operator, means
say a.();  # also outputs "called"

but what is the "pipe c" signature doing for the submethod?

From: Simon Proctor mailto:simon.proc...@gmail.com>>
Sent: Tuesday, February 11, 2020 3:17 AM
To: ToddAndMargo mailto:toddandma...@zoho.com>>
Cc: perl6-users mailto:perl6-us...@perl.org>>
Subject: Re: variable as subroutine?

If you can store a subroutine in a variable then you can pass said subroutine 
to another one as an argument.

This leads us into the joys of functional programming.

And you may have used it already and not even realised.

The .map and .grep methods (and .reduce and bunch of others) all expect a 
callable code block (that might be a subroutine) as a function.

This :

my @a = (1..10).map( * ** 2 )

and this :

my &sq = sub ($v) { $v ** 2 };
my @a = (1..10).map( &sq );

are doing the same thing. Except the second one has the &sq function available 
for other things.

(A Note on Marc's comment * * * is not the same as -> $x { $x * $x } it is the 
same  as -> $x, $y { $x * $y } )

You can then start doing things like storing functions as values in hashes and 
doing all *kinds* of fun stuff.

Welcome to the tip of the iceberg.

Simon


On Tue, 11 Feb 2020 at 03:21, ToddAndMargo via perl6-users 
mailto:perl6-us...@perl.org>> wrote:
Hi All,

Is Larry using his magic powder again?

Can I declare a subroutine as a variable?

 my $abc = my sub (UInt $u, Str $s, Int $I) {

How would I use it?

And why would do such a thing?

-T


--
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


--
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: variable as subroutine?

2020-02-11 Thread Aureliano Guedes
Sorry, I sent my answer just for you.

So, the problem is you didn't call the same var you had declared.

my $foo = * **2;

Then you call

foo(2).say

Missing the $
Try:

$foo(2).say

or

say $foo(2)


About the

my @a = * **2;

Your suggestion works

@a[0](2)

or

@a[0].(2)

But I would appreciate an explanation about why `$a[0](0)` didn't work.


On Tue, Feb 11, 2020 at 9:45 PM Andy Bach 
wrote:

> > I think it should be like this:
>
> > my $foo = * **2;
> { ... }
> > say $foo(4)
> 16
>
> That's what the doc says, but that's not what my install version says.  I
> do get
> > my $foo = * **2;
> { ... }
>
> but say foo get the "unknown sub" error
>
> > But I have another point::
>
> > my @a = * **2;
> > @a(2)
> Invocant of method 'CALL-ME' must be a type object of type 'List', not an
> object instance of type 'Array'.  Did you forget a 'multi'?
>   in block  at  line 1
> Yeah, I'd be surprised if that worked
>
> > $a[0](2)
> ===SORRY!=== Error while compiling:
> Variable '$a' is not declared. Did you mean '@a'?
> --> ⏏$a[0](2)
>
> raku doesn't swap sigils anymore, so it should be
> @a[0](2)
>
> maybe, pass the param, to the first bucket in @a which is holding a sub,
> so run it  - works here
> > my @a = * **2;
> [{ ... }]
> > say @a[0](4);
> 16
>
> as does ".()"
> > say @a[0].(5);
> 25
> --
> *From:* Aureliano Guedes 
> *Sent:* Tuesday, February 11, 2020 6:36 PM
> *To:* Andy Bach 
> *Subject:* Re: variable as subroutine?
>
> I think it should be like this:
>
> > my $foo = * **2;
> { ... }
> > say $foo(4)
> 16
>
> But I have another point::
>
> > my @a = * **2;
> [{ ... }]
> > @a(2)
> Invocant of method 'CALL-ME' must be a type object of type 'List', not an
> object instance of type 'Array'.  Did you forget a 'multi'?
>   in block  at  line 1
>
> > $a[0](2)
> ===SORRY!=== Error while compiling:
> Variable '$a' is not declared. Did you mean '@a'?
> --> ⏏$a[0](2)
>
>
>
> On Tue, Feb 11, 2020 at 8:43 PM Andy Bach 
> wrote:
>
> >The * * * call generates a WhateverCode block. This is expecting 2
> arguments.
>
> -> $x { $x * $x } is taking one argument.
>
> > The best documentation would probably be :
> https://docs.raku.org/type/Whatever
>
> so, from:
> Multiple * in one expression generate closures with as many arguments:
>
> my $c = * + *;  # same as   -> $x, $y { $x + $y }
> Using * in complex expressions will also generate closures:
>
> my $c = 4 * * + 5;  # same as   -> $x { 4 * $x + 5 }
>
> The * *  * the parser says "one whatever, one math op (*) and one more
> whatever"
> my $foo =  $x, $y { $x + $y };
>
> so,
> my $foo = *  **2;
> should do $x * $x? Though I see
>
> > my $foo = * **2;
> { ... }
> say foo(4);
> ===SORRY!=== Error while compiling:
> Undeclared routine:
> foo used at line 1
>
> but '&' works
> > my &foo = * **2;
> { ... }
> > foo(4);
> 16
> > my &c = * **2;
> { ... }
> > say c(4);
> 16
>
>
>
>
>
> --
> *From:* Simon Proctor 
> *Sent:* Tuesday, February 11, 2020 9:27 AM
> *To:* Andy Bach 
> *Cc:* perl6-users 
> *Subject:* Re: variable as subroutine?
>
> The * * * call generates a WhateverCode block. This is expecting 2
> arguments.
>
> -> $x { $x * $x } is taking one argument.
>
> The best documentation would probably be :
> https://docs.raku.org/type/Whatever
>
> Hope that helps.
>
> (For giggles earlier I made this dumb example of functional programming)
>
>
> my &ident = {$_};
> my &sq = {$_ * $_};
> sub trinar( &test, &true, &false, *@values ) { @values.map( -> $v {
> &test($v) ?? &true($v) !! &false($v) } ) };
> trinar( *.is-prime, &sq,&ident, ^30 ).say
>
> Enjoy. ;)
>
> On Tue, 11 Feb 2020 at 15:22, Andy Bach 
> wrote:
>
> I have a few less related questions
> >> those are 3 ways to write the same sub:
>
> sub foo ($x) { $x * $x }
> my &foo = -> $x { $x * $x }
> my &foo = * * *;
>
> > A Note on Marc's comment:
> my &foo = * * *
> is not the same as:
> my &foo = -> $x { $x * $x }
> it is the same  as:
> my &foo = -> $x, $y { $x * $y }
>
> Okay, "* * *" - how does that work?  How is it different than
> -> $x { $x * $x }
> ?  It needs two params?
>
> I followed the callable link but that left me with more questions:
>
> method CALL-ME
> method CALL-ME(Callable:D $self: |arguments)
> This method is required for postfix:«( )» and postfix:«.( )». It's what
> makes an object actually call-able and needs to be overloaded to let a
> given object act like a routine. If the object needs to be stored in a
> &-sigiled container, is has to implement Callable.
>
> class A does Callable {
> submethod CALL-ME(|c){ 'called' }
> }
> my &a = A;
> say a(); # OUTPUT: «called␤»
>
> That second "postfix" operator, means
> say a.();  # also outputs "called"
>
> but what is the "pipe c" signature doing for the submethod?
> --
> *From:* Simon Proctor 
> *Sent:* Tuesday, February 11, 2020 3:17 AM
> *To:* ToddAndMargo 
> *Cc:* perl6-users 
> *Subject:* Re: variable as subroutine?
>
> If you