Re: Could this be any more obscure?

2018-09-26 Thread JJ Merelo
El jue., 27 sept. 2018 a las 3:51, ToddAndMargo ()
escribió:

> On 9/26/18 6:31 PM, ToddAndMargo wrote:
> > On 9/26/18 6:18 PM, Curt Tilmes wrote:>
> >  >  > The methods don't take [].  You are calling [] on the thing
> > that the
> >  >  > methods return.
> >
> >>>
> >>> Yes, I know.  And it is human readable too.  It is one of the
> >>> many reasons I adore Perl 6.
> >>>
> >>> Where in
> >>>  multi method words(Str:D $input: $limit = Inf --> Positional)
> >>> does it state that "words" will do that?  Not all methods will.
> >>> So it need to be stated when they will.
> >>>
> >>>
> >
> >
> >
> >  > The part where it says "--> Positional" says the thing that gets
> >  > returned is Positional.
> >  >
> >  > A Positional thing has all sorts of methods and operators you can use,
> >  > including []
> >  >
> >  > Not all methods will, of course.  Only those that say "--> Positional"
> >  > return a Positional that acts like that.
> >  >
> >  > Curt
> >
> > Hi Curt,
> >
> > Perfect! Thank you!
> >
> > So all methods that respond with --> Positional will accept []
> >
> > Awesome!
> >
> > -T
>
>
>
> I do believe the reason I spaced on this was that when I see "-->"
> what goes through my head is "this is the value(s) returned".
> I had not idea it would reflect backwards and affect the method.
>

It does not.

say "Flim Flam Flum".words[2] # OUTPUT: «Flum␤»

is exactly the same as

say "Flim Flam Flum".words()[2] # OUTPUT: «Flum␤»

And exactly the same as

say "Flim Flam Flum".words(Inf)[2] # OUTPUT: «Flum␤»

And exactly the same as

my @flim-flam-flum = "Flim Flam Flum".words; # @flim-flam-flum carries
an @, ergo it's a Positional
say @flim-flam-flum[2] # OUTPUT: «Flum␤»

In Perl 6 you can chain calls, that's what is meant by postcircumfix, it
means you can put the operator like thing (in this case, []) _behind_
(post) the thing you are calling, plus you are putting the arguments
_inside_ the operator (that's the circumfix part). You can also do

say "Flim Flam Flum".words[1,2][0] # OUTPUT: «Flam␤»

You are first post-circumfixing [] over the return value of words, getting
2 elements in a Positional (an List in this case, Positional is a Role, not
a Class), and them post-circumfixing again getting the first of these two
elements. You can do this to exhaustion, as long as it's an object method
or a post-circumfix operator, chaining the one after the other. None of
them is "reflecting" on anything, you are just chaining calls, which is a
nice and compact thing to do.

Cheers
-- 
JJ


Re: Could this be any more obscure?

2018-09-26 Thread JJ Merelo
El jue., 27 sept. 2018 a las 3:19, Brandon Allbery ()
escribió:

> Additionally: Perl 5 docs don't run into this because perl 5 has only 3
> types: scalar, list, hash.
>
> Perl 6 has lots of types, each of which has its own behavior. We use roles
> to package up common
>

_and_ roles _and_ contexts.

behaviors. Positional is the role for "can be indexed" / "understands []".
> Don't just assume you know what Positional is because you know its English
> meaning; look at what it actually does, and you will find the []
> documentation.
>

Right: https://docs.perl6.org/type/Positional Just type "Positional" into
the search box, and scroll down to where it says "Roles".

Cheers

JJ


Re: Could this be any more obscure?

2018-09-26 Thread JJ Merelo
El mié., 26 sept. 2018 a las 23:31, Laurent Rosenfeld via perl6-users (<
perl6-users@perl.org>) escribió:

> You can set a limit to the number of items (words) you want to retrieve:
> you will get only the first $limit words.
>
> If you don't supply any limit, Inf can be thought as the default value for
> the number of items, i.e. there is no limit and the routine will return as
> many words as it can from the source input.
>

And this is one of the things I love Perl 6 for, its consistency. Infinity
is literally no limit. Using it meaning "no limit" is genius. Not "0 in
this case means no limit" or "-1 means no limit" or "this constant meaning
unavailable" or whatever. Infinity has no limit, we use them as a parameter
to imply that argument has no limit.

Cheers

JJ


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 7:28 PM, Brandon Allbery wrote:
I often feel like perlmonks is about 80% of what's wrong with perl 5 
these days.


And they are  G-R-O-U-C-H-Y  too!!!


Re: Could this be any more obscure?

2018-09-26 Thread Curt Tilmes
On Wed, Sep 26, 2018 at 10:30 PM ToddAndMargo  wrote:

>
> > You can also call .elems to see how many elements there are and
> > .AT-POS() (same as []), .EXISTS-POS() to see if an element exists, etc.
>

One small correction before the nit-pickers jump on me...
.AT-POS() isn't *really* the same as [] -- [] is much smarter and can do
more stuff...  One of
the things it can do is the same as .AT-POS().

Curt


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 7:28 PM, Curt Tilmes wrote:



On Wed, Sep 26, 2018 at 10:19 PM ToddAndMargo > wrote:



My understanding it that if it uses "--Positinal"
I can use []


Yes.  Everything described here: https://docs.perl6.org/type/Positional

You can also call .elems to see how many elements there are and 
.AT-POS() (same as []), .EXISTS-POS() to see if an element exists, etc.


"a b c d e".words.elems
5
"a b c d e".words(3).elems
3
"a b c d e".words.AT-POS(2)
c
"a b c d e".words(3).EXISTS-POS(4)
False

Curt


Thank you!


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 7:01 PM, Curt Tilmes wrote:


And where is it stated that an empty () defaults to all of them
and not to none of them?


empty() says set everything to defaults

If you have
sub foo($x = 3) { say $x }

and call foo(2), $x will be set to 2 and it will print out 2.

If you don't pass in $x, saying just foo()  or even just foo by itself, 
it is exactly the same

as saying foo(3).  You just get the default and it prints 3.

foo(3)
foo()
foo

are all the same.

If I have  sub foo($x = Inf) (say $x)
I'm just making the default parameter Inf instead of 3

     And where is it stated that an empty () defaults to all of them
     and not to none of them?

It tells you right in the signature what the default is.  It says 
"$limit = Inf", Inf is
an infinite number of words, i.e. all of them.  If it said "$limit = 0", 
then the default would

be 0, or none of them.  That isn't what it states.

words(Inf)
words()
words

are all the same.

Curt



Beautifully written.  Thank you Curt.


Re: Could this be any more obscure?

2018-09-26 Thread Brandon Allbery
I often feel like perlmonks is about 80% of what's wrong with perl 5 these
days.

On Wed, Sep 26, 2018 at 10:27 PM ToddAndMargo  wrote:

> On 9/26/18 6:36 PM, The Sidhekin wrote:
> > On Thu, Sep 27, 2018 at 3:14 AM Peter Scott  > > wrote:
> >
> > On 9/26/2018 3:21 PM, ToddAndMargo wrote:
> >  > Do your really think any beginner would be able to figure out
> >  > "words" from the above?
> >
> > If the beginner had studied the metasyntax of function prototypes,
> > probably.
> >
> >
> >Yeah, that's where a beginner needs to begin, in order to learn Perl6
> > from the docs.
> >
> >Syntax, metasyntax, all sorts of basics ...
> >
> > I heard about people
> > who claim to have taught themselves Perl 5 from the Camel instead of
> > the
> > Llama, but they are few and far between, and in any case, most of the
> > Camel contains exposition, if dense.
> >
> >
> >I learned Perl 5 from the man pages.  It was more fun than efficient,
> > but I could easily afford it: It was not (at the time) my job. :)
> >
> >But we're not all wired the same way.  This endeavour looks to me
> > neither fun nor efficient.
> >
> >
> > Eirik
>
>
> Oh my goodness, did you guys ever use "perl monks".  They don't
> usually answer follow up questions and the format is
> excruciatingly difficult to write or follow things in.
>
>
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>


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


Re: Could this be any more obscure?

2018-09-26 Thread Brandon Allbery
And again: this is only because you know perl 5. People are not born
knowing perl 5; to someone who doesn't know it, perldoc raises the same
kinds of questions you have been asking, and the answers have to be found
in perlsyn or perldata, etc. Which is exactly what you have been
complaining about with respect to perl 6 doing the same kind of thing.

On Wed, Sep 26, 2018 at 10:25 PM ToddAndMargo  wrote:

> On 9/26/18 7:17 PM, Brandon Allbery wrote:
> > No, perldoc only "tells you everything" if you already know perl 5. You
> > do, so you don't see this.
>
> perldocs is wonderful for the beginner.  It is the ONLY thing
> I miss in Perl 6.
>
> I like Perl 5; I adore Perl 6.  I especially love the
> clean up of sub declarations (I write in Top Down) and
> the clean up of regex's.
>
> Start simple, work up to the complex.  I am starting
> to contribute to help this along.  My beginners
> status is perfect for this as I don't miss what other think
> they see because they already know what it is suppose to say.
>
> Oh ya, and in Perl 6 EVERYTHING starts counting from zero,
> unlike Perl 5 (p5's m/ starts at $1).  No guess work and one
> liners to figure it out.
>


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


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 6:36 PM, The Sidhekin wrote:
On Thu, Sep 27, 2018 at 3:14 AM Peter Scott > wrote:


On 9/26/2018 3:21 PM, ToddAndMargo wrote:
 > Do your really think any beginner would be able to figure out
 > "words" from the above?

If the beginner had studied the metasyntax of function prototypes,
probably.


   Yeah, that's where a beginner needs to begin, in order to learn Perl6 
from the docs.


   Syntax, metasyntax, all sorts of basics ...

I heard about people
who claim to have taught themselves Perl 5 from the Camel instead of
the
Llama, but they are few and far between, and in any case, most of the
Camel contains exposition, if dense.


   I learned Perl 5 from the man pages.  It was more fun than efficient, 
but I could easily afford it: It was not (at the time) my job. :)


   But we're not all wired the same way.  This endeavour looks to me 
neither fun nor efficient.



Eirik



Oh my goodness, did you guys ever use "perl monks".  They don't
usually answer follow up questions and the format is
excruciatingly difficult to write or follow things in.



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


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 7:17 PM, Brandon Allbery wrote:
No, perldoc only "tells you everything" if you already know perl 5. You 
do, so you don't see this.


perldocs is wonderful for the beginner.  It is the ONLY thing
I miss in Perl 6.

I like Perl 5; I adore Perl 6.  I especially love the
clean up of sub declarations (I write in Top Down) and
the clean up of regex's.

Start simple, work up to the complex.  I am starting
to contribute to help this along.  My beginners
status is perfect for this as I don't miss what other think
they see because they already know what it is suppose to say.

