Re: What is the official name of regex switches?

2018-09-15 Thread ToddAndMargo

On 09/15/2018 07:24 PM, Larry Wall wrote:

On Sat, Sep 15, 2018 at 06:37:34PM -0700, ToddAndMargo wrote:
: Hi All,
:
: \L
: \N

I don't really know what you mean by those.

Regex switches are things like :i for case insensitivity.  They're also
called regex modifiers or regex options.  They always start with colon.
Something with a backslash is never called a switch in Perl culture.

: Since I use them all the time and there is a big long list of them
: over on
:
:
: 
https://docs.perl6.org/language/regexes#index-entry-regex_%3C%3Aproperty%3E-Unicode_properties
:
: it is about time I know their "Official" name?  I presume
: "regex switches" is not their official name.

You will note that that's in the section entitled "Unicode properties",
which seems like a pretty good name to me.  However, you're apparently
misconstruing their syntax.  \L and \N are not Unicode properties.
These are always used inside single angles plus a colon:

 <:L>  A letter
 <:N>  A number

Do not confuse these with any of:

 \L  (Error: Unrecognized backslash sequence)
 \N  A character that doesn't match a \n

 :L  (Error: Unrecognized regex modifier)
 :N  (Error: Unrecognized regex modifier)

   (Error: No such method 'L' for invocant of type 'Match')
   (Error: No such method 'N' for invocant of type 'Match')

More generally, Unicode properties like <:L> are a subset of character classes.
Character classes are always inside angles in Perl 6, and inside those
angles, you can combine Unicode properties and enumerated character classes:

 <:L + :N + [_]>   A letter or a number or an underscore
Same thing
 \wSame thing
 
Well, okay, I lied, since \w is a character class that is not inside angles.  :)


Larry



Thank you!


Re: Need regex help

2018-09-15 Thread Larry Wall
On Sat, Sep 15, 2018 at 06:45:33PM -0700, ToddAndMargo wrote:
: Hi All,
: 
: I have been doing a bunch with regex's lately.
: I just throw them out based on prior experience
: and they most all work now.  I only sometimes have to
: ask for help.  (The look forward () feature
: is sweet.)
: 
: Anyway, I have been using regex switches without
: knowing why. So
: 
: What is the difference between
: 
: \N

That is a character that is not any of the valid \n characters.

: :\N

That is not a thing.  That is a colon, which causes the previous thing
to not backtrack (if it would), followed by a \N (see above).

: <:\N>

That is not a thing.  In fact, it's a syntax error.

: <<\:N>>

That also is not a thing.  That is a left word boundary <<, followed by
\:, which matches a quote literally because it's backslashed, followed
by an N, which also matches literally, followed by the right word
boundary >>.  As a pattern, it is impossible for the combination to match,
since, while >> can match after a literal N, a << cannot match before a colon.

: And why would I choose one over the other (what
: are they called out for)?

I would never choose any of them, apart from \N.  Where are you getting
this craptastic list from?

Larry


Re: What is the official name of regex switches?

2018-09-15 Thread Larry Wall
On Sat, Sep 15, 2018 at 06:37:34PM -0700, ToddAndMargo wrote:
: Hi All,
: 
: \L
: \N

I don't really know what you mean by those.

Regex switches are things like :i for case insensitivity.  They're also
called regex modifiers or regex options.  They always start with colon.
Something with a backslash is never called a switch in Perl culture.

: Since I use them all the time and there is a big long list of them
: over on
: 
: 
: 
https://docs.perl6.org/language/regexes#index-entry-regex_%3C%3Aproperty%3E-Unicode_properties
: 
: it is about time I know their "Official" name?  I presume
: "regex switches" is not their official name.

You will note that that's in the section entitled "Unicode properties",
which seems like a pretty good name to me.  However, you're apparently
misconstruing their syntax.  \L and \N are not Unicode properties.
These are always used inside single angles plus a colon:

<:L>  A letter
<:N>  A number

Do not confuse these with any of:

\L  (Error: Unrecognized backslash sequence)
\N  A character that doesn't match a \n

:L  (Error: Unrecognized regex modifier)
:N  (Error: Unrecognized regex modifier)

  (Error: No such method 'L' for invocant of type 'Match')
  (Error: No such method 'N' for invocant of type 'Match')

More generally, Unicode properties like <:L> are a subset of character classes.
Character classes are always inside angles in Perl 6, and inside those
angles, you can combine Unicode properties and enumerated character classes:

<:L + :N + [_]>   A letter or a number or an underscore
   Same thing
\wSame thing

Well, okay, I lied, since \w is a character class that is not inside angles.  :)

