Re: lines :$nl-in question

2020-08-30 Thread ToddAndMargo via perl6-users

On 2020-08-30 07:43, yary wrote:

The :foo syntax is called a "colon pair"


Thank you!


Re: lines :$nl-in question

2020-08-30 Thread ToddAndMargo via perl6-users
*From:* William Michels >

*Sent:* Sunday, August 30, 2020 2:44:55 PM
*To:* yary mailto:not@gmail.com>>
*Cc:* perl6-users mailto:perl6-users@perl.org>>; 
ToddAndMargo mailto:toddandma...@zoho.com>>; 
Brad Gilbert mailto:b2gi...@gmail.com>>

*Subject:* Re: lines :$nl-in question
Do you agree with that definition, Yary? Brad? Here it is:

"Invocant"

"Caller, the one who calls or invokes. The invocant of a method would
be the object on which that method is being called, or, in some cases,
the class itself. Invocant is used instead of caller because the
latter refers to the scope."

https://docs.raku.org/language/glossary#Invocant

At first blush, the definition at
https://docs.raku.org/language/glossary#Invocant contradicts the
definition given to us by Brad. English speaker will typically use the
following word pairs to denote 1. an actor and 2. a recipient of some
action. So we have the following:

Payer vs. Payee
Lessor vs. Lessee
Employer vs. Employee

So going with the typical English usage above, the pattern would
continue with "Caller" vs "Callee" and "Invoker" vs
"Invokee/Invocant".  Therefore my humble reading of the definition
given by Brad, as well as a post authored by a certain TChrist on
StackExchange [1], suggests to me that "Invocant" is a synonym for
"Callee" (or the possibly-imaginary word "Invokee"). One can look at
the definition of "Invoker" online provided by Oracle with regards to
the Java programming language [2], to further distinguish "Invoker" vs
"Invocant".

HTH, Bill.

W. Michels, Ph.D.

[1] https://english.stackexchange.com/a/59070
[2] 
https://docs.oracle.com/javase/8/docs/api/index.html?javax/xml/ws/spi/Invoker.html



On Sun, Aug 30, 2020 at 9:54 AM yary > wrote:


The Raku glossary has a definition
https://docs.raku.org/language/glossary#Invocant

suggestion, link to that where the term appears.

-y


On Sun, Aug 30, 2020 at 9:16 AM William Michels via perl6-users mailto:perl6-users@perl.org>> wrote:


Inline:

On Sun, Aug 30, 2020 at 12:49 AM Brad Gilbert mailto:b2gi...@gmail.com>> wrote:
>
> Invocant is in the dictionary though.
>
> In fact it is from Latin.
>
> Origin & history:
>   Derived from in- + vocō ("I call").
>
> Verb:
>   I invoke
>   I call (by name)
>
> In fact that is pretty close to the same meaning as it is used in the Raku 
docs.
>
> It is the object that we are calling (aka invoking) a method on.

Maybe we can meet Todd halfway?

>
> On Sat, Aug 29, 2020 at 6:39 PM ToddAndMargo via perl6-users mailto:perl6-users@perl.org>> wrote:
>>
>> On 2020-08-28 23:51, Tobias Boege wrote:
>> > On Fri, 28 Aug 2020, ToddAndMargo via perl6-users wrote:
>> >> https://docs.raku.org/type/IO::Path#method_lines
>> >>
>> >> (IO::Path) method lines
>> >>
>> >> Defined as:
>> >>
>> >> method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in = ["\x0A", 
"\r\n"], |c --> Seq:D)
>> >>
>> >> Opens the invocant and returns its lines.


"Opens the invocant (i.e. the object being called) and returns its lines."

[Add text in parentheses above only once per method, when the word
'invocant' is first used].

Comments?

Best Regards, Bill.



On 2020-08-30 14:08, Stuckwisch, Matthew wrote:
So I guess I got included on this as the resident language professor :-) 
(although I probably should subscribe to p6 users at some point) I 
didn't see the whole thread in the e-mail I got copied in on, so 
apologizes if I repeat much.


I'll spare everyone all the linguistic details, but suffice it to say, 
invocant and invoker are functionally equivalent.  The former is a 
nominalized adjective, and the latter a noun proper.  They mean "the one 
that invokes (calls)".   We can use either, but I'd recommend we be very 
consistent.  Invocant seems to be the preferred, so let's use it 
exclusively. On the other side, we have invoked and invokee, which in 
English share a similar distinction (although nominalizing the former 
often sounds odd, and adjectifying the latter would probably be read as 
missing a genitive 's).


Summed up, we should avoid using invocant to refer to a method that's 
being called.  Generally, just calling it a "method" is sufficient, but 
if need be, I'd go with "the invoked method".  We probably can write 
documentation to avoid the formalisms altogether, though, by saying 
something to the effect of


 > Opens the file [represented by the [calling] object] and returns its 
lines.


That's fairly simple and clear.  In an article about signatures, 
however, I think using the term is absolutely appropriate, and warrants 
defining it parenthetically inline as "the object that calls/invokes the 
associated method".  I get that using the word "call" muddies the water 
(the formal distinction that tchrist was getting at is that a sub has no 
invocant except perhaps a calling context, ie the "caller" — which a 
method also has), but we already did that by having methods use CALL-ME 
instead of 

Re: lines :$nl-in question

2020-08-30 Thread yary
+1 on Matthew's comment

Do you agree with that definition, Yary? Brad? Here it is:
> "Invocant"
> "Caller, the one who calls or invokes. The invocant of a method would
> be the object on which that method is being called, or, in some cases,
> the class itself. Invocant is used instead of caller because the
> latter refers to the scope."


I have a quibble there. 1st & 2nd sentences disagree slightly by going from
active to passive voice. "Caller, the one who calls" vs "object on which
that method is being called"

Suggestion for 2nd sentence "The invocant of a method would be the object
calling the method" ... if that is correct!

On Sun, Aug 30, 2020 at 2:08 PM Stuckwisch, Matthew <
matthew-stuckwi...@utc.edu> wrote:

> So I guess I got included on this as the resident language professor :-)
> (although I probably should subscribe to p6 users at some point)  I
> didn't see the whole thread in the e-mail I got copied in on, so apologizes
> if I repeat much.
>
> I'll spare everyone all the linguistic details, but suffice it to say,
> invocant and invoker are functionally equivalent.  The former is a
> nominalized adjective, and the latter a noun proper.  They mean "the one
> that invokes (calls)".   We can use either, but I'd recommend we be very
> consistent.  Invocant seems to be the preferred, so let's use it
> exclusively.  On the other side, we have invoked and invokee, which in
> English share a similar distinction (although nominalizing the former often
> sounds odd, and adjectifying the latter would probably be read as missing a
> genitive 's).
>
> Summed up, we should avoid using invocant to refer to a method that's
> being called.  Generally, just calling it a "method" is sufficient, but if
> need be, I'd go with "the invoked method".  We probably can write
> documentation to avoid the formalisms altogether, though, by saying
> something to the effect of
>
> > Opens the file [represented by the [calling] object] and returns its
> lines.
>
> That's fairly simple and clear.  In an article about signatures, however,
> I think using the term is absolutely appropriate, and warrants defining it
> parenthetically inline as "the object that calls/invokes the associated
> method".  I get that using the word "call" muddies the water (the formal
> distinction that tchrist was getting at is that a sub has no invocant
> except perhaps a calling context, ie the "caller" — which a method also
> has), but we already did that by having methods use CALL-ME instead of
> INVOKE-ME :-) *
>
> MSS
>
>
> * Of course, the reason was to harmonize calls of all code, and the fluid
> nature of allowing transitive methods be used as subs and viceversa (method
> $invocant: @args and $invocant.) means that one term had to rule them
> all.
>
> --
> *From:* William Michels 
> *Sent:* Sunday, August 30, 2020 2:44:55 PM
> *To:* yary 
> *Cc:* perl6-users ; ToddAndMargo <
> toddandma...@zoho.com>; Brad Gilbert 
> *Subject:* Re: lines :$nl-in question
>
> Do you agree with that definition, Yary? Brad? Here it is:
>
> "Invocant"
>
> "Caller, the one who calls or invokes. The invocant of a method would
> be the object on which that method is being called, or, in some cases,
> the class itself. Invocant is used instead of caller because the
> latter refers to the scope."
>
> https://docs.raku.org/language/glossary#Invocant
>
> At first blush, the definition at
> https://docs.raku.org/language/glossary#Invocant contradicts the
> definition given to us by Brad. English speaker will typically use the
> following word pairs to denote 1. an actor and 2. a recipient of some
> action. So we have the following:
>
> Payer vs. Payee
> Lessor vs. Lessee
> Employer vs. Employee
>
> So going with the typical English usage above, the pattern would
> continue with "Caller" vs "Callee" and "Invoker" vs
> "Invokee/Invocant".  Therefore my humble reading of the definition
> given by Brad, as well as a post authored by a certain TChrist on
> StackExchange [1], suggests to me that "Invocant" is a synonym for
> "Callee" (or the possibly-imaginary word "Invokee"). One can look at
> the definition of "Invoker" online provided by Oracle with regards to
> the Java programming language [2], to further distinguish "Invoker" vs
> "Invocant".
>
> HTH, Bill.
>
> W. Michels, Ph.D.
>
> [1] https://english.stackexchange.com/a/59070
> [2]
> https://docs.oracle.com/javase/8/docs/api/index.html?javax/xml/ws/spi/Invoker.html
>
>
> On Sun, Aug 30, 2020 at 9:54 AM yary  wrote:
> >
> > The Raku glossary has a definition
> > https://docs.raku.org/language/glossary#Invocant
> >
> > suggestion, link to that where the term appears.
> >
> > -y
> >
> >
> > On Sun, Aug 30, 2020 at 9:16 AM William Michels via perl6-users <
> perl6-users@perl.org> wrote:
> >>
> >> Inline:
> >>
> >> On Sun, Aug 30, 2020 at 12:49 AM Brad Gilbert 
> wrote:
> >> >
> >> > Invocant is in the dictionary though.
> >> >
> >> > In fact it is from Latin.
> >> >
> >> > Origin & 