Oh ya, and in Perl 6 EVERYTHING starts counting from zero,
unlike Perl 5 (p5's m/ starts at $1).  No guess work and one
liners to figure it out.


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 7:11 PM, Brandon Allbery wrote:

That's not helping. What didn't you understand?



 It just improves error messages.


My understanding it that if it uses "--Positinal"
I can use []


Re: Could this be any more obscure?

2018-09-26 Thread Brandon Allbery
No, perldoc only "tells you everything" if you already know perl 5. You do,
so you don't see this.

On Wed, Sep 26, 2018 at 10:15 PM ToddAndMargo  wrote:

> On 9/26/18 7:08 PM, Brandon Allbery wrote:
> > English is not a programming language, so it will not help you with
> > understanding what Positional is. Or Callable. Or Mix, or any of the
> > other types and roles in Perl 6. Perl 5 has none of these, so it is
> > never a problem in Perl 5. Instead you have to memorize a bunch of weird
> > special case rules for the things Perl 5 does know about -- and perldoc
> > expects you to have done so. You don't notice because you've already
> > memorized them.
>
> Not an excuse for poor explanations.  Perdocs leaves you knowing
> how to "use" the functions.  Perl 6's does not, unless you
> already know how to use it, then your don't need it.
>
> So rather than grumbling about it, I am going to start
> trying to be part of the solution, rather than just
> grumble about the problem.
>
> This is my latest:
>
>  A booboo and an rfe in contains documentation
>  https://github.com/perl6/doc/issues/2334
>
> Thank you for all the help with this.
>
> -T
>


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


Re: Could this be any more obscure?

2018-09-26 Thread Brandon Allbery
Actually, let's try a simpler one:

pyanfar Z$ 6 'say ([5])[0]'
5

The list [5] understands Positional, and therefore knows about what to do
with the [0]. The parentheses are only because [5][0] looks a bit strange;
but that one works the same way.

The same is true of the list that words() produces. words() doesn't need to
know that, it just gives you a list. Positional describes the "indexable"
attribute of a list.
(If you look up List in the type documentation, you will see other roles
like Iterable that lists know about.)

On Wed, Sep 26, 2018 at 10:11 PM Brandon Allbery 
wrote:

> That's not helping. What didn't you understand? Are you still expecting
> that it is words() that must know all the details of what a list is,
> because a list can't know what itself is?
>
> On Wed, Sep 26, 2018 at 10:09 PM ToddAndMargo 
> wrote:
>
>> On 9/26/18 7:04 PM, Brandon Allbery wrote:
>> > It doesn't. It just improves error messages.
>> >
>> > words() produces a list-like thing; that's what really matters, because
>> > list-like things do the Positional role. Declaring it up front lets
>> Perl
>> > 6 give you an error message early if you use the result in the wrong
>> way
>> > or if the actual implementation of words() doesn't produce something
>> > that does the Positional role.
>> >
>> > pyanfar Z$ 6 'say (sub { [5] })()[0]'
>> > 5
>> >
>> > I didn't declare the anonymous sub as producing a Positional; it just
>> > returns a List. I then invoke it with (), and apply [] to the resulting
>> > List. It's the fact that it produced a List that matters; any List or
>> > Seq or Array or Buf, etc. can be []-ed,because they all do the
>> > Positional role that defines [].
>>
>> Uhhh okay.
>>
>
>
> --
> brandon s allbery kf8nh
> allber...@gmail.com
>


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


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 7:08 PM, Brandon Allbery wrote:
English is not a programming language, so it will not help you with 
understanding what Positional is. Or Callable. Or Mix, or any of the 
other types and roles in Perl 6. Perl 5 has none of these, so it is 
never a problem in Perl 5. Instead you have to memorize a bunch of weird 
special case rules for the things Perl 5 does know about -- and perldoc 
expects you to have done so. You don't notice because you've already 
memorized them.


Not an excuse for poor explanations.  Perdocs leaves you knowing
how to "use" the functions.  Perl 6's does not, unless you
already know how to use it, then your don't need it.

So rather than grumbling about it, I am going to start
trying to be part of the solution, rather than just
grumble about the problem.

This is my latest:

A booboo and an rfe in contains documentation
https://github.com/perl6/doc/issues/2334

Thank you for all the help with this.

-T


Re: Could this be any more obscure?

2018-09-26 Thread Brandon Allbery
That's not helping. What didn't you understand? Are you still expecting
that it is words() that must know all the details of what a list is,
because a list can't know what itself is?

On Wed, Sep 26, 2018 at 10:09 PM ToddAndMargo  wrote:

> On 9/26/18 7:04 PM, Brandon Allbery wrote:
> > It doesn't. It just improves error messages.
> >
> > words() produces a list-like thing; that's what really matters, because
> > list-like things do the Positional role. Declaring it up front lets Perl
> > 6 give you an error message early if you use the result in the wrong way
> > or if the actual implementation of words() doesn't produce something
> > that does the Positional role.
> >
> > pyanfar Z$ 6 'say (sub { [5] })()[0]'
> > 5
> >
> > I didn't declare the anonymous sub as producing a Positional; it just
> > returns a List. I then invoke it with (), and apply [] to the resulting
> > List. It's the fact that it produced a List that matters; any List or
> > Seq or Array or Buf, etc. can be []-ed,because they all do the
> > Positional role that defines [].
>
> Uhhh okay.
>


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


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 3:31 PM, Curt Tilmes wrote:



On Wed, Sep 26, 2018 at 6:13 PM Brandon Allbery > wrote:


On Wed, Sep 26, 2018 at 6:09 PM ToddAndMargo mailto:toddandma...@zoho.com>> wrote:

multi method words(Str:D $input: $limit = Inf --> Positional)


"a b c d".words(3);
(a b c)
passing the $limit parameter in with 3, limits the number of words 
returned to 3.


"a b c d".words(2);
(a b)
Passing a $limit of 2, limits the words returned to 2.

If you *don't* set $limit at all, it gets set to its default, Inf, or 
all the words.  It just never stops because there is no limit.

"a b c d".words();
(a b c d)

The () are optional since you aren't passing in any parameters, so you 
can also just say

"a b c d".words;
(a b c d)

You can store that in a variable
my @x = "a b c d".words;

Once you've got that in a variable, as described in detail on the page 
about Positional, you can access parts of it with the [] operator, for 
example, the word in the '2' position (the third word counting from 0) is

@x[2]
c

What looks a little weird is that you don't need @x at all.  You can 
just call the [] operator directly on the return value from words


"a b c d".words()[2]
c

and of course, you can omit the () since you aren't passing in 
parameters, so this is the same thing


"a b c d".words[2]
c

Curt




Perfect!  Thank you!

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


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 7:04 PM, Brandon Allbery wrote:

It doesn't. It just improves error messages.

words() produces a list-like thing; that's what really matters, because 
list-like things do the Positional role. Declaring it up front lets Perl 
6 give you an error message early if you use the result in the wrong way 
or if the actual implementation of words() doesn't produce something 
that does the Positional role.


pyanfar Z$ 6 'say (sub { [5] })()[0]'
5

I didn't declare the anonymous sub as producing a Positional; it just 
returns a List. I then invoke it with (), and apply [] to the resulting 
List. It's the fact that it produced a List that matters; any List or 
Seq or Array or Buf, etc. can be []-ed,because they all do the 
Positional role that defines [].


Uhhh okay.


Re: Could this be any more obscure?

2018-09-26 Thread Brandon Allbery
On Wed, Sep 26, 2018 at 10:04 PM ToddAndMargo  wrote:

> I presume you have P5's perldocs installed.  Pick
> out any functions (perldoc -f name) and take
> a look at how extraordinarily simple their explanations
> are to understand.  You almost never have to ask for help.
>  From my two postings on "words" you can tell the difference
> in understanding.
>

Perl 5 barely has types, so there's nothing to document.

Perl 6 has a whole bunch of types. You will need to learn to look up any
type that you do not already know.

English is not a programming language, so it will not help you with
understanding what Positional is. Or Callable. Or Mix, or any of the other
types and roles in Perl 6. Perl 5 has none of these, so it is never a
problem in Perl 5. Instead you have to memorize a bunch of weird special
case rules for the things Perl 5 does know about -- and perldoc expects you
to have done so. You don't notice because you've already memorized them.

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


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 2:30 PM, Laurent Rosenfeld via perl6-users wrote:
You can set a limit to the number of items (words) you want to retrieve: 
you will get only the first $limit words.


If you don't supply any limit, Inf can be thought as the default value 
for the number of items, i.e. there is no limit and the routine will 
return as many words as it can from the source input.




Hi Laurent,

yes, I now understand.  Curt explained it beautifully and Timo
wrote and excellent explanation too.  Yours was very easy to undestand 
too.  That takes some doing when the audience is me.


:-)


Thank you for all the help with this!

-T


Re: Could this be any more obscure?

2018-09-26 Thread Brandon Allbery
It doesn't. It just improves error messages.

words() produces a list-like thing; that's what really matters, because
list-like things do the Positional role. Declaring it up front lets Perl 6
give you an error message early if you use the result in the wrong way or
if the actual implementation of words() doesn't produce something that does
the Positional role.

pyanfar Z$ 6 'say (sub { [5] })()[0]'
5

I didn't declare the anonymous sub as producing a Positional; it just
returns a List. I then invoke it with (), and apply [] to the resulting
List. It's the fact that it produced a List that matters; any List or Seq
or Array or Buf, etc. can be []-ed,because they all do the Positional role
that defines [].


On Wed, Sep 26, 2018 at 9:51 PM ToddAndMargo  wrote:

> On 9/26/18 6:31 PM, ToddAndMargo wrote:
> > On 9/26/18 6:18 PM, Curt Tilmes wrote:>
> >  >  > The methods don't take [].  You are calling [] on the thing
> > that the
> >  >  > methods return.
> >
> >>>
> >>> Yes, I know.  And it is human readable too.  It is one of the
> >>> many reasons I adore Perl 6.
> >>>
> >>> Where in
> >>>  multi method words(Str:D $input: $limit = Inf --> Positional)
> >>> does it state that "words" will do that?  Not all methods will.
> >>> So it need to be stated when they will.
> >>>
> >>>
> >
> >
> >
> >  > The part where it says "--> Positional" says the thing that gets
> >  > returned is Positional.
> >  >
> >  > A Positional thing has all sorts of methods and operators you can use,
> >  > including []
> >  >
> >  > Not all methods will, of course.  Only those that say "--> Positional"
> >  > return a Positional that acts like that.
> >  >
> >  > Curt
> >
> > Hi Curt,
> >
> > Perfect! Thank you!
> >
> > So all methods that respond with --> Positional will accept []
> >
> > Awesome!
> >
> > -T
>
>
>
> I do believe the reason I spaced on this was that when I see "-->"
> what goes through my head is "this is the value(s) returned".
> I had not idea it would reflect backwards and affect the method.
>
> There should be a better way of stating this.
>


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


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 3:25 PM, Brandon Allbery wrote:
I question "actually do RTFM", because you apparently think words() has 
to not only explain in complete detail what "Positional" means, but also 
must be rewritten to perform the Positional role itself via a $selection 
parameter instead of letting the Positional role do the job for which it 
exists.


Brandon,

Reading and understanding are two different things.

I presume you have P5's perldocs installed.  Pick
out any functions (perldoc -f name) and take
a look at how extraordinarily simple their explanations
are to understand.  You almost never have to ask for help.
From my two postings on "words" you can tell the difference
in understanding.