Larry


Need regex help

2018-09-15 Thread ToddAndMargo

Hi All,

I have been doing a bunch with regex's lately.
I just throw them out based on prior experience
and they most all work now.  I only sometimes have to
ask for help.  (The look forward () feature
is sweet.)

Anyway, I have been using regex switches without
knowing why. So

What is the difference between

\N
:\N
<:\N>
<<\:N>>

And why would I choose one over the other (what
are they called out for)?

Many thanks,
-T


What is the official name of regex switches?

2018-09-15 Thread ToddAndMargo

Hi All,

\L
\N

Since I use them all the time and there is a big long list of them
over on


https://docs.perl6.org/language/regexes#index-entry-regex_%3C%3Aproperty%3E-Unicode_properties

it is about time I know their "Official" name?  I presume
"regex switches" is not their official name.

-T


Re: Need help with a variable inside a regex

2018-09-15 Thread ToddAndMargo
On Sat, Sep 15, 2018 at 4:09 AM ToddAndMargo > wrote:


On 09/15/2018 12:42 AM, ToddAndMargo wrote:
 > Hi All,
 >
 > I am truing to use a variable inside a regex.
 >
 > This work (without the variable):
 >     $ p6 'my $x="6937-2.2.19882.exe"; if $x ~~ m/ .*? <<:\N**4>> 
"-"

 > (.*?) ".exe" / {say "yes";}'
 >     yes
 >
 > I want to turn `<<:\N**4>>` into a variable:
 >
 >
 >     $ p6 'my $x="6937-2.2.19882.exe"; my $i="<<:\\N**4>>"; if $x
~~ m/
 > .*? $i  "-" (.*?) ".exe" / {say "yes";}else{say "No"}; say "$i";'
 >
 >     No
 >     <<:\N**4>>
 >
 > The double \\ is to get it past bash
 >
 >
 > What am I doing wrong?
 >
 > Many thanks,
 > -T

never mind.  It got just a bit too goofy.  I switched
to .contains and sent myself a tag as to when the
first bunch was a random 4 digit number.



On 09/15/2018 07:34 AM, Brandon Allbery wrote:
> To interpolate a variable as a regex instead of as a string literal, you
> need to wrap it in < >.
>


That was easy.  I am writing this down!   Thank you!

p6 'my $x="6937-2.2.19882.exe"; my $i="6937"; if $x ~~ m/ .*? <$i>  "-" 
(.*?) ".exe" / {say "yes";}else{say "No"}; say "$i";'

yes
6937

$ p6 'my $x="6937-2.2.19882.exe"; my $i="6938"; if $x ~~ m/ .*? <$i> 
"-" (.*?) ".exe" / {say "yes";}else{say "No"}; say "$i";'

No
6938

p6 'my $x="6937-2.2.19882.exe"; my $i="<<:\\N**4>>"; if $x ~~ m/ .*? 
<$i>  "-" (.*?) ".exe" / {say "yes";}else{say "No"}; say "$i";'

yes
<<:\N**4>>

--
~~~
Serious error.
All shortcuts have disappeared.
Screen. Mind. Both are blank.
~~~


Re: .kv ?

2018-09-15 Thread Brad Gilbert
On Fri, Sep 14, 2018 at 10:37 PM ToddAndMargo  wrote:
>
> On 09/14/2018 08:09 PM, Brad Gilbert wrote:
> > I think that it is because of how you read.
> >
> > The way your brain figures out what is written, is slow.
>
> That is how the human the human brain works.  It is
> always looking for patterns.  Depth perception for
> instance.  Is that a shadow or an actual hole?
> Sometimes it screws up royally.
>
> "Look See" really did me a disservice.

I'm just saying that brains are wired differently.

Anyway I edited the Option Types post.


Re: need p5/p6 :: help

2018-09-15 Thread Brent Laabs
Now that Larry has spoken on the issue of vocabulary, it's lexicanonical.

On Fri, Sep 14, 2018 at 12:49 PM Larry Wall  wrote:

> On Fri, Sep 14, 2018 at 04:15:02AM -0700, Todd Chester wrote:
> : Also, did you answer my question about "::" and did it
> : just go over my head?
>
> The implication was that "::" didn't change, but the default package
> scoping of p5 that you're relying on is no longer the default in p6.
>
> : The p5 guys use to tell me "its lexiconical", meaning it was figured
> : out on the fly.  (Took me forever to catch on.)  Is that any
> : relation to your use of the word "lexical"?
>
> I would like to see a citation of this use of the word "lexiconical".
> In the first place, the word "lexiconical" has not been used in
> perl5-porters in living memory, and if had been used there, it is
> unlikely to have meant "figured out on the fly".
>
> : https://www.dictionary.com/browse/lexical?s=t
> :
> :adjective
> :
> :of or relating to the words or vocabulary of a language,
> :especially as distinguished from its grammatical and
> :syntactical aspects.
> :
> :of, relating to, or of the nature of a lexicon.
>
> The relationship of lexicons to lexical scoping here is a bit tenuous,
> but it goes something like this: Every scope in your program can define
> things local to that scope.  When a scope does define something, it's
> creating a new lexicon of terms, like a private lingo or patois for a
> given workplace that no other workplace will understand.  It is that
> set of private definitions (overlaid on all the definitions pulled in
> from larger scopes) that functions as a "dictionary" here.
>
> So when people say "lexically scoped", they mean there are multiple
> lexicons,
> and each symbol is looked in the nearest one that actually has a definition
> for the term.  The whole point of "scoping" is to decide what is near, and
> what is far.
>
> So, for instance, you may have worked in a workplace or participated
> in a forum where the local lexicon of the "p5 guys" contained the
> word "lexiconical" with some kind of idiosyncratic meaning involving
> dynamic lookup.  That term is not used in the larger p5 culture that
> way, so people outside that workplace or forum will not understand that
> idiosyncratic definition of "lexiconical", which seems to have nothing
> whatsoever to do with lexicons.
>
> Lexical scoping is not figured out on the fly; it's figured out while the
> code is compiling.  You can have delayed compilation when you eval a
> string,
> of course, but then the fact that the lexical lookups are delayed is not
> a special feature of the lexicon; everything related to the compiler is
> delayed when you eval.  "Figured out on the fly" is a feature of eval, not
> of lexicons.
>
> Now, all that being said, in p5 subroutines are looked up in packages,
> and packages are modifiable, so we do have to discover what to call "on
> the fly" in that case.  But in p5 culture we never refer to packages as
> lexicons because that would confuse people.
>
> In Perl 6 culture we never mix them up either, but we also never put subs
> into packages by default.  The reason Foo::bar notation doesn't work is
> because bar isn't in Foo anymore unless you explicitly put it there.
>
> Larry
>


Re: Multibyte string in Windows command line

2018-09-15 Thread Brad Gilbert
I was just informed by samcv on #perl6-dev that she got the
utf16 stream decoder implemented.
http://colabti.org/irclogger/irclogger_log/perl6-dev?date=2018-09-15#l381

It should be in the next release, so after that there won't be a reason
to do the  dance I described earlier.

The following should just work in the next release.

run $install-file, :out, :enc

On Thu, Sep 13, 2018 at 11:23 PM WFB  wrote:
>
> 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: need p5/p6 :: help

2018-09-15 Thread Larry Wall
On Fri, Sep 14, 2018 at 06:12:15PM -0400, Vadim Belman wrote:
: Though technically this aspect was clear to me, but to settle things down in 
my mind completely: for now ordinary (not 'our') sub belongs not to the package 
object but to the block which belongs to that package. Is it correct way to 
describe things?

Mostly right.

I would not say that the block "belongs" to a package.  A block belongs
to a larger block, which belongs to a larger block, which (eventually)
belongs to a file, which functions as yet another block.  (And, in fact,
in Perl 6 the file itself belongs to its SETTING, which is a fake lexical
scope containing the whole file.)

Now, certainly, any given line of code happens to know which package is
its current default package, so in that sense a block may be associated
with one or more packages.  But there is no need for the block to take its
identity from its associated packages, since it can ignore them entirely.
What it can't ignore is its textual position.  A block's location is
its real identity, where it "belongs".

Larry


Re: Need help with a variable inside a regex

2018-09-15 Thread Brandon Allbery
To interpolate a variable as a regex instead of as a string literal, you
need to wrap it in < >.

On Sat, Sep 15, 2018 at 4:09 AM ToddAndMargo  wrote:

> On 09/15/2018 12:42 AM, ToddAndMargo wrote:
> > Hi All,
> >
> > I am truing to use a variable inside a regex.
> >
> > This work (without the variable):
> > $ p6 'my $x="6937-2.2.19882.exe"; if $x ~~ m/ .*? <<:\N**4>>  "-"
> > (.*?) ".exe" / {say "yes";}'
> > yes
> >
> > I want to turn `<<:\N**4>>` into a variable:
> >
> >
> > $ p6 'my $x="6937-2.2.19882.exe"; my $i="<<:\\N**4>>"; if $x ~~ m/
> > .*? $i  "-" (.*?) ".exe" / {say "yes";}else{say "No"}; say "$i";'
> >
> > No
> > <<:\N**4>>
> >
> > The double \\ is to get it past bash
> >
> >
> > What am I doing wrong?
> >
> > Many thanks,
> > -T
>
> never mind.  It got just a bit too goofy.  I switched
> to .contains and sent myself a tag as to when the
> first bunch was a random 4 digit number.
>
>
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>


