Multibyte string in Windows command line

2018-09-13 Thread WFB
Hi all,

My perl6 runs an executable and prints its output. This output is printed
as multibyte string. I assume the executable gives back a multibyte string
and perl6 interpret its as one byte string for whatever reasons.
I tried Run with different encodings like windows-1251, utf16 and so on. No
luck.

The string I get looks like that:
S e t t i n g   u p   f o l d e r   C : \ U s e r s \ w o l f
Hex:
53 00 65 00 74 00 74 00 69 00 6E 00 67 00 20 00 75 00 70 00 20 00 66 00 6F
00 6C 00 64 00 65 00 72 00 20 00 43 00 3A 00 5C 00 55 00 73 00 65 00

Here my program:

my $installer = run $install-file, :out;
for $installer.out.lines -> $line {
say $line;
}

Any idea whats wrong here. A WIndows issue or do I something wrong?

Thanks for helping,
Wolfgang


Re: Multibyte string in Windows command line

2018-09-13 Thread Andreas.Mueller
  Hi Wolfgang,

  that is an Windows issue. You can see that if you pipe the output of
  your program in a textfile (from within the command interpreter: cmd.exe):

  c:\> install.exe > x.txt

  and the 'hex' your x.txt..

  A.


On 13.09.18 14:21, WFB wrote:
> Hi all,
> 
> My perl6 runs an executable and prints its output. This output is printed
> as multibyte string. I assume the executable gives back a multibyte string
> and perl6 interpret its as one byte string for whatever reasons.
> I tried Run with different encodings like windows-1251, utf16 and so on. No
> luck.
> 
> The string I get looks like that:
> S e t t i n g   u p   f o l d e r   C : \ U s e r s \ w o l f
> Hex:
> 53 00 65 00 74 00 74 00 69 00 6E 00 67 00 20 00 75 00 70 00 20 00 66 00 6F
> 00 6C 00 64 00 65 00 72 00 20 00 43 00 3A 00 5C 00 55 00 73 00 65 00
> 
> Here my program:
> 
> my $installer = run $install-file, :out;
> for $installer.out.lines -> $line {
> say $line;
> }
> 
> Any idea whats wrong here. A WIndows issue or do I something wrong?
> 
> Thanks for helping,
> Wolfgang

-- 
Andreas Müller - Raum: 35/114b - Tel: 2875


Re: Multibyte string in Windows command line

2018-09-13 Thread WFB
Thanks!

Has nothing to do with perl6. Unfortunately, I have no idea how I can "fix"
that.
At least I can Windows blame again ^^

Best,
Wolfgang

On Thu, 13 Sep 2018 at 15:21, 
wrote:

>   Hi Wolfgang,
>
>   that is an Windows issue. You can see that if you pipe the output of
>   your program in a textfile (from within the command interpreter:
> cmd.exe):
>
>   c:\> install.exe > x.txt
>
>   and the 'hex' your x.txt..
>
>   A.
>
>
> On 13.09.18 14:21, WFB wrote:
> > Hi all,
> >
> > My perl6 runs an executable and prints its output. This output is printed
> > as multibyte string. I assume the executable gives back a multibyte
> string
> > and perl6 interpret its as one byte string for whatever reasons.
> > I tried Run with different encodings like windows-1251, utf16 and so on.
> No
> > luck.
> >
> > The string I get looks like that:
> > S e t t i n g   u p   f o l d e r   C : \ U s e r s \ w o l f
> > Hex:
> > 53 00 65 00 74 00 74 00 69 00 6E 00 67 00 20 00 75 00 70 00 20 00 66 00
> 6F
> > 00 6C 00 64 00 65 00 72 00 20 00 43 00 3A 00 5C 00 55 00 73 00 65 00
> >
> > Here my program:
> >
> > my $installer = run $install-file, :out;
> > for $installer.out.lines -> $line {
> > say $line;
> > }
> >
> > Any idea whats wrong here. A WIndows issue or do I something wrong?
> >
> > Thanks for helping,
> > Wolfgang
>
> --
> Andreas Müller - Raum: 35/114b - Tel: 2875
>