When documenting things, you always start simple and then
work your way up to the complex.

multi method words(Str:D $input: $limit = Inf --> Positional)

is not simple.

When I program, typically I have open my code editor, a
terminal for testing the code, another terminal for
testing one liners, and a web browser up with the documents
in several tabs.

Perl's routine documents are really, really difficult
for a beginner to understand (as opposed to what I am
use to in perldocs).  Think of it this way.  If I knew
enough to understand the above cryptology, why would I
need to go back and read it?  I would already know it.

Thank you all for all the help with this.  I know I
am a bit slow.

If I have a free moment soon, I will write up a perldocs
type explanation for words and submit it as an RFE to
add to the documentation.  I will submit it here first
to reduce the dripping egg on my face if I get anything wrong.

-T


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 6:47 PM, Curt Tilmes wrote:
In the signature like that it is just a default.  If you pass in a 
$limit parameter, that gets used like

"a b c d e".words(3) sets $limit to 3, limiting words() to 3 words.


Oh I get it now.  I was thinking it had to do with the list.

And do I presume correctly that the "inf" is short hand for saying
as many words as you want.

And where is it stated that an empty () defaults to all of them
and not to none of them?

There has got to be a better way of writing this stuff up.


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 6:31 PM, ToddAndMargo wrote:

On 9/26/18 6:18 PM, Curt Tilmes wrote:>
 >  > The methods don't take [].  You are calling [] on the thing 
that the

 >  > methods return.



    Yes, I know.  And it is human readable too.  It is one of the
    many reasons I adore Perl 6.

    Where in
 multi method words(Str:D $input: $limit = Inf --> Positional)
    does it state that "words" will do that?  Not all methods will.
    So it need to be stated when they will.






 > The part where it says "--> Positional" says the thing that gets
 > returned is Positional.
 >
 > A Positional thing has all sorts of methods and operators you can use,
 > including []
 >
 > Not all methods will, of course.  Only those that say "--> Positional"
 > return a Positional that acts like that.
 >
 > Curt

Hi Curt,

Perfect! Thank you!

So all methods that respond with --> Positional will accept []

Awesome!

-T




I do believe the reason I spaced on this was that when I see "-->"
what goes through my head is "this is the value(s) returned".
I had not idea it would reflect backwards and affect the method.

There should be a better way of stating this.


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 5:57 PM, Brandon Allbery wrote:
On Wed, Sep 26, 2018 at 8:49 PM ToddAndMargo > wrote:



$ p6 '"a b c d e".words[ 2, 4 ].say;'
(c e)

or

$ p6 '"a b c d e".words()[ 2, 4 ].say;'
(c e)

I am selecting the 2nd and 4th word starting from zero.  Inside
the brackets I am asking it to select th e 2nd and 4th words for me.

I am NOT asking it to limit my request to Infinity.


Correct. You put them inside the [ ]. They belong to the [ ] role of 
Positional.
The words function knows nothing whatsoever about this. It belongs to 
Positional.


If you put it inside the parentheses instead of the brackets, it belongs 
to the Callable, and will be given to words(). Now it is applied as the 
$limit on how many times to split the string.


Where does it state that

$ p6 '"a b c d e".words(3).say;'
(a b c)

means the first three words, starting at zero?


At least three of us have told you that this is $limit, because it is in 
the parentheses instead of in the brackets.
But you want words() to have a $selection there instead, so words() can 
be a list for you instead of letting the list be a list.
Why is it so important that words() pretend to be a list, when we have 
lists that know how to be lists?
Why is it so important that you not have to find out what a list is, but 
instead that words() must pretend that it is a list?


Nobody understands why you insist that lists are wired into the 
functions that produce them and can't possibly know that they can be 
indexed. And that we must document every function that produces a listas 
actally itself being a list, including magical $selection parameters, 
when that is what lists are for. What do you think lists are for, if 
words() and lines() have to be fake lists to work instead of producing 
real lists?


Hi Brandon,

Curt explained it to me.

To go along with what you stated

$ p6 '"a b c d e".words(3)[ 2, 4 ].say;'
(c Nil)

"words" is returning the first three words delimited
by whitespace.  [2,4] is request the individual words
in positions 2 and 4 starting at 0.  The "Nil" is because
there are only three words after requesting the (3).

Thank you for all the help with this!

-T


Re: Could this be any more obscure?

2018-09-26 Thread Curt Tilmes
On Wed, Sep 26, 2018 at 9:40 PM ToddAndMargo  wrote:

>  Would you take a swipe at "$limit = Inf"
>

In the signature like that it is just a default.  If you pass in a $limit
parameter, that gets used like
"a b c d e".words(3) sets $limit to 3, limiting words() to 3 words.

If you don't pass anything in, it gets the default value, in this case Inf,
which is greater than the greatest integer.

If you called "a b c d e".words(Inf) it would be the same thing as not
passing any anything.

If the signature said "$limit = 3", then the default would be 3, and calling
"a b c d e".words() or "a b c d e".words would be the same as saying "a b c
d e".words(3)

Inf is kind of special because no matter how many words get parsed out, it
will keep going.  The limit will
never read Inf because Inf is infinite!

It makes a great default, because we don't want to ever stop sending more
words if you didn't specify a limit.

Curt


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 6:19 PM, The Sidhekin wrote:
On Thu, Sep 27, 2018 at 2:49 AM ToddAndMargo > wrote:


On 9/26/18 4:33 PM, The Sidhekin wrote:
 > On Wed, Sep 26, 2018 at 11:40 PM ToddAndMargo
mailto:toddandma...@zoho.com>
 > >> wrote:

 >     And where is it stated what goes in the () and what goes
 >     in the []?
 >
 >
 >    The () is part of a method call syntax; method arguments go
there:
 > https://docs.perl6.org/language/syntax#Subroutine_calls

Where does it state that

$ p6 '"a b c d e".words(3).say;'
(a b c)

means the first three words, starting at zero?


https://docs.perl6.org/routine/words#class_Str says it returns "the same 
as a call to |$input.comb( / \S+ /, $limit )| would".


https://docs.perl6.org/routine/comb#class_Str says it "returns a list of 
non-overlapping matches limited to at most |$limit| matches".


   It doesn't say it returns the first such matches; maybe it should.

   It doesn't say "starting at zero", but then, why should it?  The 
first three wouldn't be the first three if it skipped any, right?


 >    The [] is a postcircumfix operator; index arguments go there:
 > https://docs.perl6.org/language/operators#postcircumfix_[_]

Where does

      multi method words(Str:D $input: $limit = Inf --> Positional)

state that I can do such?


   It doesn't. 
https://docs.perl6.org/language/operators#postcircumfix_[_] does.


I ask this because not all methods will take []


   Sure they will.  They might give you runtime errors, if the method 
doesn't (at runtime) return something that does Positional, but they 
will all take it.


Also, where is it stated that

     $ p6 '"a b c d e".words(3)[ 2, 4 ].say;'
     (c Nil)

will send the first three words to [2,4] ?


   It doesn't.  It shouldn't: There's no "sending".

https://docs.perl6.org/language/operators#postcircumfix_[_] tells you it 
calls postcircumfix:<[ ]> with a first argument of what the returned 
(the first three words) and the remaining positional arguments 2, 4.



Eirik


Hi Eirek,

Curt Explained it to me.  Thank you for all the help!

The only thing I am hanging on is "$limit = Inf"

-T

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


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 6:03 PM, Timo Paulssen wrote:

You're still missing that the words method doesn't "take the [2,4]". The
operation that [2,4] does takes place after the words() thing has
already done its work.

You could actually say that every method takes [0]. Try it!

Your confusion looks a bit similar to seeing

     multi sub exp(Cool:D $pow, Cool:D $base?)

and the example code

     say exp(2, 10) + 5

and then asking "where in the multi sub exp in the docs does it say that
i can add 5?"

They are separate things that work together.

The return value of words being Positional means mainly that it gives
you something you can use [ ] on.

The part of words where it says $limit = Inf means that if no number is
passed there, that the value Inf is used. Inf is not a Type, and even
though you can put a type on the right side of an assignment, it will
"just" be used as a value.

I'm not sure why you wrote "I am NOT asking it to limit my request to
Infinity.", maybe if you explain that a little more we can figure out
better what's confusing you.



Where does

     multi method words(Str:D $input: $limit = Inf --> Positional)

state that I can do such?

I ask this because not all methods will take []


$ p6 '"a b c d e".contains( "a","b" ).say;'
Cannot convert string to number: base-10 number must begin with valid
digits or '.' in '⏏b' (indicated by ⏏)
   in block  at -e line 1

$ p6 '"a b c d e".contains( 1, 3 ).say;'
Ambiguous call to 'contains(Str: Int, Int)'; these signatures all match:
:(Str:D: Cool:D $needle, Cool:D $pos, *%_)
:(Str:D: Cool:D $needle, Cool:D $pos, *%_)
   in block  at -e line 1



You aren't using [] there, you're just putting the strings and numbers
inside the (), which is the difference that people are trying to
explain, but not finding the right words to make you understand. Can you
help us by explaining how you get from "every method takes [ ]" to "i'll
try it with ()"? Perhaps some place wrongly claimed that () and [] are
the same? That might require a bit of re-wording in the docs, then.

Hope any of that helps
   - Timo



Hi Timo,

Curt explained it to me.

Your explanation was marvelous written.  That takes
talent!  I feel a little bit guilty not stopping
you sooner.

Okay, guilt over.  Would you take a swipe at "$limit = Inf"

Many thanks,
-T


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 6:08 PM, Brandon Allbery wrote:

In the part that says "Positional". You have already been told this.


Hi Brandon,

Sorry for the frustration.  It did not sink in until Curt explained
it to me.

I did look up Positional before posting this.  It did not
sink in either.

https://docs.perl6.org/type/Positional
   Role for objects which support indexing them using
   postcircumfix:«[ ]» (usually list-like objects). Example
   types with Positional role include List, Array, Range,
   and Buf.

   Returns the type constraint for elements of the positional
   container. Defaults to Mu.


Thank you for all the help with this.


-T


Re: Could this be any more obscure?

2018-09-26 Thread The Sidhekin
On Thu, Sep 27, 2018 at 3:14 AM Peter Scott  wrote:

> On 9/26/2018 3:21 PM, ToddAndMargo wrote:
> > Do your really think any beginner would be able to figure out
> > "words" from the above?
>
> If the beginner had studied the metasyntax of function prototypes,
> probably.


  Yeah, that's where a beginner needs to begin, in order to learn Perl6
from the docs.

  Syntax, metasyntax, all sorts of basics ...


> I heard about people
> who claim to have taught themselves Perl 5 from the Camel instead of the
> Llama, but they are few and far between, and in any case, most of the
> Camel contains exposition, if dense.


  I learned Perl 5 from the man pages.  It was more fun than efficient, but
I could easily afford it: It was not (at the time) my job. :)

  But we're not all wired the same way.  This endeavour looks to me neither
fun nor efficient.


Eirik


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 6:06 PM, The Sidhekin wrote:
On Thu, Sep 27, 2018 at 3:03 AM ToddAndMargo > wrote:


On 9/26/18 5:55 PM, Curt Tilmes wrote:
 > You are calling [] on the thing that the methods return.

Yes, I know.  And it is human readable too.  It is one of the
many reasons I adore Perl 6.

Where in
     multi method words(Str:D $input: $limit = Inf --> Positional)
does it state that "words" will do that?


   "words" doesn't do that.  Read it again: "You are calling []".  
"You".  Not "words".




Hi Eirik

Curt explained it.  All methods that respond with --> Positional
will accept []

Light bulb moment.

Thank you for the help!

-T


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 6:18 PM, Curt Tilmes wrote:>
>  > The methods don't take [].  You are calling [] on the thing 
that the

>  > methods return.



Yes, I know.  And it is human readable too.  It is one of the
many reasons I adore Perl 6.

Where in
 multi method words(Str:D $input: $limit = Inf --> Positional)
does it state that "words" will do that?  Not all methods will.
So it need to be stated when they will.






> The part where it says "--> Positional" says the thing that gets
> returned is Positional.
>
> A Positional thing has all sorts of methods and operators you can use,
> including []
>
> Not all methods will, of course.  Only those that say "--> Positional"
> return a Positional that acts like that.
>
> Curt

Hi Curt,

Perfect! Thank you!

So all methods that respond with --> Positional will accept []

Awesome!

-T


Re: Could this be any more obscure?

2018-09-26 Thread The Sidhekin
On Thu, Sep 27, 2018 at 2:49 AM ToddAndMargo  wrote:

> On 9/26/18 4:33 PM, The Sidhekin wrote:
> > On Wed, Sep 26, 2018 at 11:40 PM ToddAndMargo  > > wrote:
>


> > And where is it stated what goes in the () and what goes
> > in the []?
> >
> >
> >The () is part of a method call syntax; method arguments go there:
> > https://docs.perl6.org/language/syntax#Subroutine_calls
>
> Where does it state that
>
> $ p6 '"a b c d e".words(3).say;'
> (a b c)
>
> means the first three words, starting at zero?
>

  https://docs.perl6.org/routine/words#class_Str says it returns "the same
as a call to $input.comb( / \S+ /, $limit ) would".

  https://docs.perl6.org/routine/comb#class_Str says it "returns a list of
non-overlapping matches limited to at most $limit matches".

  It doesn't say it returns the first such matches; maybe it should.

  It doesn't say "starting at zero", but then, why should it?  The first
three wouldn't be the first three if it skipped any, right?


>
> >The [] is a postcircumfix operator; index arguments go there:
> > https://docs.perl6.org/language/operators#postcircumfix_[_]
>
> Where does
>
>  multi method words(Str:D $input: $limit = Inf --> Positional)
>
> state that I can do such?
>

  It doesn't.  https://docs.perl6.org/language/operators#postcircumfix_[_]
does.


> I ask this because not all methods will take []
>

  Sure they will.  They might give you runtime errors, if the method
doesn't (at runtime) return something that does Positional, but they will
all take it.


> Also, where is it stated that
>
> $ p6 '"a b c d e".words(3)[ 2, 4 ].say;'
> (c Nil)
>
> will send the first three words to [2,4] ?
>

  It doesn't.  It shouldn't: There's no "sending".

  https://docs.perl6.org/language/operators#postcircumfix_[_] tells you it
calls postcircumfix:<[ ]> with a first argument of what the returned (the
first three words) and the remaining positional arguments 2, 4.


Eirik


Re: Could this be any more obscure?

2018-09-26 Thread Brandon Allbery
Additionally: Perl 5 docs don't run into this because perl 5 has only 3
types: scalar, list, hash.

Perl 6 has lots of types, each of which has its own behavior. We use roles
to package up common behaviors. Positional is the role for "can be indexed"
/ "understands []". Don't just assume you know what Positional is because
you know its English meaning; look at what it actually does, and you will
find the [] documentation.

On Wed, Sep 26, 2018 at 9:13 PM Peter Scott  wrote:

> On 9/26/2018 3:21 PM, ToddAndMargo wrote:
> >
> > I use words all the time.  I never would have figured it out
> > from
> >
> > multi method words(Str:D $input: $limit = Inf --> Positional)
> >
> > Do your really think any beginner would be able to figure out
> > "words" from the above?
>
> If the beginner had studied the metasyntax of function prototypes,
> probably.  But this is not necessarily for beginners, this is reference
> documentation, which has to serve a purpose unencumbered by pedagogical
> weight.  This documentation is not a tutorial, it is autogenerated.  You
> are relatively unique in insisting that the reference documentation also
> function as a beginners' roadmap, so you are going to experience this
> kind of frustration repeatedly.
>
> I taught Perl 5 trainings for many years in addition to authoring books,
> videos, and courses on same, and the difference between what is best for
> learning and what is best for reference is stark.  I heard about people
> who claim to have taught themselves Perl 5 from the Camel instead of the
> Llama, but they are few and far between, and in any case, most of the
> Camel contains exposition, if dense. You're looking just at something
> corresponding to the list of functions.  I honestly think you'll get
> further forcing yourself to plow through the new Learning Perl 6 book
> than these random access forays into reference specs.  brian just spent
> two years of intense effort arranging it to fit precisely the graduated
> path your questions tell me you need.
>


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


Re: Could this be any more obscure?

2018-09-26 Thread Peter Scott

On 9/26/2018 3:21 PM, ToddAndMargo wrote:


I use words all the time.  I never would have figured it out
from

    multi method words(Str:D $input: $limit = Inf --> Positional)

Do your really think any beginner would be able to figure out
"words" from the above?


If the beginner had studied the metasyntax of function prototypes, 
probably.  But this is not necessarily for beginners, this is reference 
documentation, which has to serve a purpose unencumbered by pedagogical 
weight.  This documentation is not a tutorial, it is autogenerated.  You 
are relatively unique in insisting that the reference documentation also 
function as a beginners' roadmap, so you are going to experience this 
kind of frustration repeatedly.


I taught Perl 5 trainings for many years in addition to authoring books, 
videos, and courses on same, and the difference between what is best for 
learning and what is best for reference is stark.  I heard about people 
who claim to have taught themselves Perl 5 from the Camel instead of the 
Llama, but they are few and far between, and in any case, most of the 
Camel contains exposition, if dense. You're looking just at something 
corresponding to the list of functions.  I honestly think you'll get 
further forcing yourself to plow through the new Learning Perl 6 book 
than these random access forays into reference specs.  brian just spent 
two years of intense effort arranging it to fit precisely the graduated 
path your questions tell me you need.


Re: Could this be any more obscure?

2018-09-26 Thread Brandon Allbery
On Wed, Sep 26, 2018 at 9:03 PM ToddAndMargo  wrote:

> Where in
> multi method words(Str:D $input: $limit = Inf --> Positional)
> does it state that "words" will do that?  Not all methods will.
> So it need to be stated when they will.\
>

In the part that says "Positional". You have already been told this.

Someone please create one page with all of perl 6 documentation in it, so
the documentation for words() includes the documentation for Positional
includes the documentation for methods includes the documntation explaining
how perl 6 works etc. Obviously this is the only way to "properly" document
anything, you must include all of the documentation for perl 6 on every
page because CALL FOUL if you expect someone to go see what a Positional
is, or the notion that a Positional might be capable of accepting a []
method call, or someone might pass this method a Str so we'd better explain
what a Str is, etc.

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


Re: Could this be any more obscure?

2018-09-26 Thread The Sidhekin
On Thu, Sep 27, 2018 at 3:03 AM ToddAndMargo  wrote:

> On 9/26/18 5:55 PM, Curt Tilmes wrote:
> > You are calling [] on the thing that the methods return.
>
> Yes, I know.  And it is human readable too.  It is one of the
> many reasons I adore Perl 6.
>
> Where in
> multi method words(Str:D $input: $limit = Inf --> Positional)
> does it state that "words" will do that?


  "words" doesn't do that.  Read it again: "You are calling []".  "You".
Not "words".


Eirik


Re: Could this be any more obscure?

2018-09-26 Thread Timo Paulssen
You're still missing that the words method doesn't "take the [2,4]". The
operation that [2,4] does takes place after the words() thing has
already done its work.

You could actually say that every method takes [0]. Try it!

Your confusion looks a bit similar to seeing

    multi sub exp(Cool:D $pow, Cool:D $base?)

and the example code

    say exp(2, 10) + 5

and then asking "where in the multi sub exp in the docs does it say that
i can add 5?"

They are separate things that work together.

The return value of words being Positional means mainly that it gives
you something you can use [ ] on.

The part of words where it says $limit = Inf means that if no number is
passed there, that the value Inf is used. Inf is not a Type, and even
though you can put a type on the right side of an assignment, it will
"just" be used as a value.

I'm not sure why you wrote "I am NOT asking it to limit my request to
Infinity.", maybe if you explain that a little more we can figure out
better what's confusing you.


> Where does
>
>     multi method words(Str:D $input: $limit = Inf --> Positional)
>
> state that I can do such?
>
> I ask this because not all methods will take []
>
>
> $ p6 '"a b c d e".contains( "a","b" ).say;'
> Cannot convert string to number: base-10 number must begin with valid
> digits or '.' in '⏏b' (indicated by ⏏)
>   in block  at -e line 1
>
> $ p6 '"a b c d e".contains( 1, 3 ).say;'
> Ambiguous call to 'contains(Str: Int, Int)'; these signatures all match:
> :(Str:D: Cool:D $needle, Cool:D $pos, *%_)
> :(Str:D: Cool:D $needle, Cool:D $pos, *%_)
>   in block  at -e line 1


You aren't using [] there, you're just putting the strings and numbers
inside the (), which is the difference that people are trying to
explain, but not finding the right words to make you understand. Can you
help us by explaining how you get from "every method takes [ ]" to "i'll
try it with ()"? Perhaps some place wrongly claimed that () and [] are
the same? That might require a bit of re-wording in the docs, then.

Hope any of that helps
  - Timo


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 5:55 PM, Curt Tilmes wrote:
For each instance you are using [], it is the same as assigning to a 
variable, then calling [] on it.


$ p6 '"a b c d e".words(3).say;'
(a b c)

same as

my @x = "a b c d e".words(3);
@x.say

$ p6 '"a b c d e".words(3)[ 2, 4 ].say;'
(c Nil)

same as

my @x = '"a b c d e".words(3);  # same as @x = 'a', 'b', 'c';
@x[2,4].say;
(c, Nil)

The methods don't take [].  You are calling [] on the thing that the 
methods return.


Yes, I know.  And it is human readable too.  It is one of the
many reasons I adore Perl 6.

Where in
   multi method words(Str:D $input: $limit = Inf --> Positional)
does it state that "words" will do that?  Not all methods will.
So it need to be stated when they will.

If
   multi method words(Str:D $input: $limit = Inf --> Positional)
is written incorrectly or incompletely, and it is not just me
being dense, how would you rewrite the line?


Re: Could this be any more obscure?

2018-09-26 Thread Brandon Allbery
On Wed, Sep 26, 2018 at 8:49 PM ToddAndMargo  wrote:

>
> $ p6 '"a b c d e".words[ 2, 4 ].say;'
> (c e)
>
> or
>
> $ p6 '"a b c d e".words()[ 2, 4 ].say;'
> (c e)
>
> I am selecting the 2nd and 4th word starting from zero.  Inside
> the brackets I am asking it to select th e 2nd and 4th words for me.
>
> I am NOT asking it to limit my request to Infinity.
>
>
Correct. You put them inside the [ ]. They belong to the [ ] role of
Positional.
The words function knows nothing whatsoever about this. It belongs to
Positional.

If you put it inside the parentheses instead of the brackets, it belongs to
the Callable, and will be given to words(). Now it is applied as the $limit
on how many times to split the string.

Where does it state that
>
> $ p6 '"a b c d e".words(3).say;'
> (a b c)
>
> means the first three words, starting at zero?
>

At least three of us have told you that this is $limit, because it is in
the parentheses instead of in the brackets.
But you want words() to have a $selection there instead, so words() can be
a list for you instead of letting the list be a list.
Why is it so important that words() pretend to be a list, when we have
lists that know how to be lists?
Why is it so important that you not have to find out what a list is, but
instead that words() must pretend that it is a list?

Nobody understands why you insist that lists are wired into the functions
that produce them and can't possibly know that they can be indexed. And
that we must document every function that produces a listas actally itself
being a list, including magical $selection parameters, when that is what
lists are for. What do you think lists are for, if words() and lines() have
to be fake lists to work instead of producing real lists?

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


Re: Could this be any more obscure?

2018-09-26 Thread Curt Tilmes
For each instance you are using [], it is the same as assigning to a
variable, then calling [] on it.

$ p6 '"a b c d e".words(3).say;'
(a b c)

same as

my @x = "a b c d e".words(3);
@x.say

$ p6 '"a b c d e".words(3)[ 2, 4 ].say;'
(c Nil)

same as

my @x = '"a b c d e".words(3);  # same as @x = 'a', 'b', 'c';
@x[2,4].say;
(c, Nil)

The methods don't take [].  You are calling [] on the thing that the
methods return.


On Wed, Sep 26, 2018 at 8:49 PM ToddAndMargo  wrote:

> On 9/26/18 4:33 PM, The Sidhekin wrote:
> > On Wed, Sep 26, 2018 at 11:40 PM ToddAndMargo  > > wrote:
> >
> > What I don't understand is:
> >
> >multi method words(Str:D $input: $limit = Inf --> Positional)
> >
> > Specifically "$limit = Inf".  Why are we using "$limit" instead
> > of "$selection"
> >
> >Perhaps this would be easier if you explain where you're getting
> > "$selection", and what you think it is.
>
> $ p6 '"a b c d e".words[ 2, 4 ].say;'
> (c e)
>
> or
>
> $ p6 '"a b c d e".words()[ 2, 4 ].say;'
> (c e)
>
> I am selecting the 2nd and 4th word starting from zero.  Inside
> the brackets I am asking it to select th e 2nd and 4th words for me.
>
> I am NOT asking it to limit my request to Infinity.
>
>
>
> >
> > And where is it stated what goes in the () and what goes
> > in the []?
> >
> >
> >The () is part of a method call syntax; method arguments go there:
> > https://docs.perl6.org/language/syntax#Subroutine_calls
>
> Where does it state that
>
> $ p6 '"a b c d e".words(3).say;'
> (a b c)
>
> means the first three words, starting at zero?
>
>
> >The [] is a postcircumfix operator; index arguments go there:
> > https://docs.perl6.org/language/operators#postcircumfix_[_]
>
> Where does
>
>  multi method words(Str:D $input: $limit = Inf --> Positional)
>
> state that I can do such?
>
> I ask this because not all methods will take []
>
>
> $ p6 '"a b c d e".contains( "a","b" ).say;'
> Cannot convert string to number: base-10 number must begin with valid
> digits or '.' in '⏏b' (indicated by ⏏)
>in block  at -e line 1
>
> $ p6 '"a b c d e".contains( 1, 3 ).say;'
> Ambiguous call to 'contains(Str: Int, Int)'; these signatures all match:
> :(Str:D: Cool:D $needle, Cool:D $pos, *%_)
> :(Str:D: Cool:D $needle, Cool:D $pos, *%_)
>in block  at -e line 1
>
>
> Also, where is it stated that
>
> $ p6 '"a b c d e".words(3)[ 2, 4 ].say;'
> (c Nil)
>
> will send the first three words to [2,4] ?
>
> Thank you for helping me with this!
>
> -T
>


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 4:33 PM, The Sidhekin wrote:
On Wed, Sep 26, 2018 at 11:40 PM ToddAndMargo > wrote:


What I don't understand is:

       multi method words(Str:D $input: $limit = Inf --> Positional)

Specifically "$limit = Inf".  Why are we using "$limit" instead
of "$selection"

   Perhaps this would be easier if you explain where you're getting 
"$selection", and what you think it is.


$ p6 '"a b c d e".words[ 2, 4 ].say;'
(c e)

or

$ p6 '"a b c d e".words()[ 2, 4 ].say;'
(c e)

I am selecting the 2nd and 4th word starting from zero.  Inside
the brackets I am asking it to select th e 2nd and 4th words for me.

I am NOT asking it to limit my request to Infinity.





And where is it stated what goes in the () and what goes
in the []?


   The () is part of a method call syntax; method arguments go there: 
https://docs.perl6.org/language/syntax#Subroutine_calls


Where does it state that

$ p6 '"a b c d e".words(3).say;'
(a b c)

means the first three words, starting at zero?


   The [] is a postcircumfix operator; index arguments go there: 
https://docs.perl6.org/language/operators#postcircumfix_[_]


Where does

multi method words(Str:D $input: $limit = Inf --> Positional)

state that I can do such?

I ask this because not all methods will take []


$ p6 '"a b c d e".contains( "a","b" ).say;'
Cannot convert string to number: base-10 number must begin with valid 
digits or '.' in '⏏b' (indicated by ⏏)

  in block  at -e line 1

$ p6 '"a b c d e".contains( 1, 3 ).say;'
Ambiguous call to 'contains(Str: Int, Int)'; these signatures all match:
:(Str:D: Cool:D $needle, Cool:D $pos, *%_)
:(Str:D: Cool:D $needle, Cool:D $pos, *%_)
  in block  at -e line 1


Also, where is it stated that

   $ p6 '"a b c d e".words(3)[ 2, 4 ].say;'
   (c Nil)

will send the first three words to [2,4] ?

Thank you for helping me with this!

-T


Re: Could this be any more obscure?

2018-09-26 Thread The Sidhekin
On Wed, Sep 26, 2018 at 11:40 PM ToddAndMargo  wrote:

> What I don't understand is:
>
>   multi method words(Str:D $input: $limit = Inf --> Positional)
>
> Specifically "$limit = Inf".  Why are we using "$limit" instead
> of "$selection"
>

  Perhaps this would be easier if you explain where you're getting
"$selection", and what you think it is.

And where is it stated what goes in the () and what goes
> in the []?
>

  The () is part of a method call syntax; method arguments go there:
https://docs.perl6.org/language/syntax#Subroutine_calls

  The [] is a postcircumfix operator; index arguments go there:
https://docs.perl6.org/language/operators#postcircumfix_[_]


Eirik


Re: Could this be any more obscure?

2018-09-26 Thread Curt Tilmes
On Wed, Sep 26, 2018 at 6:13 PM Brandon Allbery  wrote:

> On Wed, Sep 26, 2018 at 6:09 PM ToddAndMargo 
> wrote:
>
>> multi method words(Str:D $input: $limit = Inf --> Positional)
>>
>
"a b c d".words(3);
(a b c)
passing the $limit parameter in with 3, limits the number of words returned
to 3.

"a b c d".words(2);
(a b)
Passing a $limit of 2, limits the words returned to 2.

If you *don't* set $limit at all, it gets set to its default, Inf, or all
the words.  It just never stops because there is no limit.
"a b c d".words();
(a b c d)

The () are optional since you aren't passing in any parameters, so you can
also just say
"a b c d".words;
(a b c d)

You can store that in a variable
my @x = "a b c d".words;

Once you've got that in a variable, as described in detail on the page
about Positional, you can access parts of it with the [] operator, for
example, the word in the '2' position (the third word counting from 0) is
@x[2]
c

What looks a little weird is that you don't need @x at all.  You can just
call the [] operator directly on the return value from words

"a b c d".words()[2]
c

and of course, you can omit the () since you aren't passing in parameters,
so this is the same thing

"a b c d".words[2]
c

Curt


Re: Could this be any more obscure?

2018-09-26 Thread Brandon Allbery
I question "actually do RTFM", because you apparently think words() has to
not only explain in complete detail what "Positional" means, but also must
be rewritten to perform the Positional role itself via a $selection
parameter instead of letting the Positional role do the job for which it
exists.

On Wed, Sep 26, 2018 at 6:22 PM ToddAndMargo  wrote:

> On 9/26/18 3:12 PM, Brandon Allbery wrote:
> > I told you that. Others told you that. You ignored it and asked the same
> > question again, because what we said that exlains what words() is doing
> > doesn't fit how you've decided words() must work.
> >
> > No amount of documentation can fix "I think the accelerator is the brake
> > pedal, and if it's not then you broke it".
>
> I don't mean to frustrate you.
>
> I am trying to come up with an understandable method of
> writing out the multi method that I can add constructive
> comments to the documentation as an RFE, rather than just
> grumbling at its obscurity.
>
> I use words all the time.  I never would have figured it out
> from
>
>  multi method words(Str:D $input: $limit = Inf --> Positional)
>
> Do your really think any beginner would be able to figure out
> "words" from the above?
>
> -T
>
> Some of us actually do RTFM.
>


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


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 3:12 PM, Brandon Allbery wrote:
I told you that. Others told you that. You ignored it and asked the same 
question again, because what we said that exlains what words() is doing 
doesn't fit how you've decided words() must work.


No amount of documentation can fix "I think the accelerator is the brake 
pedal, and if it's not then you broke it".


I don't mean to frustrate you.

I am trying to come up with an understandable method of
writing out the multi method that I can add constructive
comments to the documentation as an RFE, rather than just
grumbling at its obscurity.

I use words all the time.  I never would have figured it out
from

multi method words(Str:D $input: $limit = Inf --> Positional)

Do your really think any beginner would be able to figure out
"words" from the above?

-T

Some of us actually do RTFM.


Re: Could this be any more obscure?

2018-09-26 Thread Brandon Allbery
I told you that. Others told you that. You ignored it and asked the same
question again, because what we said that exlains what words() is doing
doesn't fit how you've decided words() must work.

No amount of documentation can fix "I think the accelerator is the brake
pedal, and if it's not then you broke it".

On Wed, Sep 26, 2018 at 6:09 PM ToddAndMargo  wrote:

> On 9/26/18 2:45 PM, Brandon Allbery wrote:
> > And I'm trying to figure out how to explain $limit since the one
> > everyone else has used apparently means nothing whatsoever. Unless
> > you've just been ignoring those as irrelevant, because it's not whatever
> > you mean by "$selection" that nobody else can figure out.
>
> I know how to use the function and use it all the time.
>
> multi method words(Str:D $input: $limit = Inf --> Positional)
>
> Why are they using the word "limit" and the type "Inf"?
>
> And how is this suppose to explain how to actually use the method?
>
> The only thing I have come up with so far is that they are
> trying to tell you that there is an infinite number of
> selections.  Again, not telling you how to use the method.
>


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


Re: words[] question

2018-09-26 Thread Brandon Allbery
We really are not communicating at all, are we?

It says "--> Positional". Positional is a role specifying what to do with
[]. Positional is what knows what to do with [], so words() and lines() and
everything else that produces a Positional doesn't have to know that.
This is more or less the *definition* of Positional. It's not up to the
documentation of words() to also tell you the documentation of Positional;
it told you to look there.

And there is more to Positional than just knowing what to do with [], and
that also is not something words() or its documentation should tell you. Or
does every documentation page have to incorporate the whole Perl 6
documentation? ("You might decide to pass this a Str, so I guess I have to
explain in detail what a Str is now just in case"?)

On Wed, Sep 26, 2018 at 6:05 PM ToddAndMargo  wrote:

> On 9/26/18 2:40 PM, Brandon Allbery wrote:
> > Do you really think every function that produces a "list" has built into
> > it secret knowledge of how you would index a list? They just produce a
> > "Positional" or "Seq" or "List", etc. and *those* know what to do with
> > []. The function doesn't even need to say it's doing that; that's to
> > produce better error messages, not "wire what a list is into me".
>
> Hi Brandon,
>
> I know how to use the function and use it all the time.  My
> frustration is with the documentation.
>
> How did this
>
>   multi method words(Str:D $input: $limit = Inf --> Positional)
>
> get to what you describe above?
>
> Yours in confusion,
> -T
>


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


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 2:45 PM, Brandon Allbery wrote:
And I'm trying to figure out how to explain $limit since the one 
everyone else has used apparently means nothing whatsoever. Unless 
you've just been ignoring those as irrelevant, because it's not whatever 
you mean by "$selection" that nobody else can figure out.


I know how to use the function and use it all the time.

multi method words(Str:D $input: $limit = Inf --> Positional)

Why are they using the word "limit" and the type "Inf"?

And how is this suppose to explain how to actually use the method?

The only thing I have come up with so far is that they are
trying to tell you that there is an infinite number of
selections.  Again, not telling you how to use the method.


Re: words[] question

2018-09-26 Thread ToddAndMargo

On 9/26/18 2:40 PM, Brandon Allbery wrote:
Do you really think every function that produces a "list" has built into 
it secret knowledge of how you would index a list? They just produce a 
"Positional" or "Seq" or "List", etc. and *those* know what to do with 
[]. The function doesn't even need to say it's doing that; that's to 
produce better error messages, not "wire what a list is into me".


Hi Brandon,

I know how to use the function and use it all the time.  My
frustration is with the documentation.

How did this

 multi method words(Str:D $input: $limit = Inf --> Positional)

get to what you describe above?

Yours in confusion,
-T


Just posted a documentation RFE

2018-09-26 Thread ToddAndMargo

Hi All,

I just posted a documentation fix and RFE

A booboo and an rfe in contains documentation
https://github.com/perl6/doc/issues/2334

Thank you all for helping me understand to the point that I
can stop grumbling and start being part of the solution.

:-)

-T


Over on
https://docs.perl6.org/routine/contains#(Str)_method_contains
the return value is missing: --> Bool

Since it need to be updated anyway, for clarity, would you please 
consider the following enhancements:


Old: multi method contains(Str:D: Str:D $needle, Int:D $pos)
Proposed: multi method contains(Str:D $Haystack : Str:D $Needle, Int:D 
$Position --> Bool)


Giving the input string the name "Haystack" gives meaning to the 
parameter of "Needle". You are searching for the "needle in the 
haystack". Without this linkage, one is left wondering what the "needle" 
is "sticking".


The " :", rather than ":" makes it more clear that it is a delimiter to 
the untrained eye.


And spelling out "Position" just makes it clearer what it is. (Not "pos" 
for Positive or what ever else it can be mistaken for.)


Re: Could this be any more obscure?

2018-09-26 Thread Brandon Allbery
What do you believe your $selection should mean?

And I'm trying to figure out how to explain $limit since the one everyone
else has used apparently means nothing whatsoever. Unless you've just been
ignoring those as irrelevant, because it's not whatever you mean by
"$selection" that nobody else can figure out.

Or is this still "words, and every other function that produces a list, is
obviously also what indexes a list, therefore you pass into it the index
you want from it"? How do you understand map() or grep() to work, if
words() has to produce not a list but a specific item from that list? Call
it once for every word in the list?

On Wed, Sep 26, 2018 at 5:39 PM ToddAndMargo  wrote:

> On 9/26/18 10:47 AM, The Sidhekin wrote:
> > On Wed, Sep 26, 2018 at 8:58 AM Todd Chester  > > wrote:
> >
> > Hi All,
> >
> > Over on
> > https://docs.perl6.org/routine/words
> > I see
> >
> >  multi method words(Str:D $input: $limit = Inf --> Positional)
> >
> > HOW IN THE WORLD did they convert `$limit = Inf` into an
> > array index!?!?!
> >
> >
> >It's not.  It's a limit:
> >
> > eirik@greencat[19:41:18]~$ perl6 -e '.say for "foo bar baz
> qux".words(2)'
> > foo
> > bar
> > eirik@greencat[19:41:29]~$
> >
> >I see from your other email that you're using square brackets.
> > That's what makes a zero-based index:
> >
> > eirik@greencat[19:41:29]~$ perl6 -e '.say for "foo bar baz
> qux".words[2]'
> > baz
> > eirik@greencat[19:43:00]~$
> >
> >But this index is not an argument to the words method.  It is an
> > argument to the .[ ] postcircumfix.
> >
> >That these are different things is perhaps more easily seen when
> > they're both present:
> >
> > eirik@greencat[19:45:54]~$ perl6 -e '.say for "foo bar baz
> > qux".words(3)[*-1]'
> > baz
> > eirik@greencat[19:45:59]~$
> >
> >Here, it may be clearer that the $limit is 3, and the index is *-1.
> >
> >
> > Eirik
>
>
> Hi Eirik,
>
> Thank you for the explanation.
>
> I think I did  not make myself clear.  I do know how to
> use the function and I use it all the time.
>
> What I don't understand is:
>
>   multi method words(Str:D $input: $limit = Inf --> Positional)
>
> Specifically "$limit = Inf".  Why are we using "$limit" instead
> of "$selection" and why are we throwing "Inf" into the mix
> as it is a "type".  "Types" are written like "Str:D" and come
> before the variable, not after.  (I know the ":D" means "defined".)
>
> And where is it stated what goes in the () and what goes
> in the []?
>
> Yours in frustration,
> -T
>


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


Re: words[] question

2018-09-26 Thread ToddAndMargo

On 9/26/18 6:04 AM, Brian Duggan wrote:

On Tuesday, September 25, Todd Chester wrote:

Not to ask too obvious a question, but why does words use a []
instead of a () ?
...
I am confused as to when to use [] and when to use () with a method.


If a method is called without arguments, the () can be omitted.

"a man a plan a canal -- panama".words()
"a man a plan a canal -- panama".words# <-- same thing

[] acts on the return value -- it takes an element of a list

"a man a plan a canal -- panama".words()[3]
"a man a plan a canal -- panama".words[3]  # <-- same thing

Brian



Hi Brian,

That was beautifully written.  Thank you!

I think I did not make myself clear.  I know how
to use the function and use it all the time.

My frustration is with
 multi method words(Str:D $input: $limit = Inf --> Positional)

Specifically "$limit = Inf".  Why are we using "$limit" instead
of "$selection" and why are we throwing "Inf" into the mix
as it is a "type".  "Types" are written like "Str:D" and come
before the variable, not after.  (I know the ":D" means "defined".)

And where is it stated what goes in the () and what goes
in the []?

My specific goal is to understand what the documentation is trying
to say.  That way, instead of grumbling about how bad it is, I can
make some constructive comments to help improve it.

-T


Re: words[] question

2018-09-26 Thread Brandon Allbery
You're still assuming they're the "same thing"in some sense.

The type of the () postfix operator says it applies to a function or method
(more specifically, to something that supports the Callable role), thus to
"words" itself.
The type of the [] postfix operator says it applies to something that
supports the Positional role; as "words" produces a Positional, the []
applies to the *result* of words.

"words" itself doesn't see or know about either of them. It is invoked by
the () postfix, and its result is processed by the [] postfix.

Do you really think every function that produces a "list" has built into it
secret knowledge of how you would index a list? They just produce a
"Positional" or "Seq" or "List", etc. and *those* know what to do with [].
The function doesn't even need to say it's doing that; that's to produce
better error messages, not "wire what a list is into me".

On Wed, Sep 26, 2018 at 5:32 PM ToddAndMargo  wrote:

> On 9/26/18 11:42 AM, Larry Wall wrote:
> > On Wed, Sep 26, 2018 at 01:16:26PM -0400, Parrot Raiser wrote:
> > : Would it be correct to say:
> > :  [ ] aka square brackets, always surround the subscript of an array or
> > : list, i.e. here "n: is an integer,  [n] always means the nth item,
> > : while
> > : ( ), round brackets or parentheses, separate and group items to
> > : control processing order, and identify subroutine calls, surrounding
> > : the argument list, if any?
> >
> > I'd say there's a bit of confusion here between different syntactic
> > categories.  Your first definition is assuming only postfix position
> > (making [] a "postcircumfix"), while your second definition includes the
> > use of () in both term position and postfix position.  In term position,
> > yes, parentheses control the processing order and group things, but
> > [] also has a term-position interpretation of its own, which is as an
> > array composer (but not a subscript).  In postfix position, [] is always
> > a subscript as you indicated, but () is only for passing arguments
> > to something (and forcing a function call if that something might be
> > construed as a different keyword without the parens).  Any grouping
> > behavior is incidental to the argument processing, and in fact many
> > constructs you can use in normal grouping parens are illegal in an
> > argument list:
> >
> >  > p6 'say abs(42 or 43)'
> >  ===SORRY!=== Error while compiling -e
> >  Unable to parse expression in argument list; couldn't find final
> ')' (corresponding starter was at line 1)
> >  at -e:1
> >  --> say abs(42⏏ or 43)
> >
> > but in term position that's fine since the inside is a whole statement:
> >
> >  > p6 'say abs (42 or 43)'
> >  42
> >
> > The latter cannot be taken as a postfix because of the space. (Unless
> > you use Tuxic, which confuses this intentionally. :)
> >
> > The three main syntax categories you have to be able to track (and
> > it's much easier to track in Perl 6 than in Perl 5), are:
> >
> >  1) when you're expecting a term
> >  2) when you're expecting a postfix (or infix if there's no postfix)
> >  3) when you're expecting only an infix
> >
> > The careful distinction of which category the grammar engine is expecting
> > is critical to understanding any version of Perl, whether 5 or 6.
> > You can't adequately describe any random syntax in Perl without first
> > nailing down which of the main grammar rules is going to be parsing it.
> >
> > Well, I've probably said more than enough.  :)
> >
> > Larry
> >
>
> Hi Larry,
>
> Wonderful explanation!  Thank you!
>
> Followup question.  I am confused.  How did they get from
>
>   multi method words(Str:D $input: $limit = Inf --> Positional)
>
> to what goes in the () and what goes in the []?
>
> And why are they using the term "$limit" instead of "$selection"?
>
> Yours in confusion,
> -T
>
>
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>


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


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 10:47 AM, The Sidhekin wrote:
On Wed, Sep 26, 2018 at 8:58 AM Todd Chester > wrote:


Hi All,

Over on
https://docs.perl6.org/routine/words
I see

     multi method words(Str:D $input: $limit = Inf --> Positional)

HOW IN THE WORLD did they convert `$limit = Inf` into an
array index!?!?!


   It's not.  It's a limit:

eirik@greencat[19:41:18]~$ perl6 -e '.say for "foo bar baz qux".words(2)'
foo
bar
eirik@greencat[19:41:29]~$

   I see from your other email that you're using square brackets.  
That's what makes a zero-based index:


eirik@greencat[19:41:29]~$ perl6 -e '.say for "foo bar baz qux".words[2]'
baz
eirik@greencat[19:43:00]~$

   But this index is not an argument to the words method.  It is an 
argument to the .[ ] postcircumfix.


   That these are different things is perhaps more easily seen when 
they're both present:


eirik@greencat[19:45:54]~$ perl6 -e '.say for "foo bar baz 
qux".words(3)[*-1]'

baz
eirik@greencat[19:45:59]~$

   Here, it may be clearer that the $limit is 3, and the index is *-1.


Eirik



Hi Eirik,

Thank you for the explanation.

I think I did  not make myself clear.  I do know how to
use the function and I use it all the time.

What I don't understand is:

 multi method words(Str:D $input: $limit = Inf --> Positional)

Specifically "$limit = Inf".  Why are we using "$limit" instead
of "$selection" and why are we throwing "Inf" into the mix
as it is a "type".  "Types" are written like "Str:D" and come
before the variable, not after.  (I know the ":D" means "defined".)

And where is it stated what goes in the () and what goes
in the []?

Yours in frustration,
-T


Re: words[] question

2018-09-26 Thread ToddAndMargo

On 9/26/18 11:42 AM, Larry Wall wrote:

On Wed, Sep 26, 2018 at 01:16:26PM -0400, Parrot Raiser wrote:
: Would it be correct to say:
:  [ ] aka square brackets, always surround the subscript of an array or
: list, i.e. here "n: is an integer,  [n] always means the nth item,
: while
: ( ), round brackets or parentheses, separate and group items to
: control processing order, and identify subroutine calls, surrounding
: the argument list, if any?

I'd say there's a bit of confusion here between different syntactic
categories.  Your first definition is assuming only postfix position
(making [] a "postcircumfix"), while your second definition includes the
use of () in both term position and postfix position.  In term position,
yes, parentheses control the processing order and group things, but
[] also has a term-position interpretation of its own, which is as an
array composer (but not a subscript).  In postfix position, [] is always
a subscript as you indicated, but () is only for passing arguments
to something (and forcing a function call if that something might be
construed as a different keyword without the parens).  Any grouping
behavior is incidental to the argument processing, and in fact many
constructs you can use in normal grouping parens are illegal in an
argument list:

 > p6 'say abs(42 or 43)'
 ===SORRY!=== Error while compiling -e
 Unable to parse expression in argument list; couldn't find final ')' 
(corresponding starter was at line 1)
 at -e:1
 --> say abs(42⏏ or 43)

but in term position that's fine since the inside is a whole statement:

 > p6 'say abs (42 or 43)'
 42

The latter cannot be taken as a postfix because of the space. (Unless
you use Tuxic, which confuses this intentionally. :)

The three main syntax categories you have to be able to track (and
it's much easier to track in Perl 6 than in Perl 5), are:

 1) when you're expecting a term
 2) when you're expecting a postfix (or infix if there's no postfix)
 3) when you're expecting only an infix
 
The careful distinction of which category the grammar engine is expecting

is critical to understanding any version of Perl, whether 5 or 6.
You can't adequately describe any random syntax in Perl without first
nailing down which of the main grammar rules is going to be parsing it.

Well, I've probably said more than enough.  :)

Larry



Hi Larry,

Wonderful explanation!  Thank you!

Followup question.  I am confused.  How did they get from

 multi method words(Str:D $input: $limit = Inf --> Positional)

to what goes in the () and what goes in the []?

And why are they using the term "$limit" instead of "$selection"?

Yours in confusion,
-T



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


Re: Could this be any more obscure?

2018-09-26 Thread Laurent Rosenfeld via perl6-users
You can set a limit to the number of items (words) you want to retrieve:
you will get only the first $limit words.

If you don't supply any limit, Inf can be thought as the default value for
the number of items, i.e. there is no limit and the routine will return as
many words as it can from the source input.


Le mer. 26 sept. 2018 à 23:19, ToddAndMargo  a
écrit :

> >> On Wed, Sep 26, 2018 at 2:57 AM Todd Chester  >> multi method words(Str:D $input: $limit = Inf --> Positional)
>
>
> On 9/26/18 7:21 AM, Brandon Allbery wrote:
>
> > $limit sets a limit on how many words it will make. Inf means there's no
> > limit. Your assumption that it must be some kind of array index doesn't
> > make a lot of sense; this doesn't index at all, it splits at whitespace
> > until it's got the number of chunks you told it to make, indexing the
> > result is your problem. Small pieces of functionality, not "god
> > functions" that try to do everything you can possibly think of.
>
> Hi Brandon,
>
> So, "$limit = Inf" means that I can put an infinite number of
> stuff in the [] or ()
>
> p6 '"a b c d e".words(3)[2,4].say;'
> (c Nil)
>
> $ p6 '"a b c d e".words(3).say;'
> (a b c)
>
>
> I really think that could be written better.
>
> First off the parameter is not a "limit".  It is
> a selection.
>
> And second, "Inf" is a "type", meaning "infinity" or larger
> than Perl's memory allocation can handle.  It is confusing
> to use it to state that there can be any number of selections
> in the parameter.
>
> $ p6 '"a b c d e".words()[2,4,1,3,3,3,3,20].say;'
> (c e b d d d d Nil)
>
> It also does not tell that the parameter(s) is/are integers
> or what happens if you supply a sting (error) or a real (it
> truncates):
>
>  $ p6 '"a b c d e".words()["a"].say;'
>  Cannot convert string to number: base-10 number must begin
>  with valid digits or '.' in '⏏a' (indicated by ⏏)
>  in block  at -e line 1
>
> $ p6 '"a b c d e".words()[ 2.5 ].say;'
> c
>
> Third, it does not state the difference between using () and [].
> Or how to mix and match them.
>
> $ p6 '"a b c d e".words(3).say;'
> (a b c)
>
> Where (3) gives you the first three words
>
> -T
>


Re: Could this be any more obscure?

2018-09-26 Thread Brandon Allbery
No, that's not it either. words is "split at whitespace until you've made
$limit chunks". It doesn't know or care what you do afterward with the Seq.
And the [] are afterward, they apply to the Seq, not to words() which
doesn't even know about them.

On Wed, Sep 26, 2018 at 5:19 PM ToddAndMargo  wrote:

> >> On Wed, Sep 26, 2018 at 2:57 AM Todd Chester  >> multi method words(Str:D $input: $limit = Inf --> Positional)
>
>
> On 9/26/18 7:21 AM, Brandon Allbery wrote:
>
> > $limit sets a limit on how many words it will make. Inf means there's no
> > limit. Your assumption that it must be some kind of array index doesn't
> > make a lot of sense; this doesn't index at all, it splits at whitespace
> > until it's got the number of chunks you told it to make, indexing the
> > result is your problem. Small pieces of functionality, not "god
> > functions" that try to do everything you can possibly think of.
>
> Hi Brandon,
>
> So, "$limit = Inf" means that I can put an infinite number of
> stuff in the [] or ()
>
> p6 '"a b c d e".words(3)[2,4].say;'
> (c Nil)
>
> $ p6 '"a b c d e".words(3).say;'
> (a b c)
>
>
> I really think that could be written better.
>
> First off the parameter is not a "limit".  It is
> a selection.
>
> And second, "Inf" is a "type", meaning "infinity" or larger
> than Perl's memory allocation can handle.  It is confusing
> to use it to state that there can be any number of selections
> in the parameter.
>
> $ p6 '"a b c d e".words()[2,4,1,3,3,3,3,20].say;'
> (c e b d d d d Nil)
>
> It also does not tell that the parameter(s) is/are integers
> or what happens if you supply a sting (error) or a real (it
> truncates):
>
>  $ p6 '"a b c d e".words()["a"].say;'
>  Cannot convert string to number: base-10 number must begin
>  with valid digits or '.' in '⏏a' (indicated by ⏏)
>  in block  at -e line 1
>
> $ p6 '"a b c d e".words()[ 2.5 ].say;'
> c
>
> Third, it does not state the difference between using () and [].
> Or how to mix and match them.
>
> $ p6 '"a b c d e".words(3).say;'
> (a b c)
>
> Where (3) gives you the first three words
>
> -T
>


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


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo
On Wed, Sep 26, 2018 at 2:57 AM Todd Chester multi method words(Str:D $input: $limit = Inf --> Positional)



On 9/26/18 7:21 AM, Brandon Allbery wrote:

$limit sets a limit on how many words it will make. Inf means there's no 
limit. Your assumption that it must be some kind of array index doesn't 
make a lot of sense; this doesn't index at all, it splits at whitespace 
until it's got the number of chunks you told it to make, indexing the 
result is your problem. Small pieces of functionality, not "god 
functions" that try to do everything you can possibly think of.


Hi Brandon,

So, "$limit = Inf" means that I can put an infinite number of
stuff in the [] or ()

   p6 '"a b c d e".words(3)[2,4].say;'
   (c Nil)

   $ p6 '"a b c d e".words(3).say;'
   (a b c)


I really think that could be written better.

First off the parameter is not a "limit".  It is
a selection.

And second, "Inf" is a "type", meaning "infinity" or larger
than Perl's memory allocation can handle.  It is confusing
to use it to state that there can be any number of selections
in the parameter.

   $ p6 '"a b c d e".words()[2,4,1,3,3,3,3,20].say;'
   (c e b d d d d Nil)

It also does not tell that the parameter(s) is/are integers
or what happens if you supply a sting (error) or a real (it
truncates):

$ p6 '"a b c d e".words()["a"].say;'
Cannot convert string to number: base-10 number must begin
with valid digits or '.' in '⏏a' (indicated by ⏏)
in block  at -e line 1

   $ p6 '"a b c d e".words()[ 2.5 ].say;'
   c

Third, it does not state the difference between using () and [].
Or how to mix and match them.

   $ p6 '"a b c d e".words(3).say;'
   (a b c)

Where (3) gives you the first three words

-T