Raku Study group in progress

2020-08-30 Thread Joseph Brenner
I'm trying to get the Raku study group working today, but I've
been having a bunch of zoom weirdness.  It should be in progress
now:


The SF Perl Raku Study Group, 8/30 at 1pm PDT

https://us02web.zoom.us/j/88495193366?pwd=TXpMSlVqaVVGMm52SWlvSmRrZXFBUT09

Password: 4RakuRoll


Re: How to I modify what is a new line in lines?

2020-08-30 Thread Brad Gilbert
$file.IO.lines( :nl-in(…), :chomp, … )

is actually short for

$file.IO.open( :nl-in(…), :chomp ).lines( … )

On Sun, Aug 30, 2020 at 10:43 AM yary  wrote:

> You were close!
>
> First, you were looking at the docs for Path's "lines", but you are using
> a string "lines" and those docs say
>
> multi method lines(Str:D: $limit, :$chomp = True)
> multi method lines(Str:D: :$chomp = True)
>
> Files get "nl-in" due to the special case of text files having various
> line endings to tweak.
>
> Strings already have "split" and "comb" for all the flexibility one may
> need there, and what you're playing with is more naturally
> dd $_ for $x.split("\t"); # "a","b", ... removes \t
> dd $_ for $x.split(//); "a\t","b\t", 
>
> Now back to the Path lines, which DOES let you specify line endings
>
> method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in = ["\x0A"
> , "\r\n"], |c --> Seq:D)
>
> $ cat line0-10.txt
> Line 0
> Line 1
> Line 2
> ...
>
> let's pretend that the letter "i" is a line ending.
> named arguments can be conveniently written colon pairs :-)
>
> my $nl-in="i"; dd $_ for 'line0-10.txt'.IO.lines(:$nl-in)[0..3];
> "L"
> "ne 0\nL"
> "ne 1\nL"
> "ne 2\nL"
>
> How about splitting on either "i" or "\n", and not chomping
>
> my $nl-in=("i","\n"); dd $_ for 'line0-10.txt'.IO.lines(:$nl-in,
> :!chomp)[0..3];
> "Li"
> "ne 0\n"
> "Li"
> "ne 1\n"
>
> To put in line endings without having a variable of the same name as the
> naed arg, use the full form of the colon pair
> dd $_ for 'line0-10.txt'.IO.lines(:nl-in["i","\n"], :!chomp)[0..3];
> "Li"
> "ne 0\n"
> "Li"
> "ne 1\n"
>
>
>
> -y
>
>
> On Sun, Aug 30, 2020 at 2:58 AM ToddAndMargo via perl6-users <
> perl6-users@perl.org> wrote:
>
>> Hi All,
>>
>> https://docs.raku.org/type/IO::Path#method_lines
>>
>> method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in =
>> ["\x0A", "\r\n"], |c --> Seq:D)
>>
>> How do I change what lines sees as a new line.  Is it
>> :$nl-in?  A tab in this case.
>>
>> Some of my missteps:
>>
>> $ p6 'my $x="a\tb\tc\td\t"; dd $x; for $x.lines(:!chomp, "\t") {dd $_};'
>> Str $x = "a\tb\tc\td\t"
>>
>>
>> $ p6 'my $x="a\tb\tc\td\t"; dd $x; for $x.lines(:!chomp, :$nl-in =
>> ["\x0A", "\r\n"]) {dd $_};'
>> ===SORRY!=== Error while compiling -e
>> Variable '$nl-in' is not declared
>> at -e:1
>> --> tc\td\t"; dd $x; for $x.lines(:!chomp, :⏏$nl-in = ["\x0A",
>> "\r\n"]) {dd $_};
>>
>> $ p6 'my $x="a\tb\tc\td\t"; dd $x; for $x.lines(:!chomp, :nl-in =
>> ["\x0A", "\r\n"]) {dd $_};'
>> Str $x = "a\tb\tc\td\t"
>> Cannot modify an immutable Pair (nl-in => True)
>>in block  at -e line 1
>>
>>
>> Many thanks,
>> -T
>>
>


Re: lines :$nl-in question

2020-08-30 Thread William Michels via perl6-users
Do you agree with that definition, Yary? Brad? Here it is:

"Invocant"

"Caller, the one who calls or invokes. The invocant of a method would
be the object on which that method is being called, or, in some cases,
the class itself. Invocant is used instead of caller because the
latter refers to the scope."

https://docs.raku.org/language/glossary#Invocant

At first blush, the definition at
https://docs.raku.org/language/glossary#Invocant contradicts the
definition given to us by Brad. English speaker will typically use the
following word pairs to denote 1. an actor and 2. a recipient of some
action. So we have the following:

Payer vs. Payee
Lessor vs. Lessee
Employer vs. Employee

So going with the typical English usage above, the pattern would
continue with "Caller" vs "Callee" and "Invoker" vs
"Invokee/Invocant".  Therefore my humble reading of the definition
given by Brad, as well as a post authored by a certain TChrist on
StackExchange [1], suggests to me that "Invocant" is a synonym for
"Callee" (or the possibly-imaginary word "Invokee"). One can look at
the definition of "Invoker" online provided by Oracle with regards to
the Java programming language [2], to further distinguish "Invoker" vs
"Invocant".

HTH, Bill.

W. Michels, Ph.D.