-- 
brandon s allbery kf8nh
allber...@gmail.com


Re: Need help with a variable inside a regex

2018-09-15 Thread ToddAndMargo

On 09/15/2018 12:42 AM, ToddAndMargo wrote:

Hi All,

I am truing to use a variable inside a regex.

This work (without the variable):
    $ p6 'my $x="6937-2.2.19882.exe"; if $x ~~ m/ .*? <<:\N**4>>  "-" 
(.*?) ".exe" / {say "yes";}'

    yes

I want to turn `<<:\N**4>>` into a variable:


    $ p6 'my $x="6937-2.2.19882.exe"; my $i="<<:\\N**4>>"; if $x ~~ m/ 
.*? $i  "-" (.*?) ".exe" / {say "yes";}else{say "No"}; say "$i";'


    No
    <<:\N**4>>

The double \\ is to get it past bash


What am I doing wrong?

Many thanks,
-T


never mind.  It got just a bit too goofy.  I switched
to .contains and sent myself a tag as to when the
first bunch was a random 4 digit number.



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


Need help with a variable inside a regex

2018-09-15 Thread ToddAndMargo

Hi All,

I am truing to use a variable inside a regex.

This work (without the variable):
   $ p6 'my $x="6937-2.2.19882.exe"; if $x ~~ m/ .*? <<:\N**4>>  "-" 
(.*?) ".exe" / {say "yes";}'

   yes

I want to turn `<<:\N**4>>` into a variable:


   $ p6 'my $x="6937-2.2.19882.exe"; my $i="<<:\\N**4>>"; if $x ~~ m/ 
.*? $i  "-" (.*?) ".exe" / {say "yes";}else{say "No"}; say "$i";'


   No
   <<:\N**4>>

The double \\ is to get it past bash


What am I doing wrong?

Many thanks,
-T


Re: I need hash syntax help

2018-09-15 Thread ToddAndMargo
On Fri, Sep 14, 2018 at 11:59 PM ToddAndMargo > wrote:


Hi All,

Why does `$y =%x<<$z>>` work in the following and
`$y =%x<$z>` and `$y =%x<"$z"> do not work?

$ p6 'my Str %x=("Jan"=>"01", "Feb"=>"02");
my Str $z="Jan";
my $y =%x<<$z>>;
say "$y";'
01

Why did I get it right?


Many thanks,
-T



On 09/15/2018 12:13 AM, Brent Laabs wrote:
Because << >> is a double-quoted index (same as quote words «»), so it 
interpolates the variable.  <> is a single-quoted string, so it doesn't 
interpolate.


But what you really want here is %x{$z}, so you don't bother with string 
interpolation at all, and pass the String variable directly.





perfect!  Thank you!

$ p6 'my Str %x=("Jan"=>"01", "Feb"=>"02"); my Str $z="Jan"; my $y 
=%x{$z}; say "$y";'

01


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


Re: I need hash syntax help

2018-09-15 Thread Brent Laabs
Because << >> is a double-quoted index (same as quote words «»), so it
interpolates the variable.  <> is a single-quoted string, so it doesn't
interpolate.

But what you really want here is %x{$z}, so you don't bother with string
interpolation at all, and pass the String variable directly.

On Fri, Sep 14, 2018 at 11:59 PM ToddAndMargo  wrote:

> Hi All,
>
> Why does `$y =%x<<$z>>` work in the following and
> `$y =%x<$z>` and `$y =%x<"$z"> do not work?
>
> $ p6 'my Str %x=("Jan"=>"01", "Feb"=>"02");
>my Str $z="Jan";
>my $y =%x<<$z>>;
>say "$y";'
> 01
>
> Why did I get it right?
>
>
> Many thanks,
> -T
>


I need hash syntax help

2018-09-15 Thread ToddAndMargo

Hi All,

Why does `$y =%x<<$z>>` work in the following and
`$y =%x<$z>` and `$y =%x<"$z"> do not work?

$ p6 'my Str %x=("Jan"=>"01", "Feb"=>"02");
  my Str $z="Jan";
  my $y =%x<<$z>>;
  say "$y";'
01

Why did I get it right?


Many thanks,
-T