Re: Could this be any more obscure?

2018-09-26 Thread ToddAndMargo

On 9/26/18 7:21 AM, Brandon Allbery wrote:
You're imposing a shape on this, then getting angry at us when it turns 
out to be wrong. I'm sorry nobody could read your mind ahead of time to 
find out the "proper" way to shape it.


Hi Brandon,

Uh Oh !  Better fix this.  I am not angry.  I am frustrated.  It
would be really foolish of me to get angry at those who are
extremely gracious in helping me sort these things out.  That
would be cutting my nose off to spite my face.  I do apologize
if I am coming off as anything other than trying to learn.

-T


Re: words[] question

2018-09-26 Thread Larry Wall
On Wed, Sep 26, 2018 at 01:16:26PM -0400, Parrot Raiser wrote:
: Would it be correct to say:
:  [ ] aka square brackets, always surround the subscript of an array or
: list, i.e. here "n: is an integer,  [n] always means the nth item,
: while
: ( ), round brackets or parentheses, separate and group items to
: control processing order, and identify subroutine calls, surrounding
: the argument list, if any?

I'd say there's a bit of confusion here between different syntactic
categories.  Your first definition is assuming only postfix position
(making [] a "postcircumfix"), while your second definition includes the
use of () in both term position and postfix position.  In term position,
yes, parentheses control the processing order and group things, but
[] also has a term-position interpretation of its own, which is as an
array composer (but not a subscript).  In postfix position, [] is always
a subscript as you indicated, but () is only for passing arguments
to something (and forcing a function call if that something might be
construed as a different keyword without the parens).  Any grouping
behavior is incidental to the argument processing, and in fact many
constructs you can use in normal grouping parens are illegal in an
argument list:

> p6 'say abs(42 or 43)'
===SORRY!=== Error while compiling -e
Unable to parse expression in argument list; couldn't find final ')' 
(corresponding starter was at line 1)
at -e:1
--> say abs(42⏏ or 43)

but in term position that's fine since the inside is a whole statement:

> p6 'say abs (42 or 43)'
42

The latter cannot be taken as a postfix because of the space. (Unless
you use Tuxic, which confuses this intentionally. :)

The three main syntax categories you have to be able to track (and
it's much easier to track in Perl 6 than in Perl 5), are:

1) when you're expecting a term
2) when you're expecting a postfix (or infix if there's no postfix)
3) when you're expecting only an infix

The careful distinction of which category the grammar engine is expecting
is critical to understanding any version of Perl, whether 5 or 6.
You can't adequately describe any random syntax in Perl without first
nailing down which of the main grammar rules is going to be parsing it.

Well, I've probably said more than enough.  :)

Larry


Re: Could this be any more obscure?

2018-09-26 Thread The Sidhekin
On Wed, Sep 26, 2018 at 8:58 AM Todd Chester  wrote:

> Hi All,
>
> Over on
>  https://docs.perl6.org/routine/words
> I see
>
> multi method words(Str:D $input: $limit = Inf --> Positional)
>
> HOW IN THE WORLD did they convert `$limit = Inf` into an
> array index!?!?!
>

  It's not.  It's a limit:

eirik@greencat[19:41:18]~$ perl6 -e '.say for "foo bar baz qux".words(2)'
foo
bar
eirik@greencat[19:41:29]~$

  I see from your other email that you're using square brackets.  That's
what makes a zero-based index:

eirik@greencat[19:41:29]~$ perl6 -e '.say for "foo bar baz qux".words[2]'
baz
eirik@greencat[19:43:00]~$

  But this index is not an argument to the words method.  It is an argument
to the .[ ] postcircumfix.

  That these are different things is perhaps more easily seen when they're
both present:

eirik@greencat[19:45:54]~$ perl6 -e '.say for "foo bar baz
qux".words(3)[*-1]'
baz
eirik@greencat[19:45:59]~$

  Here, it may be clearer that the $limit is 3, and the index is *-1.


Eirik


Re: words[] question

2018-09-26 Thread Parrot Raiser
Would it be correct to say:
 [ ] aka square brackets, always surround the subscript of an array or
list, i.e. here "n: is an integer,  [n] always means the nth item,
while
( ), round brackets or parentheses, separate and group items to
control processing order, and identify subroutine calls, surrounding
the argument list, if any?

On 9/26/18, Brian Duggan  wrote:
> On Tuesday, September 25, Todd Chester wrote:
>> Not to ask too obvious a question, but why does words use a []
>> instead of a () ?
>> ...
>> I am confused as to when to use [] and when to use () with a method.
>
> If a method is called without arguments, the () can be omitted.
>
>"a man a plan a canal -- panama".words()
>"a man a plan a canal -- panama".words# <-- same thing
>
> [] acts on the return value -- it takes an element of a list
>
>"a man a plan a canal -- panama".words()[3]
>"a man a plan a canal -- panama".words[3]  # <-- same thing
>
> Brian
>


Re: Installing Perl6 on shared server

2018-09-26 Thread Parrot Raiser
P.S. By today's standards, that's a pretty chintzy service; are their
limits aimed at IoT thingies?


Re: Installing Perl6 on shared server

2018-09-26 Thread Parrot Raiser
> I'm not sure which of these is limiting the compilation of rakudo.

2 out of 3 ain’t bad?  :-(


Unfortunately, they're && not ||. :-)*

On 9/26/18, Elizabeth Mattijsen  wrote:
>> On 26 Sep 2018, at 06:03, Richard Hainsworth 
>> wrote:
>>
>> Further to this question. Support staff at hosting company just informed
>> me that for the plan I have at present, the following limits are in
>> place:
>>
>> 60 seconds CPU execution time per process
>
> Build time on my MBP is around 75 seconds on my MBP.
>
>
>> 195MB of RAM per process
>
> Building rakudo *at the moment* takes about 1.2G of RAM.  This is about to
> get a whole lot less, but no where near 195MB.
>
>
>> 20 simultaneous processes
>
> That should be ok.
>
>
>> I'm not sure which of these is limiting the compilation of rakudo.
>
> 2 out of 3 ain’t bad?  :-(
>
>
> Liz


Re: Could this be any more obscure?

2018-09-26 Thread Brad Gilbert
`$limit` isn't an array index.

It's an argument that is passed on to the Iterator that tells it to stop
when it has produced that many values.

(Also it returns a `Seq`, not a `Positional` [fixed])

You can think of it as the following:

'abc def'.words.head( $limit );

`words` does something more like this though:

sub words ( Str:D $input, $limit = Inf --> Seq ) {
gather {
my $count = 0;
my $prev-ws = -1;

loop {
# stop if $limit has been reached
last if ++$count > $limit;  #<--- $limit

# index of whitespace
my $next-ws = $input.index( ' ', $prev-ws + 1 );

# run after each iteration
NEXT $prev-ws = $next-ws;

with $next-ws {  # index found a space

# skip two whitespaces in a row
next if $prev-ws+1 == $next-ws;

# give the next value
take substr( $input, $prev-ws+1, $next-ws - $prev-ws - 1 );

} else { # index didn't find a space

# stop if the last character was a space
last if $prev-ws+1 >= $input.chars;

# give the last value
take substr( $input, $prev-ws+1 );

# end of sequence
last;
}
}
}
}

say words('abc def ghi jkl mno pqr stu vwx yz', 3).perl;
# ("abc", "def", "ghi").Seq
On Wed, Sep 26, 2018 at 1:57 AM Todd Chester  wrote:
>
> Hi All,
>
> Over on
>  https://docs.perl6.org/routine/words
> I see
>
> multi method words(Str:D $input: $limit = Inf --> Positional)
>
> HOW IN THE WORLD did they convert `$limit = Inf` into an
> array index!?!?!
>
> https://docs.perl6.org/type/Num#Inf
> And `Inf` means a number larger than Perl can handle or Infinity.
> What does that have to do with ANYTHING!?
>
> Yours in confusion,
> -T
>
> And the worst part is that I know how to use "words" and use it
> frequently.  And the documentation is a nightmare to understand.
>
> Link to Positional:
> https://docs.perl6.org/type/Positional
> Role for objects which support indexing them using
> postcircumfix:«[ ]» (usually list-like objects).
> Example types with Positional role include List,
> Array, Range, and Buf.
>
> I like him using `Str:D $input:` rather than just `Str:D:`
> and it is more intuitive


Re: Could this be any more obscure?

2018-09-26 Thread Brandon Allbery
You're imposing a shape on this, then getting angry at us when it turns out
to be wrong. I'm sorry nobody could read your mind ahead of time to find
out the "proper" way to shape it.

$limit sets a limit on how many words it will make. Inf means there's no
limit. Your assumption that it must be some kind of array index doesn't
make a lot of sense; this doesn't index at all, it splits at whitespace
until it's got the number of chunks you told it to make, indexing the
result is your problem. Small pieces of functionality, not "god functions"
that try to do everything you can possibly think of.

On Wed, Sep 26, 2018 at 2:57 AM Todd Chester  wrote:

> Hi All,
>
> Over on
>  https://docs.perl6.org/routine/words
> I see
>
> multi method words(Str:D $input: $limit = Inf --> Positional)
>
> HOW IN THE WORLD did they convert `$limit = Inf` into an
> array index!?!?!
>
> https://docs.perl6.org/type/Num#Inf
> And `Inf` means a number larger than Perl can handle or Infinity.
> What does that have to do with ANYTHING!?
>
> Yours in confusion,
> -T
>
> And the worst part is that I know how to use "words" and use it
> frequently.  And the documentation is a nightmare to understand.
>
> Link to Positional:
> https://docs.perl6.org/type/Positional
> Role for objects which support indexing them using
> postcircumfix:«[ ]» (usually list-like objects).
> Example types with Positional role include List,
> Array, Range, and Buf.
>
> I like him using `Str:D $input:` rather than just `Str:D:`
> and it is more intuitive
>


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


Re: words[] question

2018-09-26 Thread Brian Duggan
On Tuesday, September 25, Todd Chester wrote: 
> Not to ask too obvious a question, but why does words use a []
> instead of a () ?
> ...
> I am confused as to when to use [] and when to use () with a method.

If a method is called without arguments, the () can be omitted.

   "a man a plan a canal -- panama".words()
   "a man a plan a canal -- panama".words# <-- same thing

[] acts on the return value -- it takes an element of a list

   "a man a plan a canal -- panama".words()[3]
   "a man a plan a canal -- panama".words[3]  # <-- same thing

Brian


Re: Installing Perl6 on shared server

2018-09-26 Thread Elizabeth Mattijsen
> On 26 Sep 2018, at 06:03, Richard Hainsworth  wrote:
> 
> Further to this question. Support staff at hosting company just informed me 
> that for the plan I have at present, the following limits are in place:
> 
> 60 seconds CPU execution time per process

Build time on my MBP is around 75 seconds on my MBP.


> 195MB of RAM per process

Building rakudo *at the moment* takes about 1.2G of RAM.  This is about to get 
a whole lot less, but no where near 195MB.


> 20 simultaneous processes

That should be ok.


> I'm not sure which of these is limiting the compilation of rakudo.

2 out of 3 ain’t bad?  :-(


Liz