[1] https://english.stackexchange.com/a/59070
[2] 
https://docs.oracle.com/javase/8/docs/api/index.html?javax/xml/ws/spi/Invoker.html


On Sun, Aug 30, 2020 at 9:54 AM yary  wrote:
>
> The Raku glossary has a definition
> https://docs.raku.org/language/glossary#Invocant
>
> suggestion, link to that where the term appears.
>
> -y
>
>
> On Sun, Aug 30, 2020 at 9:16 AM William Michels via perl6-users 
>  wrote:
>>
>> Inline:
>>
>> On Sun, Aug 30, 2020 at 12:49 AM Brad Gilbert  wrote:
>> >
>> > Invocant is in the dictionary though.
>> >
>> > In fact it is from Latin.
>> >
>> > Origin & history:
>> >   Derived from in- + vocō ("I call").
>> >
>> > Verb:
>> >   I invoke
>> >   I call (by name)
>> >
>> > In fact that is pretty close to the same meaning as it is used in the Raku 
>> > docs.
>> >
>> > It is the object that we are calling (aka invoking) a method on.
>>
>> Maybe we can meet Todd halfway?
>>
>> >
>> > On Sat, Aug 29, 2020 at 6:39 PM ToddAndMargo via perl6-users 
>> >  wrote:
>> >>
>> >> On 2020-08-28 23:51, Tobias Boege wrote:
>> >> > On Fri, 28 Aug 2020, ToddAndMargo via perl6-users wrote:
>> >> >> https://docs.raku.org/type/IO::Path#method_lines
>> >> >>
>> >> >> (IO::Path) method lines
>> >> >>
>> >> >> Defined as:
>> >> >>
>> >> >> method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in = 
>> >> >> ["\x0A", "\r\n"], |c --> Seq:D)
>> >> >>
>> >> >> Opens the invocant and returns its lines.
>>
>>
>> "Opens the invocant (i.e. the object being called) and returns its lines."
>>
>> [Add text in parentheses above only once per method, when the word
>> 'invocant' is first used].
>>
>> Comments?
>>
>> Best Regards, Bill.


Re: lines :$nl-in question

2020-08-30 Thread yary
The Raku glossary has a definition
https://docs.raku.org/language/glossary#Invocant

suggestion, link to that where the term appears.

-y


On Sun, Aug 30, 2020 at 9:16 AM William Michels via perl6-users <
perl6-users@perl.org> wrote:

> Inline:
>
> On Sun, Aug 30, 2020 at 12:49 AM Brad Gilbert  wrote:
> >
> > Invocant is in the dictionary though.
> >
> > In fact it is from Latin.
> >
> > Origin & history:
> >   Derived from in- + vocō ("I call").
> >
> > Verb:
> >   I invoke
> >   I call (by name)
> >
> > In fact that is pretty close to the same meaning as it is used in the
> Raku docs.
> >
> > It is the object that we are calling (aka invoking) a method on.
>
> Maybe we can meet Todd halfway?
>
> >
> > On Sat, Aug 29, 2020 at 6:39 PM ToddAndMargo via perl6-users <
> perl6-users@perl.org> wrote:
> >>
> >> On 2020-08-28 23:51, Tobias Boege wrote:
> >> > On Fri, 28 Aug 2020, ToddAndMargo via perl6-users wrote:
> >> >> https://docs.raku.org/type/IO::Path#method_lines
> >> >>
> >> >> (IO::Path) method lines
> >> >>
> >> >> Defined as:
> >> >>
> >> >> method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in
> = ["\x0A", "\r\n"], |c --> Seq:D)
> >> >>
> >> >> Opens the invocant and returns its lines.
>
>
> "Opens the invocant (i.e. the object being called) and returns its lines."
>
> [Add text in parentheses above only once per method, when the word
> 'invocant' is first used].
>
> Comments?
>
> Best Regards, Bill.
>


Re: lines :$nl-in question

2020-08-30 Thread William Michels via perl6-users
Inline:

On Sun, Aug 30, 2020 at 12:49 AM Brad Gilbert  wrote:
>
> Invocant is in the dictionary though.
>
> In fact it is from Latin.
>
> Origin & history:
>   Derived from in- + vocō ("I call").
>
> Verb:
>   I invoke
>   I call (by name)
>
> In fact that is pretty close to the same meaning as it is used in the Raku 
> docs.
>
> It is the object that we are calling (aka invoking) a method on.

Maybe we can meet Todd halfway?

>
> On Sat, Aug 29, 2020 at 6:39 PM ToddAndMargo via perl6-users 
>  wrote:
>>
>> On 2020-08-28 23:51, Tobias Boege wrote:
>> > On Fri, 28 Aug 2020, ToddAndMargo via perl6-users wrote:
>> >> https://docs.raku.org/type/IO::Path#method_lines
>> >>
>> >> (IO::Path) method lines
>> >>
>> >> Defined as:
>> >>
>> >> method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in = 
>> >> ["\x0A", "\r\n"], |c --> Seq:D)
>> >>
>> >> Opens the invocant and returns its lines.


"Opens the invocant (i.e. the object being called) and returns its lines."

[Add text in parentheses above only once per method, when the word
'invocant' is first used].

Comments?

Best Regards, Bill.


Re: How to I modify what is a new line in lines?

2020-08-30 Thread yary
You were close!

First, you were looking at the docs for Path's "lines", but you are using a
string "lines" and those docs say

multi method lines(Str:D: $limit, :$chomp = True)
multi method lines(Str:D: :$chomp = True)

Files get "nl-in" due to the special case of text files having various line
endings to tweak.

Strings already have "split" and "comb" for all the flexibility one may
need there, and what you're playing with is more naturally
dd $_ for $x.split("\t"); # "a","b", ... removes \t
dd $_ for $x.split(//); "a\t","b\t", 

Now back to the Path lines, which DOES let you specify line endings

method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in = ["\x0A",
"\r\n"], |c --> Seq:D)

$ cat line0-10.txt
Line 0
Line 1
Line 2
...

let's pretend that the letter "i" is a line ending.
named arguments can be conveniently written colon pairs :-)

my $nl-in="i"; dd $_ for 'line0-10.txt'.IO.lines(:$nl-in)[0..3];
"L"
"ne 0\nL"
"ne 1\nL"
"ne 2\nL"

How about splitting on either "i" or "\n", and not chomping

my $nl-in=("i","\n"); dd $_ for 'line0-10.txt'.IO.lines(:$nl-in,
:!chomp)[0..3];
"Li"
"ne 0\n"
"Li"
"ne 1\n"

To put in line endings without having a variable of the same name as the
naed arg, use the full form of the colon pair
dd $_ for 'line0-10.txt'.IO.lines(:nl-in["i","\n"], :!chomp)[0..3];
"Li"
"ne 0\n"
"Li"
"ne 1\n"



-y


On Sun, Aug 30, 2020 at 2:58 AM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> https://docs.raku.org/type/IO::Path#method_lines
>
> method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in =
> ["\x0A", "\r\n"], |c --> Seq:D)
>
> How do I change what lines sees as a new line.  Is it
> :$nl-in?  A tab in this case.
>
> Some of my missteps:
>
> $ p6 'my $x="a\tb\tc\td\t"; dd $x; for $x.lines(:!chomp, "\t") {dd $_};'
> Str $x = "a\tb\tc\td\t"
>
>
> $ p6 'my $x="a\tb\tc\td\t"; dd $x; for $x.lines(:!chomp, :$nl-in =
> ["\x0A", "\r\n"]) {dd $_};'
> ===SORRY!=== Error while compiling -e
> Variable '$nl-in' is not declared
> at -e:1
> --> tc\td\t"; dd $x; for $x.lines(:!chomp, :⏏$nl-in = ["\x0A",
> "\r\n"]) {dd $_};
>
> $ p6 'my $x="a\tb\tc\td\t"; dd $x; for $x.lines(:!chomp, :nl-in =
> ["\x0A", "\r\n"]) {dd $_};'
> Str $x = "a\tb\tc\td\t"
> Cannot modify an immutable Pair (nl-in => True)
>in block  at -e line 1
>
>
> Many thanks,
> -T
>