Re: Multibyte string in Windows command line

2018-09-13 Thread Andreas.Mueller
  but you can solve that (quick and dirty) with perl6..
  ..delete every secound char - it is most often \0

  have fun
  A.

On 13.09.18 16:03, WFB wrote:
> Thanks!
> 
> Has nothing to do with perl6. Unfortunately, I have no idea how I can "fix"
> that.
> At least I can Windows blame again ^^
> 
> Best,
> Wolfgang
> 
> On Thu, 13 Sep 2018 at 15:21, 
> wrote:
> 
> >   Hi Wolfgang,
> >
> >   that is an Windows issue. You can see that if you pipe the output of
> >   your program in a textfile (from within the command interpreter:
> > cmd.exe):
> >
> >   c:\> install.exe > x.txt
> >
> >   and the 'hex' your x.txt..
> >
> >   A.
> >
> >
> > On 13.09.18 14:21, WFB wrote:
> > > Hi all,
> > >
> > > My perl6 runs an executable and prints its output. This output is printed
> > > as multibyte string. I assume the executable gives back a multibyte
> > string
> > > and perl6 interpret its as one byte string for whatever reasons.
> > > I tried Run with different encodings like windows-1251, utf16 and so on.
> > No
> > > luck.
> > >
> > > The string I get looks like that:
> > > S e t t i n g   u p   f o l d e r   C : \ U s e r s \ w o l f
> > > Hex:
> > > 53 00 65 00 74 00 74 00 69 00 6E 00 67 00 20 00 75 00 70 00 20 00 66 00
> > 6F
> > > 00 6C 00 64 00 65 00 72 00 20 00 43 00 3A 00 5C 00 55 00 73 00 65 00
> > >
> > > Here my program:
> > >
> > > my $installer = run $install-file, :out;
> > > for $installer.out.lines -> $line {
> > > say $line;
> > > }
> > >
> > > Any idea whats wrong here. A WIndows issue or do I something wrong?
> > >
> > > Thanks for helping,
> > > Wolfgang
> >
> > --
> > Andreas Müller - Raum: 35/114b - Tel: 2875
> >

-- 
Andreas Müller - Raum: 35/114b - Tel: 2875


Re: Multibyte string in Windows command line

2018-09-13 Thread Brad Gilbert
On Thu, Sep 13, 2018 at 7:22 AM WFB  wrote:
>
> Hi all,
>
> My perl6 runs an executable and prints its output. This output is printed as 
> multibyte string. I assume the executable gives back a multibyte string and 
> perl6 interpret its as one byte string for whatever reasons.
> I tried Run with different encodings like windows-1251, utf16 and so on. No 
> luck.
>
> The string I get looks like that:
> S e t t i n g   u p   f o l d e r   C : \ U s e r s \ w o l f
> Hex:
> 53 00 65 00 74 00 74 00 69 00 6E 00 67 00 20 00 75 00 70 00 20 00 66 00 6F 00 
> 6C 00 64 00 65 00 72 00 20 00 43 00 3A 00 5C 00 55 00 73 00 65 00
>
> Here my program:
>
> my $installer = run $install-file, :out;
> for $installer.out.lines -> $line {
> say $line;
> }
>
> Any idea whats wrong here. A WIndows issue or do I something wrong?
>

Windows uses UTF16 encoding by default (which you see here), while
Perl 6 uses UTF8 by default.