Re: liens and :chomp question

2020-08-30 Thread yary
Expanding on how to read the docs & signature a bit, from Tobias

> You confuse two methods that have the same name "lines". One of them,
> which exists in the IO::Path class, has a :chomp argument. The other,
> on IO::Handle does not.
>   "path".IO.lines()   <-- calls lines on an IO::Path (supports :chomp)
>   "path".IO.open.lines()  <-- calls lines on an IO::Handle (does not
> support :chomp)


Looking up https://docs.raku.org/routine/lines shows a Table of Contents
with

class Cool
(Cool) routine lines
class Supply
(Supply) method lines
class Str
(Str) routine lines
class IO::CatHandle
(IO::CatHandle) method lines
class IO::Path
(IO::Path) method lines
class IO::Handle
(IO::Handle) routine lines
class IO::Socket::INET
(IO::Socket::INET) method lines


Lots of different "lines" methods. If I click on IO::Handle it jumps to
sub  lines( $what = $*ARGFILES, |c)
multi method lines( IO::Handle:D: $limit, :$close )
multi method lines( IO::Handle:D: :$close )

which indeed has no named argument for "chomp"

As an aside-Reading between the lines (no pun intended), I deduce that the
IO::Handle "lines" method is its own implementation so that it can read
"lazily" as needed, and to support the "close" option.

And as another aside, it has a "sub" which shows that when "lines" is
called with no arguments, it defaults to reading from $*ARGFILES.

So, back to the table of contents. How does one know which "lines" routine
to look at?

Either by thinking & remembering --
"oh 'file'.IO.open returns an IO::Handle that's the one to read"
"Huh 'file'.IO returns a path object, and there's *'(IO::Path) method*
*lines'* listed lets look at that, hmm it has *chomp*"

or by experiment!
> 'example.txt'.IO.WHAT
(Path)
> 'example.txt'.IO.open.WHAT
(Handle)

-y


On Sun, Aug 30, 2020 at 12:56 AM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 2020-08-30 00:35, Tobias Boege wrote:
> > On Sun, 30 Aug 2020, ToddAndMargo via perl6-users wrote:
> >>> - You are calling .lines on the value of .IO.open which is an
> >>>   IO::Handle. IO::Handle.lines does not take a named argument
> >>>   :chomp, so passing one is useless.
> >>
> >> That explains it.
> >>
> >> Bu:
> >>   https://docs.raku.org/type/IO::Path#method_lines
> >>
> >>   (IO::Path) method lines
> >>   Defined as:
> >>
> >>   method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in =
> >> ["\x0A", "\r\n"], |c --> Seq:D)
> >>
> >>   Opens the invocant and returns its lines.
> >>
> >>   The behavior is equivalent to opening the file specified
> >>   by the invocant, forwarding the :$chomp, :$enc, and
> >>   :$nl-in arguments to IO::Handle.open, then calling
> >>   IO::Handle.lines on that handle, forwarding any of
> >>   the remaining arguments to that method, and returning
> >>   the resultant Seq.
> >>
> >> The "signature" line (cryptogram) clearly stated that
> >> ":$chomp" is a parameter of the method.
> >>
> >> Now you are obviously correct that :chomp is ignored.
> >> If I am not mistaken, I have just tripped over another
> >> error in the documentation.  Your take?
> >>
> >
> > You confuse two methods that have the same name "lines". One of them,
> > which exists in the IO::Path class, has a :chomp argument. The other,
> > on IO::Handle does not.
> >
> >"path".IO.lines()   <-- calls lines on an IO::Path (supports
> :chomp)
> >"path".IO.open.lines()  <-- calls lines on an IO::Handle (does not
> support :chomp)
> >
> > In the second case, if you want chomping to happen you have to pass
> > the :chomp to the *open* call, as you do below:
>
> Hi Tobias,
>
> The terrible example they included was:
> '50GB-file'.IO.lines.grep(*.contains: 'Perl').elems,
>" lines that mention Perl";
>
> I left off the "grep" and the "elems".
>
> "Lines.txt".IO.open.lines
>
> This was the example they gave for
>
> method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in =
> ["\x0A", "\r\n"], |c --> Seq:D)
>
> Exactly what is "IO::Path:D:"?
>
> I know that :D is declared and the ":" after it
> is a delimiter.  That leaved "IO::Path":
>
> https://docs.raku.org/type/IO::Path
>
> And I can't make heads or tails out of the page.
>
> My goal is to learn how to use :$chomp = True,
> :$enc = 'utf8', :$nl-in, and, |c
>
> Thank you for the help!
> -T
>


Re: Reminder: Fill Raku's user survey!

2020-08-30 Thread William Michels via perl6-users
Has an announcement been made on all the following:
"Hackernews/Reddit/Slashdot/PerlMonks/[yCombinator]/[Hackernoon]/[Slack]/[Discord]/[IRC]/similar
online forum and/or news aggregator?"

Can anyone reading here who has an account on another forum/service,
make sure an announcement is made?

Thank you!

On Sun, Aug 30, 2020 at 2:27 AM JJ Merelo  wrote:
>
> Hi,
> Here's the link 
> https://docs.google.com/forms/d/e/1FAIpQLSdRPBdn1iRN_sT8BMNMOBhVbEY1u8ngZWVwLyM37sqsa4OLwQ/viewform
>
> It'll take you five minutes, top. Answers will be summarized and carefully 
> considered. Thanks!
>
> --
> JJ


Re: lines :$nl-in question

2020-08-30 Thread yary
The :foo syntax is called a "colon pair", and colon pair also
describes :quux since it is short for :quux(True)

Colon pair also describes :$foo because it is a shorthand using a colon to
create the Pair object foo=>$foo

Searching raku docs showed
https://docs.raku.org/language/glossary#index-entry-Colon_Pair

which also says that putting a bunch of those together creates a "colon
list"

It also has a link to Adverb https://docs.raku.org/language/glossary#Adverb

which shows how colon pairs can be used to set named arguments–when used
that way, a colon pair is also called an "adverbial pair."

-y


On Sun, Aug 30, 2020 at 2:50 AM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:
>
> >> On Sat, Aug 29, 2020 at 9:05 PM ToddAndMargo via perl6-users
> >> mailto:perl6-users@perl.org>> wrote:
>
> >> And if you would not mind, what is the official name
> >> of variables that begin with ":"
> >>
>
> On 2020-08-30 00:43, Brad Gilbert wrote:
> > There are no variables that begin with :
> >
> > There are variable declarations in signatures that begin with :
> >
> > :$foo is exactly the same as :foo($foo)
> >
> >  sub bar ( :$foo ) {…}
> >  sub bar ( :foo($foo) ){…}
> >
> > :$foo in a signature is a shortcut for declaring a named argument :foo()
> > and a variable with the same base name $foo
> >
> > :$foo also does the same thing as an argument
> >
> >  my $foo = 1;
> >
> >  bar( :$foo )
> >  bar( :foo($foo) )
> >  bar( foo => $foo )
> >
> > Note that forms with : can be outside of the signature
> >
> >  bar( ) :$foo
> >  bar( ) :foo($foo)
>
>
> Follow up questions:
>
> 1) what is the exact name used to describe these critters?
>
> 2) is there a manual page on them?


Re: Reminder: Fill Raku's user survey!

2020-08-30 Thread JJ Merelo
El dom., 30 ago. 2020 a las 11:43, ToddAndMargo ()
escribió:

> >> El dom., 30 ago. 2020 a las 11:34, ToddAndMargo ( >> >) escribió:
> >>
> >> On 2020-08-30 02:26, JJ Merelo wrote:
> >>  > Hi,
> >>  > Here's the link
> >>  >
> >>
> https://docs.google.com/forms/d/e/1FAIpQLSdRPBdn1iRN_sT8BMNMOBhVbEY1u8ngZWVwLyM37sqsa4OLwQ/viewform
> >>  >
> >>  > It'll take you five minutes, top. Answers will be summarized and
> >>  > carefully considered. Thanks!
> >>  >
> >>  > --
> >>  > JJ
> >>
> >>
> >> Hi JJ,
> >>
> >> I missed one when I filled out the list:
> >>
> >> 8)  The developers seriously need to fix the staging
> >> compile times on par with Perl 5:
> >>
> >> $ raku -c --stagestats GetUpdates.pl6
> >> Stage start  :   0.000
> >> Stage parse  :  18.108
> >> Stage syntaxcheck: Syntax OK
> >>
> >> Any way you an get it into the fray?
> >>
> >> Many thnks,
> >> -T
>
> On 2020-08-30 02:36, JJ Merelo wrote:
> > In principle, answers are anonymous, so no way, sorry. Did you
> > *actually* fill the form, though, or just answered the question here? We
> > need them to be in the form, to consider them.
>
> Indeed I did.  I just forgot to add the "staging" problem
> to the fray.  Then I started taklig about it on this forum.
>
> And I do not care if I am anonymous, especially if when you
> get to mine, you will know immediately it is me.  My views
> are quite public.
>


There are 128 answers so far. I went so far as to actually look for 7.,
since that issue was 8. I didn't find anything there (only, unsurprisingly,
some answers that mention Perl 7).
Even if I had found it, you must understand that setting up and analyzing a
survey is a good amount of work. Trying to find a specific answer and edit
it is way beyond what is actually required, or actually needed.

You've actually expressed your view, it's been noted. You want it to go
into the survey, I'm afraid you'll have to fill it up again.

Cheers


-- 
JJ


How to I modify what is a new line in lines?

2020-08-30 Thread ToddAndMargo via perl6-users

Hi All,

https://docs.raku.org/type/IO::Path#method_lines

method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in = 
["\x0A", "\r\n"], |c --> Seq:D)


How do I change what lines sees as a new line.  Is it
:$nl-in?  A tab in this case.

Some of my missteps:

$ p6 'my $x="a\tb\tc\td\t"; dd $x; for $x.lines(:!chomp, "\t") {dd $_};'
Str $x = "a\tb\tc\td\t"


$ p6 'my $x="a\tb\tc\td\t"; dd $x; for $x.lines(:!chomp, :$nl-in = 
["\x0A", "\r\n"]) {dd $_};'

===SORRY!=== Error while compiling -e
Variable '$nl-in' is not declared
at -e:1
--> tc\td\t"; dd $x; for $x.lines(:!chomp, :⏏$nl-in = ["\x0A", 
"\r\n"]) {dd $_};


$ p6 'my $x="a\tb\tc\td\t"; dd $x; for $x.lines(:!chomp, :nl-in = 
["\x0A", "\r\n"]) {dd $_};'

Str $x = "a\tb\tc\td\t"
Cannot modify an immutable Pair (nl-in => True)
  in block  at -e line 1


Many thanks,
-T


Re: lines :$nl-in question

2020-08-30 Thread ToddAndMargo via perl6-users
On Sat, Aug 29, 2020 at 9:05 PM ToddAndMargo via perl6-users 
mailto:perl6-users@perl.org>> wrote:



And if you would not mind, what is the official name
of variables that begin with ":"



On 2020-08-30 00:43, Brad Gilbert wrote:

There are no variables that begin with :

There are variable declarations in signatures that begin with :

:$foo is exactly the same as :foo($foo)

     sub bar ( :$foo ) {…}
     sub bar ( :foo($foo) ){…}

:$foo in a signature is a shortcut for declaring a named argument :foo() 
and a variable with the same base name $foo


:$foo also does the same thing as an argument

     my $foo = 1;

     bar( :$foo )
     bar( :foo($foo) )
     bar( foo => $foo )

Note that forms with : can be outside of the signature

     bar( ) :$foo
     bar( ) :foo($foo)



Follow up questions:

1) what is the exact name used to describe these critters?

2) is there a manual page on them?


Re: Reminder: Fill Raku's user survey!

2020-08-30 Thread ToddAndMargo via perl6-users
El dom., 30 ago. 2020 a las 11:34, ToddAndMargo (>) escribió:


On 2020-08-30 02:26, JJ Merelo wrote:
 > Hi,
 > Here's the link
 >

https://docs.google.com/forms/d/e/1FAIpQLSdRPBdn1iRN_sT8BMNMOBhVbEY1u8ngZWVwLyM37sqsa4OLwQ/viewform
 >
 > It'll take you five minutes, top. Answers will be summarized and
 > carefully considered. Thanks!
 >
 > --
 > JJ


Hi JJ,

I missed one when I filled out the list:

8)  The developers seriously need to fix the staging
compile times on par with Perl 5:

$ raku -c --stagestats GetUpdates.pl6
Stage start  :   0.000
Stage parse  :  18.108
Stage syntaxcheck: Syntax OK

Any way you an get it into the fray?

Many thnks,
-T


On 2020-08-30 02:36, JJ Merelo wrote:
In principle, answers are anonymous, so no way, sorry. Did you 
*actually* fill the form, though, or just answered the question here? We 
need them to be in the form, to consider them.


Indeed I did.  I just forgot to add the "staging" problem
to the fray.  Then I started taklig about it on this forum.

And I do not care if I am anonymous, especially if when you
get to mine, you will know immediately it is me.  My views
are quite public.

Is there another place to report this? A bugzilla?  Is
there a bug already open on it?

-T


Re: Reminder: Fill Raku's user survey!

2020-08-30 Thread JJ Merelo
In principle, answers are anonymous, so no way, sorry. Did you *actually*
fill the form, though, or just answered the question here? We need them to
be in the form, to consider them.

El dom., 30 ago. 2020 a las 11:34, ToddAndMargo ()
escribió:

> On 2020-08-30 02:26, JJ Merelo wrote:
> > Hi,
> > Here's the link
> >
> https://docs.google.com/forms/d/e/1FAIpQLSdRPBdn1iRN_sT8BMNMOBhVbEY1u8ngZWVwLyM37sqsa4OLwQ/viewform
> >
> > It'll take you five minutes, top. Answers will be summarized and
> > carefully considered. Thanks!
> >
> > --
> > JJ
>
>
> Hi JJ,
>
> I missed one when I filled out the list:
>
> 8)  The developers seriously need to fix the staging
> compile times on par with Perl 5:
>
> $ raku -c --stagestats GetUpdates.pl6
> Stage start  :   0.000
> Stage parse  :  18.108
> Stage syntaxcheck: Syntax OK
>
> Any way you an get it into the fray?
>
> Many thnks,
> -T
>


-- 
JJ


Re: Reminder: Fill Raku's user survey!

2020-08-30 Thread ToddAndMargo via perl6-users

On 2020-08-30 02:26, JJ Merelo wrote:

Hi,
Here's the link 
https://docs.google.com/forms/d/e/1FAIpQLSdRPBdn1iRN_sT8BMNMOBhVbEY1u8ngZWVwLyM37sqsa4OLwQ/viewform


It'll take you five minutes, top. Answers will be summarized and 
carefully considered. Thanks!


--
JJ



Hi JJ,

I missed one when I filled out the list:

8)  The developers seriously need to fix the staging
compile times on par with Perl 5:

$ raku -c --stagestats GetUpdates.pl6
Stage start  :   0.000
Stage parse  :  18.108
Stage syntaxcheck: Syntax OK

Any way you an get it into the fray?

Many thnks,
-T


Reminder: Fill Raku's user survey!

2020-08-30 Thread JJ Merelo
Hi,
Here's the link
https://docs.google.com/forms/d/e/1FAIpQLSdRPBdn1iRN_sT8BMNMOBhVbEY1u8ngZWVwLyM37sqsa4OLwQ/viewform

It'll take you five minutes, top. Answers will be summarized and carefully
considered. Thanks!

-- 
JJ


Re: lines :$nl-in question

2020-08-30 Thread ToddAndMargo via perl6-users

On 2020-08-30 02:00, Richard Hainsworth wrote:
While your logical transitions move you down some interesting rabbit 
holes, if you are going to say stuff, at least check first.


On 30/08/2020 00:39, ToddAndMargo via perl6-users wrote:

On 2020-08-28 23:51, Tobias Boege wrote:




You do realize "invocant" is not even in the dictionary


Not true, Todd. Took me 5 seconds to find:

https://www.merriam-webster.com/dictionary/invocant


Definition of /invocant/



Here is where I looked:

https://duckduckgo.com/?q=defination+invocant=ffab=definition

I did not scroll down far enough to the merrian webster
hit.  Folks kept thinking I misspelled "innocent"

https://www.merriam-webster.com/dictionary/invocant
 History and Etymology for invocant
 Latin invocant-, invocans, present participle of
 invocare to invoke

Which was right in line with what Brad said.

:-)

-T


Re: lines :$nl-in question

2020-08-30 Thread ToddAndMargo via perl6-users

On 2020-08-30 00:48, Brad Gilbert wrote:

Invocant is in the dictionary though.

In fact it is from Latin.

Origin & history:
   Derived from in- + vocō ("I call").

Verb:
   I invoke
   I call (by name)

In fact that is pretty close to the same meaning as it is used in the 
Raku docs.


It is the object that we are calling (aka invoking) a method on.


Great explanation. It is in the Latin dictionary.
Thank you!


Re: lines :$nl-in question

2020-08-30 Thread Richard Hainsworth

Todd,

While your logical transitions move you down some interesting rabbit 
holes, if you are going to say stuff, at least check first.


On 30/08/2020 00:39, ToddAndMargo via perl6-users wrote:

On 2020-08-28 23:51, Tobias Boege wrote:




You do realize "invocant" is not even in the dictionary


Not true, Todd. Took me 5 seconds to find:

https://www.merriam-webster.com/dictionary/invocant


   Definition of /invocant/

*: *one that invokes


(esoteric or requiring special knowledge)?


And whilst we there:


   Definition of /funny/

 (Entry 1 of 2)

1a *: *affording light mirth and laughter *: *amusing 
 His account of the 
war came in bits and pieces, sometimes bloody, sometimes funny.— Robert 
Penn Warren
b *: *seeking or intended to amuse *: *facetious 
 Don't take him so 
seriously; he was just being funny.
2 *: *differing from the ordinary in a suspicious, perplexing, quaint, 
or eccentric way *: *peculiar 
 My car has been 
making a funny noise. —often used as a sentence modifierFunny, things 
didn't turn out the way we planned.
3 *: *involving trickery or deception told his prisoner not to try 
anything funny


Which is not the same as 'esoteric'

So operators are a 'funny' sort of function, is an apt use of the word 
'funny'. But "operators are an 'esoteric' sort of function" does not work.


 “Anyone who can only think of one way to spell a
 word obviously lacks imagination.”
    -- Mark Twain

I do have to look at it twice when I see it, but I do figure
it out.  So is okay with me.


which returns
 an IO::Handle,




Re: liens and :chomp question

2020-08-30 Thread ToddAndMargo via perl6-users

On 2020-08-30 00:35, Tobias Boege wrote:

On Sun, 30 Aug 2020, ToddAndMargo via perl6-users wrote:

- You are calling .lines on the value of .IO.open which is an
  IO::Handle. IO::Handle.lines does not take a named argument
  :chomp, so passing one is useless.


That explains it.

Bu:
  https://docs.raku.org/type/IO::Path#method_lines

  (IO::Path) method lines
  Defined as:

  method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in =
["\x0A", "\r\n"], |c --> Seq:D)

  Opens the invocant and returns its lines.

  The behavior is equivalent to opening the file specified
  by the invocant, forwarding the :$chomp, :$enc, and
  :$nl-in arguments to IO::Handle.open, then calling
  IO::Handle.lines on that handle, forwarding any of
  the remaining arguments to that method, and returning
  the resultant Seq.

The "signature" line (cryptogram) clearly stated that
":$chomp" is a parameter of the method.

Now you are obviously correct that :chomp is ignored.
If I am not mistaken, I have just tripped over another
error in the documentation.  Your take?



You confuse two methods that have the same name "lines". One of them,
which exists in the IO::Path class, has a :chomp argument. The other,
on IO::Handle does not.

   "path".IO.lines()   <-- calls lines on an IO::Path (supports :chomp)
   "path".IO.open.lines()  <-- calls lines on an IO::Handle (does not support 
:chomp)

In the second case, if you want chomping to happen you have to pass
the :chomp to the *open* call, as you do below:


Hi Tobias,

The terrible example they included was:
'50GB-file'.IO.lines.grep(*.contains: 'Perl').elems,
  " lines that mention Perl";

I left off the "grep" and the "elems".

"Lines.txt".IO.open.lines

This was the example they gave for

method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in = 
["\x0A", "\r\n"], |c --> Seq:D)


Exactly what is "IO::Path:D:"?

I know that :D is declared and the ":" after it
is a delimiter.  That leaved "IO::Path":

https://docs.raku.org/type/IO::Path

And I can't make heads or tails out of the page.

My goal is to learn how to use :$chomp = True,
:$enc = 'utf8', :$nl-in, and, |c

Thank you for the help!
-T


Re: lines :$nl-in question

2020-08-30 Thread Brad Gilbert
Invocant is in the dictionary though.

In fact it is from Latin.

Origin & history:
  Derived from in- + vocō ("I call").

Verb:
  I invoke
  I call (by name)

In fact that is pretty close to the same meaning as it is used in the Raku
docs.

It is the object that we are calling (aka invoking) a method on.