You should be able to fix it by setting the encoding
(Note that it should probably be set with :encoding, but that
doesn't work currently)

run $install-file, :out, :enc

Though I currently get an error from that.

Streaming decode NYI for encoding 4

Also I'm sure I should be able to set it after that line, but it also
produces an error

> my $installer = run $install-file, :out;
> $installer.out.encoding('utf16');
Cannot assign to an immutable value

---

A work around is to use 'latin1' (almost binary) and use `.encode.decode`

my $installer = run $install-file, :out, :enc;
for $installer.out.lines.map(*.encode('latin1').decode('utf16')) -> $line {
say $line;
}


Re: Nil ?

2018-09-13 Thread ToddAndMargo

On 09/12/2018 10:09 AM, Larry Wall wrote:

Basically, ignore any advice to treat Nil as a normal value, because
it really is intended to represent the *absence* of a value as much as
possible.  It's a bit like the way solid-state electronics treats "holes"
as if they were real particles, and gets away with it much of the time.
But not all the time, because the hole isn't real; it's the collective
behavior of everything around a thing that's missing.

So while you can test explicitly for Nil if you try hard enough, it's
better not to try at all, because lots of places internally are using
that Nil to select some kind of default behavior that might or might
not look like Nil afterwards.

It was probably a mistake to put Nil into the type hierarchy underneath
the Any type in the first place.  It's more of a concept type like
Junction, so probably belongs outside of Any, which sits the top of the
"normal" object hierarchy.

These types are deeply magical.  Whenever you find yourself trying to
use Nil or Junction as a normal value, you have to ask yourself whether
you're just Mickey Mouse falling into the Sorcerer's Apprentice trap.
Unless you're a wizard, with Nil and Junction it's better to cargo cult
a few common usages and stay the heck away the rest of the time.

Larry



Hi Larry,

Beautiful description!  Almost magical!  :-)

I will stick with .defined that you suggested in another
thread.

Thank you!

-T

--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: how do I do this index in p6?

2018-09-13 Thread ToddAndMargo

On 09/12/2018 07:14 AM, Parrot Raiser wrote:

Built-in constants:
pi, tau, e, i


Do you know where I can find the list ?

https://duckduckgo.com/?q=perl6+built+in+constants&t=ffab&ia=web

is no help


Re: how do I do this index in p6?

2018-09-13 Thread Parrot Raiser
https://docs.perl6.org/language/terms#Identifier_terms

On 9/13/18, ToddAndMargo  wrote:
> On 09/12/2018 07:14 AM, Parrot Raiser wrote:
>> Built-in constants:
>> pi, tau, e, i
>
> Do you know where I can find the list ?
>
>  https://duckduckgo.com/?q=perl6+built+in+constants&t=ffab&ia=web
>
> is no help
>


Re: Nil ?

2018-09-13 Thread Elizabeth Mattijsen
> On 13 Sep 2018, at 20:47, ToddAndMargo  wrote:
> On 09/12/2018 10:09 AM, Larry Wall wrote:
>> Basically, ignore any advice to treat Nil as a normal value, because
>> it really is intended to represent the *absence* of a value as much as
>> possible.  It's a bit like the way solid-state electronics treats "holes"
>> as if they were real particles, and gets away with it much of the time.
>> But not all the time, because the hole isn't real; it's the collective
>> behavior of everything around a thing that's missing.
>> So while you can test explicitly for Nil if you try hard enough, it's
>> better not to try at all, because lots of places internally are using
>> that Nil to select some kind of default behavior that might or might
>> not look like Nil afterwards.
>> It was probably a mistake to put Nil into the type hierarchy underneath
>> the Any type in the first place.  It's more of a concept type like
>> Junction, so probably belongs outside of Any, which sits the top of the
>> "normal" object hierarchy.
>> These types are deeply magical.  Whenever you find yourself trying to
>> use Nil or Junction as a normal value, you have to ask yourself whether
>> you're just Mickey Mouse falling into the Sorcerer's Apprentice trap.
>> Unless you're a wizard, with Nil and Junction it's better to cargo cult
>> a few common usages and stay the heck away the rest of the time.
>> Larry
> 
> Hi Larry,
> 
> Beautiful description!  Almost magical!  :-)
> 
> I will stick with .defined that you suggested in another
> thread.

Another way to deal with Nil is to use “with”, especially if you don’t need to 
do anything if the value is Nil:

with “foo”.index(“o”) -> $index {
say “Found at index $index”;
}

Documentation: 
https://docs.perl6.org/language/control#index-entry-control_flow_with_orwith_without-with%2C_orwith%2C_without

Re: how do I do this index in p6?

2018-09-13 Thread ToddAndMargo