On Sat, Aug 29, 2020 at 6:39 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 2020-08-28 23:51, Tobias Boege wrote:
> > On Fri, 28 Aug 2020, ToddAndMargo via perl6-users wrote:
> >> https://docs.raku.org/type/IO::Path#method_lines
> >>
> >> (IO::Path) method lines
> >>
> >> Defined as:
> >>
> >> method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in =
> ["\x0A", "\r\n"], |c --> Seq:D)
> >>
> >> Opens the invocant and returns its lines.
> >>
> >> The behavior is equivalent to opening the file specified
> >> by the invocant, forwarding the :$chomp, :$enc,
> >> and :$nl-in arguments to IO::Handle.open, then calling
> >> IO::Handle.lines on that handle, forwarding any of the
> >> remaining arguments to that method, and returning the
> >> resultant Seq.
> >>
> >> And if I am not pushing it, what is `|c`?
> >>
> >> [...]
> >> I do not understand
> >
> > The description of this method says that it shall do two things:
> >
> >- open the invocant path (IIRC you like to use the phrase
> >  "what is fed into it" instead of "invocant")
>
> What ???  Okay, you know me.
>
> You do realize "invocant" is not even in the dictionary
> (esoteric or requiring special knowledge)?
>
>   “Anyone who can only think of one way to spell a
>   word obviously lacks imagination.”
>  -- Mark Twain
>
> I do have to look at it twice when I see it, but I do figure
> it out.  So is okay with me.
>
> > which returns
> >  an IO::Handle,
> >
> >- then call the lines method on this IO::Handle, resulting
> >  in a sequence of lines (Seq in Raku), and it should return
> >  this same Seq value.
> >
> > The lines method on an IO::Path does the same as the lines method on an
> > IO::Handle, except that it has to open the path before to get a handle.
> >
> > The arguments to the IO::Path.lines method therefore split into two
> groups:
> >
> >- :$chomp, :$enc, :$nl-in which are passed on to the open call
> >  in the first bullet point above,
> >
> >- all the remaining arguments, whatever they are, are *captured*
> >  by the syntax |c and will be forwarded to the IO::Handle.lines
> >  call in the second bullet point above.
> >
> > The |c is a so-called capture parameter [1]. It is used in a signature
> > (what you stubbornly call "cryptogram") when a method wants to inspect
> > some (or none) of the arguments it got but keep all the others in a
> > black box, named c here. The capture black box allows forwarding these
> > extra arguments to some other call. The point is that the IO::Path.lines
> > method does not need to know which arguments the target IO::Handle.lines
> > method accepts. It only needs to take everything in and pass it on.
> >
> > It follows that you read about the meaning of the individual arguments or
> > which arguments it makes sense to pass to IO::Path.lines in the
> documentation
> > pages for the IO::Handle.open and IO::Handle.lines methods, which are
> linked
> > to in the text. Really, everything that IO::Path.lines does is
> redistribute
> > its arguments to two other method calls.
> >
> > The documentation of lines does not tell you that |c is a capture
> parameter,
> > but it described what it is used for with the slide-in
> >
> >[...] forwarding any of the remaining arguments to that method [...]
> >
> > in the paragraph you quoted. The connection of that slide-in with the
> > "|c thing" is a matter of text comprehension.
> >
> > Best,
> > Tobias
> >
> > [1] https://docs.raku.org/type/Signature#Capture_parameters
> >
>
> Hi Tobias,
>
> That was a wonderful explanation.  I am writing it down!
> Thank you!
>
> -T
>
> I will probably forget the term "Signature" several more
> times.  :'(
>


Re: liens and :chomp question

2020-08-30 Thread ToddAndMargo via perl6-users

On Sat, Aug 29, 2020 at 10:15 PM ToddAndMargo via perl6-users
 wrote:


Hi All,

I am trying to figure out how to use line with :$chomp.
Now what am I doing wrong?


$ alias p6
alias p6='perl6 -e'

$ p6 'say "Lines.txt".IO.open.lines(:chomp)[3,2];'
(Line 3 Line 2)

$ p6 'say "Lines.txt".IO.open.lines(:!chomp)[3,2];'
(Line 3 Line 2)

I am looking for

Line 3
Line 2

Many thanks,
-T


On 2020-08-29 23:10, William Michels via perl6-users wrote:

Maybe this is what you want?

~$ raku -e 'say "test_lines.txt".IO.lines;'
(Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Line 11)

~$ raku -e 'say "test_lines.txt".IO.lines.join("\n");'
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10
Line 11

~$ raku -e 'say "test_lines.txt".IO.lines[3,2].join("\n");'
Line 4
Line 3

~$ raku -e 'say "test_lines.txt".IO.lines[ (3,2).map(*-1) ].join("\n");'
Line 3
Line 2

By default, Raku strips new lines off when reading data in, and adds
newlines back on when outputting with "say" or "put" (but not
"print"). Using "WHAT" you can get an idea how Raku behaves
differently depending on whether you call "IO.lines" or "for lines()"
on an input file:

~$ raku -e '"test_lines.txt".IO.lines.WHAT.say;'
(Seq)

~$ raku -e '"test_lines.txt".IO.lines[3,2].WHAT.say;'
(List)

~$ cat "test_lines.txt" | raku -e 'for lines()[3,2] {.WHAT.say};'
(Str)
(Str)


HTH, Bill.



Hi Bill,

Actually what I am after is to learn

https://docs.raku.org/type/IO::Path#method_lines
method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in = 
["\x0A", "\r\n"], |c --> Seq:D)


Specifically :$chomp = True, :$enc = 'utf8', :$nl-in, and |c.

But, I do love the examples you sent!

Thank you,
-T



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


Re: lines :$nl-in question

2020-08-30 Thread Brad Gilbert
There are no variables that begin with :

There are variable declarations in signatures that begin with :

:$foo is exactly the same as :foo($foo)

sub bar ( :$foo ) {…}
sub bar ( :foo($foo) ){…}

:$foo in a signature is a shortcut for declaring a named argument :foo()
and a variable with the same base name $foo

:$foo also does the same thing as an argument

my $foo = 1;

bar( :$foo )
bar( :foo($foo) )
bar( foo => $foo )

Note that forms with : can be outside of the signature

bar( ) :$foo
bar( ) :foo($foo)

On Sat, Aug 29, 2020 at 9:05 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 2020-08-29 17:04, ToddAndMargo via perl6-users wrote:
> > On 2020-08-28 23:51, Tobias Boege wrote:
> >>- :$chomp, :$enc, :$nl-in which are passed on to the open call
> >>  in the first bullet point above,
> >
> > Hi Tobias,
> >
> > I am in process of revising my keeper on lines.
> > May I talk you out of examples of the syntax used
> > by :$chomp, :$enc, and :$nl-in?
> >
> > Many thanks,
> > -T
>
> And if you would not mind, what is the official name
> of variables that begin with ":"
>


Re: liens and :chomp question

2020-08-30 Thread Tobias Boege
On Sun, 30 Aug 2020, ToddAndMargo via perl6-users wrote:
> >- You are calling .lines on the value of .IO.open which is an
> >  IO::Handle. IO::Handle.lines does not take a named argument
> >  :chomp, so passing one is useless.
> 
> That explains it.
> 
> Bu:
>  https://docs.raku.org/type/IO::Path#method_lines
> 
>  (IO::Path) method lines
>  Defined as:
> 
>  method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in =
> ["\x0A", "\r\n"], |c --> Seq:D)
> 
>  Opens the invocant and returns its lines.
> 
>  The behavior is equivalent to opening the file specified
>  by the invocant, forwarding the :$chomp, :$enc, and
>  :$nl-in arguments to IO::Handle.open, then calling
>  IO::Handle.lines on that handle, forwarding any of
>  the remaining arguments to that method, and returning
>  the resultant Seq.
> 
> The "signature" line (cryptogram) clearly stated that
> ":$chomp" is a parameter of the method.
> 
> Now you are obviously correct that :chomp is ignored.
> If I am not mistaken, I have just tripped over another
> error in the documentation.  Your take?
> 

You confuse two methods that have the same name "lines". One of them,
which exists in the IO::Path class, has a :chomp argument. The other,
on IO::Handle does not.

  "path".IO.lines()   <-- calls lines on an IO::Path (supports :chomp)
  "path".IO.open.lines()  <-- calls lines on an IO::Handle (does not support 
:chomp)

In the second case, if you want chomping to happen you have to pass
the :chomp to the *open* call, as you do below:

> $ p6 'dd "Lines.txt".IO.open(:chomp).lines()[3,2];'
> ("Line 3", "Line 2")
> 
> $ p6 'dd "Lines.txt".IO.open(:!chomp).lines()[3,2];'
> ("Line 3\n", "Line 2\n")
> 
> $ p6 'say "Lines.txt".IO.open(:!chomp).lines()[3,2];'
> (Line 3
>  Line 2<-- why the space?
> )
> 

The better question is "whose space". You print again the List of lines
you obtain by indexing the return value of .lines, so expect output in
the form of "(item1 item2 ...)". This is where your space comes from.
Lists print that way. They insert spaces between their elements.