On 09/13/2018 12:10 PM, Parrot Raiser wrote:

https://docs.perl6.org/language/terms#Identifier_terms

On 9/13/18, ToddAndMargo  wrote:

On 09/12/2018 07:14 AM, Parrot Raiser wrote:

Built-in constants:
pi, tau, e, i


Do you know where I can find the list ?

  https://duckduckgo.com/?q=perl6+built+in+constants&t=ffab&ia=web

is no help



Thank you!

What ??? What ??? No Universal Constant?  Next I will
find that there is no Gravitational Constant either!
Kids these days!

:-)

$ p6 'constant c=299792458; say c ~" metres per second";'
299792458 metres per second

Hm. Now I am wondering how to format the
commas into the say.


Re: Nil ?

2018-09-13 Thread ToddAndMargo

On 09/13/2018 12:29 PM, Elizabeth Mattijsen wrote:

On 13 Sep 2018, at 20:47, ToddAndMargo  wrote:
On 09/12/2018 10:09 AM, Larry Wall wrote:

Basically, ignore any advice to treat Nil as a normal value, because
it really is intended to represent the *absence* of a value as much as
possible.  It's a bit like the way solid-state electronics treats "holes"
as if they were real particles, and gets away with it much of the time.
But not all the time, because the hole isn't real; it's the collective
behavior of everything around a thing that's missing.
So while you can test explicitly for Nil if you try hard enough, it's
better not to try at all, because lots of places internally are using
that Nil to select some kind of default behavior that might or might
not look like Nil afterwards.
It was probably a mistake to put Nil into the type hierarchy underneath
the Any type in the first place.  It's more of a concept type like
Junction, so probably belongs outside of Any, which sits the top of the
"normal" object hierarchy.
These types are deeply magical.  Whenever you find yourself trying to
use Nil or Junction as a normal value, you have to ask yourself whether
you're just Mickey Mouse falling into the Sorcerer's Apprentice trap.
Unless you're a wizard, with Nil and Junction it's better to cargo cult
a few common usages and stay the heck away the rest of the time.
Larry


Hi Larry,

Beautiful description!  Almost magical!  :-)

I will stick with .defined that you suggested in another
thread.


Another way to deal with Nil is to use “with”, especially if you don’t need to 
do anything if the value is Nil:

with “foo”.index(“o”) -> $index {
 say “Found at index $index”;
}

Documentation: 
https://docs.perl6.org/language/control#index-entry-control_flow_with_orwith_without-with%2C_orwith%2C_without



Where I typically have to deal with Nil's is when I
am looping through something I read back from a system
call.  I never thought much of it when I was using bash,
but when you see the raw stuff ...

Not a Nil, but things read back and looped with split
can be interesting too.

$ p6 'my $x="\na\nb\nc\n"; for ( split "\n", $x ) -> $i {print "<$i>\n"};'
<>



<>

with beginning and ending new lines.


Re: Nil ?

2018-09-13 Thread Elizabeth Mattijsen
> On 13 Sep 2018, at 23:21, ToddAndMargo  wrote:
> On 09/13/2018 12:29 PM, Elizabeth Mattijsen wrote:
>>> On 13 Sep 2018, at 20:47, ToddAndMargo  wrote:
>>> On 09/12/2018 10:09 AM, Larry Wall wrote:
 Basically, ignore any advice to treat Nil as a normal value, because
 it really is intended to represent the *absence* of a value as much as
 possible.  It's a bit like the way solid-state electronics treats "holes"
 as if they were real particles, and gets away with it much of the time.
 But not all the time, because the hole isn't real; it's the collective
 behavior of everything around a thing that's missing.
 So while you can test explicitly for Nil if you try hard enough, it's
 better not to try at all, because lots of places internally are using
 that Nil to select some kind of default behavior that might or might
 not look like Nil afterwards.
 It was probably a mistake to put Nil into the type hierarchy underneath
 the Any type in the first place.  It's more of a concept type like
 Junction, so probably belongs outside of Any, which sits the top of the
 "normal" object hierarchy.
 These types are deeply magical.  Whenever you find yourself trying to
 use Nil or Junction as a normal value, you have to ask yourself whether
 you're just Mickey Mouse falling into the Sorcerer's Apprentice trap.
 Unless you're a wizard, with Nil and Junction it's better to cargo cult
 a few common usages and stay the heck away the rest of the time.
 Larry
>>> 
>>> Hi Larry,
>>> 
>>> Beautiful description!  Almost magical!  :-)
>>> 
>>> I will stick with .defined that you suggested in another
>>> thread.
>> Another way to deal with Nil is to use “with”, especially if you don’t need 
>> to do anything if the value is Nil:
>> with “foo”.index(“o”) -> $index {
>> say “Found at index $index”;
>> }
>> Documentation: 
>> https://docs.perl6.org/language/control#index-entry-control_flow_with_orwith_without-with%2C_orwith%2C_without
> 
> Where I typically have to deal with Nil's is when I
> am looping through something I read back from a system
> call.  I never thought much of it when I was using bash,
> but when you see the raw stuff ...
> 
> Not a Nil, but things read back and looped with split
> can be interesting too.
> 
> $ p6 'my $x="\na\nb\nc\n"; for ( split "\n", $x ) -> $i {print "<$i>\n"};'
> <>
> 
> 
> 
> <>
> 
> with beginning and ending new lines.

FWIW, a more Perl6ish way would be:

$ p6 'my $x="\na\nb\nc\n"; for $x.lines -> $i {print "<$i>\n"};'


Re: Multibyte string in Windows command line

2018-09-13 Thread WFB
@Andreas Thanks, I was thinking to do that with regex by myself, but that
would be a ugly workaround and only as a last resort.

@Brad: Cool, thanks, I got the errors as well. But did not come up with
your solution. One question, though:
>> for $installer.out.lines.map(*.encode('latin1').decode('utf16')) ->
$line {
Why .encode? I would assume the IO::Handle is allready given back latin-1
because of the :enc<"latin-1"> in the Run command.

On Thu, 13 Sep 2018 at 18:20, Brad Gilbert  wrote:

> On Thu, Sep 13, 2018 at 7:22 AM WFB  wrote:
> >
> > Hi all,
> >
> > My perl6 runs an executable and prints its output. This output is
> printed as multibyte string. I assume the executable gives back a multibyte
> string and perl6 interpret its as one byte string for whatever reasons.
> > I tried Run with different encodings like windows-1251, utf16 and so on.
> No luck.
> >
> > The string I get looks like that:
> > S e t t i n g   u p   f o l d e r   C : \ U s e r s \ w o l f
> > Hex:
> > 53 00 65 00 74 00 74 00 69 00 6E 00 67 00 20 00 75 00 70 00 20 00 66 00
> 6F 00 6C 00 64 00 65 00 72 00 20 00 43 00 3A 00 5C 00 55 00 73 00 65 00
> >
> > Here my program:
> >
> > my $installer = run $install-file, :out;
> > for $installer.out.lines -> $line {
> > say $line;
> > }
> >
> > Any idea whats wrong here. A WIndows issue or do I something wrong?
> >
>
> Windows uses UTF16 encoding by default (which you see here), while
> Perl 6 uses UTF8 by default.
>
> You should be able to fix it by setting the encoding
> (Note that it should probably be set with :encoding, but that
> doesn't work currently)
>
> run $install-file, :out, :enc
>
> Though I currently get an error from that.
>
> Streaming decode NYI for encoding 4
>
> Also I'm sure I should be able to set it after that line, but it also
> produces an error
>
> > my $installer = run $install-file, :out;
> > $installer.out.encoding('utf16');
> Cannot assign to an immutable value
>
> ---
>
> A work around is to use 'latin1' (almost binary) and use `.encode.decode`
>
> my $installer = run $install-file, :out, :enc;
> for $installer.out.lines.map(*.encode('latin1').decode('utf16')) ->
> $line {
> say $line;
> }
>


Re: Multibyte string in Windows command line

2018-09-13 Thread WFB
Never mind. .lines gives back Str and thus .encode is needed...
Thanks again

On Fri, 14 Sep 2018 at 06:20, WFB  wrote:

> @Andreas Thanks, I was thinking to do that with regex by myself, but that
> would be a ugly workaround and only as a last resort.
>
> @Brad: Cool, thanks, I got the errors as well. But did not come up with
> your solution. One question, though:
> >> for $installer.out.lines.map(*.encode('latin1').decode('utf16')) ->
> $line {
> Why .encode? I would assume the IO::Handle is allready given back latin-1
> because of the :enc<"latin-1"> in the Run command.
>
> On Thu, 13 Sep 2018 at 18:20, Brad Gilbert  wrote:
>
>> On Thu, Sep 13, 2018 at 7:22 AM WFB  wrote:
>> >
>> > Hi all,
>> >
>> > My perl6 runs an executable and prints its output. This output is
>> printed as multibyte string. I assume the executable gives back a multibyte
>> string and perl6 interpret its as one byte string for whatever reasons.
>> > I tried Run with different encodings like windows-1251, utf16 and so
>> on. No luck.
>> >
>> > The string I get looks like that:
>> > S e t t i n g   u p   f o l d e r   C : \ U s e r s \ w o l f
>> > Hex:
>> > 53 00 65 00 74 00 74 00 69 00 6E 00 67 00 20 00 75 00 70 00 20 00 66 00
>> 6F 00 6C 00 64 00 65 00 72 00 20 00 43 00 3A 00 5C 00 55 00 73 00 65 00
>> >
>> > Here my program:
>> >
>> > my $installer = run $install-file, :out;
>> > for $installer.out.lines -> $line {
>> > say $line;
>> > }
>> >
>> > Any idea whats wrong here. A WIndows issue or do I something wrong?
>> >
>>
>> Windows uses UTF16 encoding by default (which you see here), while
>> Perl 6 uses UTF8 by default.
>>
>> You should be able to fix it by setting the encoding
>> (Note that it should probably be set with :encoding, but that
>> doesn't work currently)
>>
>> run $install-file, :out, :enc
>>
>> Though I currently get an error from that.
>>
>> Streaming decode NYI for encoding 4
>>
>> Also I'm sure I should be able to set it after that line, but it also
>> produces an error
>>
>> > my $installer = run $install-file, :out;
>> > $installer.out.encoding('utf16');
>> Cannot assign to an immutable value
>>
>> ---
>>
>> A work around is to use 'latin1' (almost binary) and use `.encode.decode`
>>
>> my $installer = run $install-file, :out, :enc;
>> for $installer.out.lines.map(*.encode('latin1').decode('utf16')) ->
>> $line {
>> say $line;
>> }
>>
>


Re: how do I do this index in p6?

2018-09-13 Thread Todd Chester
Le jeu. 13 sept. 2018 à 23:12, ToddAndMargo > a écrit :





$ p6 'constant c=299792458; say c ~" metres per second";'
299792458 metres per second

Hm. Now I am wondering how to format the
commas into the say.





On 09/13/2018 02:43 PM, Laurent Rosenfeld wrote:

Not very pretty, but this works:

constant c = 299792458;
say c.flip.subst(/(\d**3)/, {"$0,"}, :g).flip.subst(/^\,/, "");



Oh Dude!


Re: Nil ?

2018-09-13 Thread Todd Chester




On 09/13/2018 02:24 PM, Elizabeth Mattijsen wrote:

On 13 Sep 2018, at 23:21, ToddAndMargo  wrote:



$ p6 'my $x="\na\nb\nc\n"; for ( split "\n", $x ) -> $i {print "<$i>\n"};'
<>



<>

with beginning and ending new lines.


FWIW, a more Perl6ish way would be:

$ p6 'my $x="\na\nb\nc\n"; for $x.lines -> $i {print "<$i>\n"};'



That is pretty looking.  Thank you!


Re: how do I do this index in p6?

2018-09-13 Thread Brad Gilbert
On Thu, Sep 13, 2018 at 11:52 PM Todd Chester  wrote:
>
> >> Le jeu. 13 sept. 2018 à 23:12, ToddAndMargo  >> > a écrit :
> >>
> >
> >> $ p6 'constant c=299792458; say c ~" metres per second";'
> >> 299792458 metres per second
> >>
> >> Hm. Now I am wondering how to format the
> >> commas into the say.
> >>
>
>
>
> On 09/13/2018 02:43 PM, Laurent Rosenfeld wrote:
> > Not very pretty, but this works:
> >
> > constant c = 299792458;
> > say c.flip.subst(/(\d**3)/, {"$0,"}, :g).flip.subst(/^\,/, "");
> >
>
> Oh Dude!

It's simpler to use comb and join

constant c = 299792458;
say c.flip.comb(3).join(',').flip;


Re: Please explain this to me

2018-09-13 Thread Todd Chester




On 09/11/2018 05:05 AM, Simon Proctor wrote:
Please note the Perl5 docs have had decades of people working on them 
the Perl6 ones less so. There's bound to be some difference in scope.


Hi Simon,

That you for the tutorial.  I have it tagged to read over again
really SSSLLLOOOWWLY

As for P5's and P6's documentation, I don't think it is a case of
not having a lot of time to refine things.  I think it is
difference in approach:  I think P6's expects the reader
to have developer level knowledge and P5 tries explain how
to use the function in simple terms that common users
can understand.

As I figure things out, I write my own notes.  I am closing
in on 200 of them now.  I hit them all the time.  After
a while, things sink in and I don't have to look.

After my first attempt at improving "contains" description,
I am not sure it is worth the effort.  It is my impression
that those maintaining these references will not budge.

-T


Re: Please explain this to me

2018-09-13 Thread Todd Chester




On 09/12/2018 10:34 AM, Larry Wall wrote:

On Tue, Sep 11, 2018 at 10:28:27PM -0700, ToddAndMargo wrote:
: Okay, foul!
:Str:D: Cool:D $needle
: why is there not a comma between "Str:D:" and "Cool:D"?
: And what is with the extra ":".  By chance is the extra ":"
: a confusing way of using a comma for a separator?

Well, "confusing" is kind of a value judgement, but yes, that is precisely
how the parser is parsing it, as a funny-looking kind of comma.  You could
write it "Str:D :" with a space and it would still work.

You can't just replace any old comma with a colon though.  Replacing the
comma with a colon is only allowed on the first argument, since we can
have only one invocant for the current object.  And in fact we MUST
have an invocant in a method, so if you accidentally put comma instead
of colon, the parser will assume you left the invocant out, and that
the first argument is really the second argument.  Arguably this is
"confusing" if you don't know it's going to happen, but it's a great
convenience for the vast majority of methods that don't care about the
invocant, and where the user will just refer to the invocant as "self"
if they do want to talk about it.

: "Cool:D $needle" means that sub string or number you are
: looking for.  And it is constrained.  You must enter a value.
:
: Foul again!
:Int(Cool:D) $pos
: Why "Int(Cool:D)"?  Why is type Int being redefined
: as type "Cool" (number or any type or a string).

That is the wrong direction to think about it.  Int is not being redefined
as Cool:D there.  The basic type there is just Int, and when the $pos
comes in, it will end up being a simple Int.  This syntax is called a
"coercion type", and it just says that we can also accept anything that
matches Cool:D and turn it into an Int.  But the inside of the method
knows nothing about the Cool:D part.

Think of Int(Cool:D) as the signature matcher automatically applying
the normal Int($coolthing) coercer for you to make sure you have an Int,
precisely so that you *don't* have to worry about the Cool:D part
inside the routine, but know that it simply an Int for any part
of the routine after the signature.

: $pos is the starting position to check for a match,
: start at zero.
:
: Foul!
: $pos is optional.  But there is a "D" in its definition
: making it constrained and not optional.

No, that D is not part of its definition, which is simply Int.  The D
is part of the coercion type's signature.  The coercion is only applied
if there actually an argument passed.  So Int(Cool:D) is allowed to
default to an undefine Int to indicate no value was passed.  You'd have
to write Int:D(Cool) to mean the other thing, and then yes, it couldn't
be optional.

: And another foul!
: There is no stating what the return value is.  It
: should be of single value of type Bool.

Indeed, the signature should include --> Bool to indicate that.

Larry




Hi Larry,

Thank you!

You have a gift of this kind of technical writing. You make the
complex look simple and that is no easy task.

-T


Re: Please explain this to me

2018-09-13 Thread JJ Merelo
Hi,

El vie., 14 sept. 2018 a las 7:11, Todd Chester ()
escribió:

>
>
> On 09/11/2018 05:05 AM, Simon Proctor wrote:
> > Please note the Perl5 docs have had decades of people working on them
> > the Perl6 ones less so. There's bound to be some difference in scope.
>
> Hi Simon,
>
> That you for the tutorial.  I have it tagged to read over again
> really SSSLLLOOOWWLY
>
> As for P5's and P6's documentation, I don't think it is a case of
> not having a lot of time to refine things.  I think it is
> difference in approach:  I think P6's expects the reader
> to have developer level knowledge and P5 tries explain how
> to use the function in simple terms that common users
> can understand.
>
> As I figure things out, I write my own notes.  I am closing
> in on 200 of them now.  I hit them all the time.  After
> a while, things sink in and I don't have to look.
>
> After my first attempt at improving "contains" description,
> I am not sure it is worth the effort.  It is my impression
> that those maintaining these references will not budge.
>
>
Last time I counted, there were a dozen comments and 3 commits in the issue
I created to try and improve the description. 2 files were modified by me.
That's rather a dynamic way of not budging.

Cheers

JJ


Re: how do I do this index in p6?

2018-09-13 Thread JJ Merelo
Of course, you can also use Math::Constants

use Math::Constants;

say "We are flying at speed ", .1c;


-- 
JJ


Re: Please explain this to me

2018-09-13 Thread Todd Chester




On 09/13/2018 10:24 PM, JJ Merelo wrote:
Last time I counted, there were a dozen comments and 3 commits in the 
issue I created to try and improve the description. 2 files were 
modified by me. That's rather a dynamic way of not budging.


Cheers

JJ


I wrote you off list giving you my reasoning.


Re: Please explain this to me

2018-09-13 Thread Todd Chester




On 09/12/2018 12:19 AM, Simon Proctor wrote:
In answer to "why the : between Str:D and Cool:D and why Int(Cool:D) ?" 
can I just point out the video I linked (or the slides) which answer 
both of these questions.


Hi Simon,

Larry Wall, who has a unique gift for making the complex
easy, explained it to me this way:

 On 09/12/2018 10:34 AM, Larry Wall wrote:

 That is the wrong direction to think about it.  Int is not
 being redefined as Cool:D there.  The basic type there is
 just Int, and when the $pos comes in, it will end up being
 a simple Int.  This syntax is called a "coercion type", and
 it just says that we can also accept anything that matches
 Cool:D and turn it into an Int.  But the inside of the
 method knows nothing about the Cool:D part.

 Think of Int(Cool:D) as the signature matcher automatically
 applying the normal Int($coolthing) coercer for you to
 make sure you have an Int, precisely so that you *don't*
 have to worry about the Cool:D part inside the routine,
 but know that it simply an Int for any part of the routine
 after the signature.


multi method contains(Str:D: Cool:D $needle, Int(Cool:D) $pos) --> Bool

$ p6 'say "abc234.56".contains( 2, "1" );' # Str changed to an Int
True

$ p6 'say "abc234.56".contains( 2, 2.4 );' # Real changed to an Int
True


Re: Please explain this to me

2018-09-13 Thread Todd Chester




On 09/13/2018 10:24 PM, JJ Merelo wrote:
Last time I counted, there were a dozen comments and 3 commits in the 
issue I created to try and improve the description. 2 files were 
modified by me. 


Is there some where I can look at these comments?


That's rather a dynamic way of not budging.


True.  I was over reacting