In this case, you had :chomp disabled, so the "Line 3" item printed
"Line 3\n", including the newline that was not chomped, then the space
and then the next item, "Line2\n" with its newline, then the closing
parenthesis which is also part of printing a List.

This serves to better illustrate where one element of the List ends
and where the next begins. The space separate them:

  $ rakudo -e 'say "Lines.txt".IO.open(:!chomp).lines()[3,2].map({ "«$_»" });'
  («Line 3
  » «Line 2
  »)

Best,
Tobias

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


Re: liens and :chomp question

2020-08-30 Thread ToddAndMargo via perl6-users

On 2020-08-29 23:09, Tobias Boege wrote:

On Sat, 29 Aug 2020, ToddAndMargo via perl6-users wrote:

Hi All,

I am trying to figure out how to use line with :$chomp.
Now what am I doing wrong?


$ alias p6
alias p6='perl6 -e'

$ p6 'say "Lines.txt".IO.open.lines(:chomp)[3,2];'
(Line 3 Line 2)

$ p6 'say "Lines.txt".IO.open.lines(:!chomp)[3,2];'
(Line 3 Line 2)

I am looking for

Line 3
Line 2



Then I would suggest

   say $_ for "Lines.txt".IO.lines[3,2]


Now what am I doing wrong?


   - You are calling .lines on the value of .IO.open which is an
 IO::Handle. IO::Handle.lines does not take a named argument
 :chomp, so passing one is useless. 


That explains it.

Bu:
 https://docs.raku.org/type/IO::Path#method_lines

 (IO::Path) method lines
 Defined as:

 method lines(IO::Path:D: :$chomp = True, :$enc = 'utf8', :$nl-in = 
["\x0A", "\r\n"], |c --> Seq:D)


 Opens the invocant and returns its lines.

 The behavior is equivalent to opening the file specified
 by the invocant, forwarding the :$chomp, :$enc, and
 :$nl-in arguments to IO::Handle.open, then calling
 IO::Handle.lines on that handle, forwarding any of
 the remaining arguments to that method, and returning
 the resultant Seq.

The "signature" line (cryptogram) clearly stated that
":$chomp" is a parameter of the method.

Now you are obviously correct that :chomp is ignored.
If I am not mistaken, I have just tripped over another
error in the documentation.  Your take?

Now to beat a dead horse some more, who in the right
mind thinks this example belongs as an example of
"(IO::Path) method lines"?  It does not show how to
use any of the options and is a far better example
of how to use "grep" and "elems" than "(IO::Path)
method lines". Me thinks someone was showing off.

   say "The file contains ",
  '50GB-file'.IO.lines.grep(*.contains: 'Perl').elems,
  " lines that mention Perl";
   # OUTPUT: «The file contains 72 lines that mention Perl␤»



The .lines method on an
 IO::Path, however, which I call in my snippet, supports
 such an argument. You could call .IO.lines(:chomp) or
 .IO.open(:chomp).lines.

   - You should use :chomp and not :!chomp because :chomp removes
 the trailing newline from every line read for you. When you
 use `say`, a trailing newline is added automatically, so in
 order to get only one newline in the output per item, you
 have to :chomp. The :chomp argument does not appear in my
 snippet because it is the default, but you could have done

   say $_ for "Lines.txt".IO.lines(:!chomp)[3,2]

 to see the effect of not chomping.

   - What you `say` is the return value of indexing the Seq that
 is returned by .lines. This is an object of type List and
 will always print in the format "(item1 item2 ...)" and not
 in the format you desire. In the snippet above I iterate
 over that List with `for` and print every item in a new line.

Best,
Tobias




$ p6 'dd "Lines.txt".IO.open(:chomp).lines()[3,2];'
("Line 3", "Line 2")

$ p6 'dd "Lines.txt".IO.open(:!chomp).lines()[3,2];'
("Line 3\n", "Line 2\n")

$ p6 'say "Lines.txt".IO.open(:!chomp).lines()[3,2];'
(Line 3
 Line 2<-- why the space?
)

$ p6 'print "Lines.txt".IO.open(:!chomp).lines()[3,2];'
Line 3
 Line 2<-- why the space?

$ p6 'print "Lines.txt".IO.open(:!chomp).lines()[3,2,5];'
Line 3
 Line 2<-- why the space?
 Line 5<-- why the space?

-T


Re: liens and :chomp question

2020-08-30 Thread William Michels via perl6-users
Maybe this is what you want?

~$ raku -e 'say "test_lines.txt".IO.lines;'
(Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Line 11)

~$ raku -e 'say "test_lines.txt".IO.lines.join("\n");'
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10
Line 11

~$ raku -e 'say "test_lines.txt".IO.lines[3,2].join("\n");'
Line 4
Line 3

~$ raku -e 'say "test_lines.txt".IO.lines[ (3,2).map(*-1) ].join("\n");'
Line 3
Line 2

By default, Raku strips new lines off when reading data in, and adds
newlines back on when outputting with "say" or "put" (but not
"print"). Using "WHAT" you can get an idea how Raku behaves
differently depending on whether you call "IO.lines" or "for lines()"
on an input file:

~$ raku -e '"test_lines.txt".IO.lines.WHAT.say;'
(Seq)

~$ raku -e '"test_lines.txt".IO.lines[3,2].WHAT.say;'
(List)

~$ cat "test_lines.txt" | raku -e 'for lines()[3,2] {.WHAT.say};'
(Str)
(Str)


HTH, Bill.





On Sat, Aug 29, 2020 at 10:15 PM ToddAndMargo via perl6-users
 wrote:
>
> Hi All,
>
> I am trying to figure out how to use line with :$chomp.
> Now what am I doing wrong?
>
>
> $ alias p6
> alias p6='perl6 -e'
>
> $ p6 'say "Lines.txt".IO.open.lines(:chomp)[3,2];'
> (Line 3 Line 2)
>
> $ p6 'say "Lines.txt".IO.open.lines(:!chomp)[3,2];'
> (Line 3 Line 2)
>
> I am looking for
>
> Line 3
> Line 2
>
> Many thanks,
> -T


Re: liens and :chomp question

2020-08-30 Thread Tobias Boege
On Sat, 29 Aug 2020, ToddAndMargo via perl6-users wrote:
> Hi All,
> 
> I am trying to figure out how to use line with :$chomp.
> Now what am I doing wrong?
> 
> 
> $ alias p6
> alias p6='perl6 -e'
> 
> $ p6 'say "Lines.txt".IO.open.lines(:chomp)[3,2];'
> (Line 3 Line 2)
> 
> $ p6 'say "Lines.txt".IO.open.lines(:!chomp)[3,2];'
> (Line 3 Line 2)
> 
> I am looking for
> 
> Line 3
> Line 2
> 

Then I would suggest

  say $_ for "Lines.txt".IO.lines[3,2]

> Now what am I doing wrong?

  - You are calling .lines on the value of .IO.open which is an
IO::Handle. IO::Handle.lines does not take a named argument
:chomp, so passing one is useless. The .lines method on an
IO::Path, however, which I call in my snippet, supports
such an argument. You could call .IO.lines(:chomp) or
.IO.open(:chomp).lines.

  - You should use :chomp and not :!chomp because :chomp removes
the trailing newline from every line read for you. When you
use `say`, a trailing newline is added automatically, so in
order to get only one newline in the output per item, you
have to :chomp. The :chomp argument does not appear in my
snippet because it is the default, but you could have done

  say $_ for "Lines.txt".IO.lines(:!chomp)[3,2]

to see the effect of not chomping.

  - What you `say` is the return value of indexing the Seq that
is returned by .lines. This is an object of type List and
will always print in the format "(item1 item2 ...)" and not
in the format you desire. In the snippet above I iterate
over that List with `for` and print every item in a new line.

Best,
Tobias

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk