Nil ?

2018-09-11 Thread ToddAndMargo

What am, I missing?

$ p6 'my $x; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };'
Not Nil

$ p6 'my $x = Nil; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };'
Not Nil


Re: how do I do this index in p6?

2018-09-11 Thread ToddAndMargo

On 09/11/2018 07:08 PM, Vadim Belman wrote:

Of course constants!

constant ACONST = pi;
constant $SCONST = "aaa";

Even

constant @a = [1,2,3];

though it doesn't affect the actual array content making '@a = []' 
possible due to the way '=' works in the array context. But

constant @a = <1 2 3>;

works as expected. I could leave it as a homework for you to find out why!  A 
tip which you wouldn't find in the documentation: '=' in array context does 
element-by-element assign to the left hand array.


11 вер. 2018 р. о 20:17 ToddAndMargo  написав(ла):

On 09/11/2018 08:11 AM, yary wrote:

"Nil... it's a constant, so you have to use =:= to check for equality."


Constants?  I thought we did not have constants!  Am I mixing
Perl 5 with Perl 6, again?



Best regards,
Vadim Belman



Hi Vadim,

G   Foiled by Perl 5 again!

$ p6 'constant Pi= 3.1415; say Pi.perl;'
3.1415

$ p6 'constant Pi= "3.1415"; say Pi.perl;'
"3.1415"

$ p6 'constant Pi= "3.1415"; say "<" ~ Pi ~">";'
<3.1415>

$ p6 'constant Pi= "3.1415"; say Pi / 2;'
1.57075

$ p6 'constant Pi= "3.1415"; say "Pi";'
Pi

$ p6 'constant Pi= "3.1415"; say Pi;'
3.1415


Thank you!

-T


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


Re: Please explain this to me

2018-09-11 Thread ToddAndMargo

On 09/11/2018 03:09 AM, ToddAndMargo wrote:

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

Okay, I know that
    Str is a string
    Cool is an object that can be treated as both a string and a number
    $needle is the second optional parameter

What is "D"?

$needle is optional, why is it not stated as "$needle?"

How is both Str:D: and Cool:D the first parameter?

Why does "Str:D:" have a colon on the end and "Cool:D" does not?

What is Int(Cool:D) ?

What is $pos ?

Where is it stated that it has a return a value?

Where is it state that the return value is a boolean?

Yours in confusion,
-T


First off, I band the heck out of "contains" all over my code.
I know how it works.  What I don't know is how the documentation
got there.

Okay I am making progress.

"multi method contains" means that it is a "method" (.foo).
Perl 6 has "methods" `.foo` and subroutines `sub foo(...){...}`

"Str:D" means it reads a string Str.contains(...) and
that the string is mandatory (constrained).

Okay, foul!
   Str:D: Cool:D $needle
why is there not a comma between "Str:D:" and "Cool:D"?
And what is with the extra ":".  By chance is the extra ":"
a confusing way of using a comma for a separator?

"Cool:D $needle" means that sub string or number you are
looking for.  And it is constrained.  You must enter a value.

Foul again!
   Int(Cool:D) $pos
Why "Int(Cool:D)"?  Why is type Int being redefined
as type "Cool" (number or any type or a string).

$pos is the starting position to check for a match,
start at zero.

Foul!
$pos is optional.  But there is a "D" in its definition
making it constrained and not optional.

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

I am getting there.  Thank you all for the help.

-T









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


Re: how do I do this index in p6?

2018-09-11 Thread Vadim Belman
Of course constants!

constant ACONST = pi;
constant $SCONST = "aaa";

Even

constant @a = [1,2,3];

though it doesn't affect the actual array content making '@a = []' 
possible due to the way '=' works in the array context. But

constant @a = <1 2 3>;

works as expected. I could leave it as a homework for you to find out why!  A 
tip which you wouldn't find in the documentation: '=' in array context does 
element-by-element assign to the left hand array.

> 11 вер. 2018 р. о 20:17 ToddAndMargo  написав(ла):
> 
> On 09/11/2018 08:11 AM, yary wrote:
>> "Nil... it's a constant, so you have to use =:= to check for equality."
> 
> Constants?  I thought we did not have constants!  Am I mixing
> Perl 5 with Perl 6, again?
> 

Best regards,
Vadim Belman


!

2018-09-11 Thread ToddAndMargo

On 09/11/2018 10:14 AM, Larry Wall wrote:

On Tue, Sep 11, 2018 at 02:42:20AM -0700, ToddAndMargo wrote:
: How do I clean this up for use with Perl 6?
:
: $ perl -E 'say index("abc", "z") == -1 ? "False" : "True"'
: False

I'm a little bit surprised nobody suggested the most basic method:

 say index("abc", "z").defined ?? "True" !! "False"

Larry



I love it!  Thank you!


Re: how do I do this index in p6?

2018-09-11 Thread ToddAndMargo

On 09/11/2018 08:11 AM, yary wrote:

"Nil... it's a constant, so you have to use =:= to check for equality."


Constants?  I thought we did not have constants!  Am I mixing
Perl 5 with Perl 6, again?


Re: case insensitive "contains"?

2018-09-11 Thread ToddAndMargo

On 09/11/2018 03:53 PM, Trey Harris wrote:

And my response to his response that also was unintentionally off-list.



I got it.  I will probably be writing it down later today
in my documents.

My failing was thinking rx was some kind of command
I had not seen before.  As soon as you showed me it
was of a dynamic way of salting the inside of a regex
with commands, the lights when off.

Excellent write up by the way.  Thank you!


Re: A comparison between P5 docs and p6 docs

2018-09-11 Thread ToddAndMargo

On 09/11/2018 08:17 AM, Laurent Rosenfeld via perl6-users wrote:

Hi Todd,

I fully agree with Tom B.'s message that you should really set out to 
read a Perl 6 book. Many of the things you asked are covered in most of 
the available books. And the available books are easier than the 
official documentation for a beginner to start understand the basic 
underlying concepts.


I should add that you don't even have to /buy/ one book, since my own 
/Think Perl 6/ book is freely available on the Internet (Creative 
Commons license): https://greenteapress.com/wp/think-perl-6/. Well, if 
you are interested in reading it, I'd suggest you look for the PDF on my 
Github repository 
(https://github.com/LaurentRosenfeld/thinkperl6/tree/master/PDF), 
because it is more up-to-date (number of small corrections made 
following comments from readers).


So it would take you just a few minutes (at no cost) to download it and 
start enjoying it.


Cheers,
Laurent.



Hi Laurent,

Ordinarily I would agree with you.  But I know my own brain and
how it works.  I only learn by doing.  Have tried to change that
and can't.

When I "dive in", I open up the reference docs and bang away.
I also use Google, but that is next to useless in Perl 6 as Perl 5
hits drowned Perl 6 out.

I am 62 years old, have a bachelors degree in Electronic and
Computer Engineering, Cum Laude and have been programming
things all my life.  I live with the reference page open
while pounding out code.

Perl 6's document are next to useless for me.  This is the first
time I have come across references that were so badly done.
And programming of the Automated Test Equipment I did
had some documents to behold.  CP-M was not fun either.

Do not misunderstand, I ADORE Perl 6.  It is a wonderful clean
up of Perl 5, especially the subroutine definitions and regex's.
The only step backward is the docs.

The developers have their own specification/documentation.
The reference docs need to be written for the rest of us.

By the way, I never mastered Perl 5's regex's.  I used them,
but could never figure out exactly what I did.  In Perl 6
I now can throw them together off the top of my head.  It
is kind of fun.

-T

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


Re: A comparison between P5 docs and p6 docs

2018-09-11 Thread ToddAndMargo

On 09/11/2018 08:52 AM, Tom Browder wrote:

On Tue, Sep 11, 2018 at 10:39 AM Parrot Raiser <1parr...@gmail.com> wrote:


One of the paradoxes of documentation, and the teaching of many
abstract topics, is that those with the most in-depth knowledge of the

...

I agree with you for the most part.  But the docs DO have examples,
and any reader who sees the lack of a suitable one should file an
issue or contribute a suitable change.

I got my  start here as a noob p6 user (coming  from years of p5 use)
contributing to the docs. And I, too, found many examples too obtuse
for a noob, and have changed some of them.

As experienced as Todd seems to be in p5, he should be able to improve
the docs one way or the other (but get a good book in the meantime;
Andrew Shitov's "Perl 6 at a Glance" is short and sweet for a first
book, Laurent's "Think Perl 6: How to Think Like a Computer Scientist"
for a deeper look).

Cheers,

-Tom



Hi Tom,

There are indeed some examples.  They are seldom explained
or even useful.  As such are pretty useless.  It is my impression
that sometimes the writer is showing off his skills as to how
complicated he can get.

Here is a useless example from contains:

say "Hello, World".contains(',', 1);  # OUTPUT: «False␤»

The "1" is not explained.  It took me 20 minutes to figure
out it was the starting position to start looking
in the string.  Initially I tough is was an extra command
for case sensitivity, multiple matches, etc..

The docs need to be written in the same fashion as a
spoken language dictionary.

Here is what the word mean
Here is how to use it in sentence.


This is how I would write "contains" in perdoc fashion
(It is posted on issue 2303):

   STR contains SUBSTR,POSITION
   STR contains SUBSTR

  Search for the existence of a SUBSTR in STR starting at
  or after POSITION. If POSITION is omitted, starts'
  searching from the beginning of the string (0).

  If the SUBSTR is located, "contains" returns "True",
  otherwise it returns "False".

  Examples:

  my Str $Haystack = "abc";
  my Str $Needle = "c";
  my Int $StartIndex = 1; # index to start looking, default = 0
  my Bool $Result;
  $Result = $Haystack.contains( "c", $StartIndex );
  say $Result;'

  True

  say "abc".contains( "b", 1 ); # start looking at index 1
  True

  say "abc".contains( "z" ); # start looking at default index 0
  False

You walk away knowing exactly how to use the function.  And you do not
have to have developer level knowledge to use it!

-T


Re: A comparison between P5 docs and p6 docs

2018-09-11 Thread ToddAndMargo

On 09/11/2018 04:53 AM, Tom Browder wrote:

Todd, some free advice:

1. DOCUMENTATION

The docs are a volunteer effort. You can help by contributing changes
and submitting issues.


Hi Tom,

I have started contributing to this effort as well.

One of the big hurdles is that those maintaining the
documents expect you to have developer lever knowledge
of their wring to understand it.  Perldocs does
not do this.

The developers have their own specification to work with.
The Docs need to be written for the rest of us.

Here is my latest on "contains" in perldocs fashion:
https://github.com/perl6/doc/issues/2303

But, it is like hitting your head on a brick wall.

-T


Re: case insensitive "contains"?

2018-09-11 Thread Trey Harris
And my response to his response that also was unintentionally off-list.

(Todd, if you don't mind resending your last private response—since your
other response was quoted below—in reply to this, please do.)

On Mon, Sep 10, 2018 at 22:00 ToddAndMargo  wrote:
> So you get to iteratively pick what the regex will be.
> I can see where this would be very powerful. Thank you!
>
> Also, really a bad idea to use in documentation
> as it "presumes" that the reader is very advanced in
> his knowledge of regex's. In which case he would
> not need to read the documentation anyway.

Pardon? I don't follow. "Really a bad idea to use" what?

Personally, I get rather annoyed when I have to sift through Yet Another
Introduction to Regexes just in order to find out how to use regexes in a
particular language or library. The documentation for a regex library
shouldn't explain regexes, if that's what you're saying. Most programmers
will be coming to any new language already knowing regexes of some sort.

I don't see what's "very advanced in... knowledge of regex[es]". Those
examples don't even use quantifiers; they're just fixed text matches with
case-insensitivity. If you find that "advanced", you should do one of the
many excellent regex tutorials available in whatever languages or
programmable editors you already know—trying to learn regexes and a new
language simultaneously will be a bit overwhelming, as regexes are a
language and practice unto themselves.

Perl 6's regex syntax is rather different from other languages' (a bit
amusingly, since in the meantime other modern languages have mostly
coalesced around adopting something close to Perl 5's), but you'll be much
better-equipped to understand them in Perl 6 if you understand them in
general first.


On Tue, Sep 11, 2018 at 18:49 Trey Harris  wrote:

> Oops— I sent the following yesterday and it somehow didn't go to the list:
>
> On Mon, Sep 10, 2018 at 19:02 ToddAndMargo  wrote:
>
>> Question, what the heck is
>>
>>   my $rx1 = rx:i/a/;
>>
>> Are they talking over beginner's heads again?
>>
>
> In the sense of "beginners to Perl", perhaps, since "rx" is familiar to
> Perl 5 programmers.
>
> Though if you search docs.perl6.org for "rx" you'll see a choice in the
> pop-down, "rx (quote)", which leads to:
>
> https://docs.perl6.org/language/regexes#index-entry-quote_%2F_%2F-quote_rx-quote_m-Lexical_conventions
>  and
> that says:
>
> ```
>
> Perl 6 has special syntax for writing regexes:
>
> m/abc/; # a regex that is immediately matched against $_
>
> rx/abc/;# a Regex object; allow adverbs to be used before regex
>
> /abc/;  # a Regex object; shorthand version of 'rx/ /' operator
> ```
>
> That entire section of the documentation is worth reading as it describes
> everything discussed in this thread.
>
> But in case it isn't clear, it just means that if you do
>
> my $result = "Juli 2018" ~~ m:i/jul/;
>
> then you'll get a match containing "Jul" as a result.
>
> It so happens in this case, when using ~~ against a literal like above,
> m// and rx// are pretty much interchangeable.
>
> But you could also do:
>
> my $pattern = rx:i/jul/;
> my $result = "Juli 2018" ~~ $pattern;
>
> and get the same result.
>
> If you tried to do
>
>my $pattern = m:i/jul/;
>
> You'll get an exception unless the $_ topic variable happens to contain a
> thing that can be regex-matched (like a string). The `m` explicitly causes
> the match to happen immediately.
>


Re: case insensitive "contains"?

2018-09-11 Thread Trey Harris
Oops— I sent the following yesterday and it somehow didn't go to the list:

On Mon, Sep 10, 2018 at 19:02 ToddAndMargo  wrote:

> Question, what the heck is
>
>   my $rx1 = rx:i/a/;
>
> Are they talking over beginner's heads again?
>

In the sense of "beginners to Perl", perhaps, since "rx" is familiar to
Perl 5 programmers.

Though if you search docs.perl6.org for "rx" you'll see a choice in the
pop-down, "rx (quote)", which leads to:
https://docs.perl6.org/language/regexes#index-entry-quote_%2F_%2F-quote_rx-quote_m-Lexical_conventions
and
that says:

```

Perl 6 has special syntax for writing regexes:

m/abc/; # a regex that is immediately matched against $_

rx/abc/;# a Regex object; allow adverbs to be used before regex

/abc/;  # a Regex object; shorthand version of 'rx/ /' operator
```

That entire section of the documentation is worth reading as it describes
everything discussed in this thread.

But in case it isn't clear, it just means that if you do

my $result = "Juli 2018" ~~ m:i/jul/;

then you'll get a match containing "Jul" as a result.

It so happens in this case, when using ~~ against a literal like above, m//
and rx// are pretty much interchangeable.

But you could also do:

my $pattern = rx:i/jul/;
my $result = "Juli 2018" ~~ $pattern;

and get the same result.

If you tried to do

   my $pattern = m:i/jul/;

You'll get an exception unless the $_ topic variable happens to contain a
thing that can be regex-matched (like a string). The `m` explicitly causes
the match to happen immediately.


Re: Appropriate last words

2018-09-11 Thread Shlomi Fish
Hi all,

On Mon, 3 Sep 2018 11:09:35 -0700
Larry Wall  wrote:

> On Mon, Sep 03, 2018 at 11:45:58AM -0500, Stephen Wilcoxon wrote:
> : Why the change in die handling between Perl 5 and 6?  Suppressing line
> : numbers with newline was very handy.  Alternatively, adding some sort of
> : directive would be more straight-forward (at least for Perl 5 users moving
> : to Perl 6).
> 
> Well, we did take Perl 5 users into account quite a lot, since many of
> us came from that direction, and we hope more will come in the future.
> 
> On the other hand, language design is all tradeoffs, and every time you
> add a low-powered feature (or keep one, in this case), you raise the
> barrier to entry for folks coming from other cultures, and you waste
> mindspace remembering things that don't buy you much.  For similar
> reasons, <> changed to lines() and all the magic rules about which
> variables are local to a loop went away. Likewise, a lot of the arcane
> knowledge of how a given function behaves in scalar or list context went
> away, mostly by splitting them into distinct operators that are easier
> to read and document.  Of course, the tradeoff is that that are then
> more operators.
> 
> So, sure, you could argue that we've just substituted one kind of arcane
> knowledge for another, but at least you can justify something like
> 
> exit note “Phooey”;
> 
> by mere function composition without appealing to the authority of
> a particular paragraph in the manual.  And of course you could also
> compose your own function if the situation ever rises more than once in
> your program.
> 
> my  =  ∘   eep “Phooey”;
> 
> In the specific case of this feature, one could also argue that putting
> that much semantic weight on the final character of the string is
> violating some kind of end-weight or one-pass principle, forcing a kind
> of mental time-travel for the reader, if not for the compiler.
> 
> Anyway, don't be a language designer if you want to make everyone happy
> all the time.  :-)
> 
> Well, actually, you can want it, just don't expect it... :-)
> 

I agree and I wrote about it here back in 2011 -
https://shlomif-tech.livejournal.com/57811.html ("Your Programming Language
Must Suck"). I also concentrate links to the more general theme of why one can
never please everyone here:
http://shlomifishswiki.branchable.com/Never_Try_to_Please_Everyone/ .

Regards,

Shlomi
> Larry



-- 
-
Shlomi Fish   http://www.shlomifish.org/
http://www.shlomifish.org/humour/ways_to_do_it.html

All Chuck Norris has to do is *look* at Perl code and it interprets itself
out of fear and respect. — DrForr
— http://www.shlomifish.org/humour/bits/facts/Chuck-Norris/

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


Re: Please explain this to me

2018-09-11 Thread Curt Tilmes
There's a talk for that too:

https://www.youtube.com/watch?v=7mkmZVIizFY 2016 - Basic OO in Perl 6‎ -
Dave Rolsky

On Tue, Sep 11, 2018 at 1:42 PM Brandon Allbery  wrote:

> I'd like to point out that Todd is from Perl 5, which doesn't distinguish
> between subs and methods because its built-in OO is a minimalist hack. An
> introduction to true objects might be in order.
>
> On Tue, Sep 11, 2018 at 8:34 AM Simon Proctor 
> wrote:
>
>> Also Todd I gave a talk on signatures types and multi methods at The Perl
>> Conference this year.
>>
>> https://www.youtube.com/watch?v=Sy-qb5nXKyc=8606s
>>
>> That should be just before the start.
>>
>>
>> https://www.slideshare.net/SimonProctor8/perl6-signatures-types-and-multicall
>>
>> Slides are here.
>>
>> Hope this helps.
>>
>> Simon
>>
>> On Tue, 11 Sep 2018 at 13:05 Simon Proctor 
>> wrote:
>>
>>> 1) why is it a "method" and not a "function"?
>>>
>>> methods are all on instance of a Class (or Role) they can locally access
>>> the instances data via self or $ or ... see below.
>>>
>>> 1-1/2) why is there a color after a$?  What happens to $a?
>>>
>>> You can as an extra option give your instance object a different name,
>>> you seperate that from the rest of the args with a :
>>>
>>> 2) What is an "invocant"?  Does it mean I can access it
>>> by placing it after something with a dot?  Sort of
>>> like
>>>  contains("abc", "b")
>>>  "abc".contians("b")
>>>
>>> The incovant is the object you invoke the method on. It's the thing that
>>> gets assigned to self, $ (and whatever else you want to call it)
>>>
>>> 3) What makes the "invocant" special over the other second
>>> and third parameters?
>>>
>>> See about
>>>
>>>  > class Foo {
>>>
>>> 4) I see no class called "Foo" over on
>>> https://docs.perl6.org/type.html
>>>
>>> That's a class being defined for this example
>>>
>>> 5) Are they creating a new class?  If so, why?
>>>
>>> To make an example
>>>
>>>  >method whoami($me:) {
>>>
>>> 6) where is @b and %c?
>>>
>>> In this case thet aren't being passed.
>>>
>>>
>>>  >"Well I'm class $me.^name(), of course!"
>>>
>>> 7) why is there a caret in front of "name"?
>>>
>>> There are certain Meta Object methods that are access with a ^ infront
>>> of the name. I'd need to check the exact definition though.
>>>
>>> Please note the Perl5 docs have had decades of people working on them
>>> the Perl6 ones less so. There's bound to be some difference in scope.
>>>
>>> On Tue, 11 Sep 2018 at 12:11 ToddAndMargo  wrote:
>>>
 On 09/11/2018 03:30 AM, JJ Merelo wrote:
 > Also, "is no help whatsoever" is no help whatsoever. Saying what part
 of
 > it is not clear enough, or could be explained better, is.
 >

 Well now,

  >  method ($a: @b, %c) {};   # first argument is the invocant

 1) why is it a "method" and not a "function"?

 1-1/2) why is there a color after a$?  What happens to $a?

 2) What is an "invocant"?  Does it mean I can access it
 by placing it after something with a dot?  Sort of
 like
  contains("abc", "b")
  "abc".contians("b")

 3) What makes the "invocant" special over the other second
 and third parameters?

  > class Foo {

 4) I see no class called "Foo" over on
 https://docs.perl6.org/type.html

 5) Are they creating a new class?  If so, why?

  >method whoami($me:) {

 6) where is @b and %c?

  >"Well I'm class $me.^name(), of course!"

 7) why is there a caret in front of "name"?

  >}
  >  }
  >
  >
  >  say Foo.whoami; # OUTPUT: «Well I'm class Foo, of course!␤»

 8) no clue how they got there


 JJ, have you ever used Perl 5's perldocs?  They are a bazillion
 times easier to understand than Perl 6's.

 Thank you for the help with this?

 -T

>>> --
>>> Simon Proctor
>>> Cognoscite aliquid novum cotidie
>>>
>> --
>> Simon Proctor
>> Cognoscite aliquid novum cotidie
>>
>
>
> --
> brandon s allbery kf8nh
> allber...@gmail.com
>


Re: Functions and subroutines?

2018-09-11 Thread Larry Wall
On Tue, Sep 11, 2018 at 03:47:46AM -0700, ToddAndMargo wrote:
: In Perl, what is the proper terminology?

We're not picky, since Perl has never made a hard and fast distinction
between routines that return values and routines that don't.  You can call
them all functions or routines or procedures interchangeably depending
on whether you're thinking about their return values or their side effects.
Or just call 'em all "subs", that works too.

We do tend to distinguish the term "method", but even those are the
same thing underneath once they're called.  Methods are just routines
that were discovered via method dispatch on the first argument rather
than the usual function calling method.  And there's a little syntactic
sugar to let methods treat their first argument specially.  But you can
take a routine and poke it into a class to turn it into a method, and
going the other way, you can pull a method out of a class and call it
like a function.

So basically, if it's meant to be called with .foo notation, call it a
"method", and if it's meant to be called with foo() notation, call it
whatever you like.  But not "method". :)

Larry


Re: how do I do this index in p6?

2018-09-11 Thread Larry Wall
Oh, I guess Timo suggested .defined.  I should relearn to read, now that
I can see again...

Larry


Re: how do I do this index in p6?

2018-09-11 Thread Larry Wall
On Tue, Sep 11, 2018 at 02:42:20AM -0700, ToddAndMargo wrote:
: How do I clean this up for use with Perl 6?
: 
: $ perl -E 'say index("abc", "z") == -1 ? "False" : "True"'
: False

I'm a little bit surprised nobody suggested the most basic method:

say index("abc", "z").defined ?? "True" !! "False"

Larry


Re: A comparison between P5 docs and p6 docs

2018-09-11 Thread Parrot Raiser
One of the paradoxes of documentation, and the teaching of many
abstract topics, is that those with the most in-depth knowledge of the
topic,are the least suitable to explain it,  precisely because of that
knowledge. They can't remember what it felt like not to know
something, and they've usually learnt a
jargon to simplify and speed discussions. That has to be filtered
through 2 or 3 layers of ignorance before it's diluted to
comprehensibility. If you don't know what you don't know, it's hard to
plot a route to mastery. (On the other hand, more than one expert has
said something like "the best way to learn a topic is to teach a
course in it".)

In wanders the noob, and s/he is surrounded by weird words, some
utterly new, which may or may not have their usual meanings if they
aren't. It's hard to start exploring Wonderland when you don't even
know how to ask the way to the rabbit hole.

My impression of the Perl 6 documentation is that it was written by
the designers and implementors, for their needs, a by-product of the
development process. Since it's at the intersection of linguistics and
computer science, the terminology tends to be a blend of both,
seasoned with a pinch of local dialect. It's designed to answer
questions like "what category of language is it?", "what programming
paradigms does it favour?", "how is [some feature] designed?". For
someone constructing a taxonomy of computer languages, or looking for
interesting compiler techniques, it's great. That doesn't help the
(English major) beginner who wants to find and fix incorrectly cased
names  in a file, or extract some data.

It's also like the Unix documentation, an example-free zone. That
assumes that the reader is skilled in converting abstract categories
into explanatory examples for themselves, possibly one of the
fundamental skills of programming.  (It's much more natural to learn
an abstract principle for re-use by having it explained through a
concrete example.)

I'm still trying to map a path into the jungle from practical daily
treks, and it takes ruthless pruning of the language's features to
avoid diversions and use of as-yet-unexplained features.  (P5 can be
tricky that way, too, but there's not as much to hide behind the
curtain.) Trainee sales droids are taught not to mention "features",
unless they can explain at least 2 "benefits" to the mark, (sorry,
"prospect").  I'm going to start out with 5 ways to produce valid P6
that does absolutely nothing, and proceed from there. It'll be
interesting to see if that approach works.

(Apologies to Tom Browder for duplication; I had to edit the start of
the message to make sense )


Re: A comparison between P5 docs and p6 docs

2018-09-11 Thread Tom Browder
On Tue, Sep 11, 2018 at 10:31 AM Simon Proctor  wrote:
>
> It's a very good read. :)

Yes it is!


Re: how do I do this index in p6?

2018-09-11 Thread yary
"with"...

with 'apple'.index('a') { say "Found at position $_" } else { "Not here" }

# Found at position 0


with 'apple'.index('b') { say "Found at position $_" } else { "Not here" }

# Not here


-y

On Tue, Sep 11, 2018 at 8:16 AM, Timo Paulssen  wrote:

> On 11/09/18 17:11, yary wrote:
>
> "Nil... it's a constant, so you have to use =:= to check for equality."
>
> Can you elaborate on that requirement? == works for an equality checks
> with numeric constants- must be more than Nil's constant-ness that makes
> one use =:= - perhaps that Nil doesn't numify to anything?
>
>
> Nil does numify, but using == comparison for this is still problematic for
> two reasons:
>
> 1) Nil numifies to 0, which is a valid "true" result for the index method
> and
> 2) it outputs a warning:
>
> Use of Nil in numeric context
>   in block  at -e line 1
>
> using ~~ instead of =:= should also be okay, or checking for definedness
> with either .defined or using "with" instead of "if", which is very useful
> especially for index and friends.
>
> HTH
>   - Timo
>


Re: A comparison between P5 docs and p6 docs

2018-09-11 Thread Simon Proctor
It's a very good read. :)

On Tue, 11 Sep 2018 at 16:19 Laurent Rosenfeld via perl6-users <
perl6-users@perl.org> wrote:

> Hi Todd,
>
> I fully agree with Tom B.'s message that you should really set out to read
> a Perl 6 book. Many of the things you asked are covered in most of the
> available books. And the available books are easier than the official
> documentation for a beginner to start understand the basic underlying
> concepts.
>
> I should add that you don't even have to *buy* one book, since my own *Think
> Perl 6* book is freely available on the Internet (Creative Commons
> license): https://greenteapress.com/wp/think-perl-6/. Well, if you are
> interested in reading it, I'd suggest you look for the PDF on my Github
> repository (https://github.com/LaurentRosenfeld/thinkperl6/tree/master/PDF),
> because it is more up-to-date (number of small corrections made following
> comments from readers).
>
> So it would take you just a few minutes (at no cost) to download it and
> start enjoying it.
>
> Cheers,
> Laurent.
>
> Le mar. 11 sept. 2018 à 13:26, ToddAndMargo  a
> écrit :
>
>> Hi All,
>>
>> Not to beat a dead horse, but Perl 6's docs are
>> miserably hard to understand.
>>
>> Here is a comparison of Perl 5's perldocs and Perl 6's
>> docs:
>>
>> Perl 5:
>>
>> $ perldoc -f index
>>  index STR,SUBSTR,POSITION
>>  index STR,SUBSTR
>> The index function searches for one string within another,
>> but without the wildcard-like behavior of a full regular-
>> expression pattern match. It returns the position of
>> the first occurrence of SUBSTR in STR at or after POSITION.
>> If POSITION is omitted, starts searching from the beginning
>> of the string. POSITION before the beginning of the string
>> or after its end is treated as if it were the beginning
>> or the end, respectively. POSITION and the return value
>> are based at zero. If the substring is not found, "index"
>> returns -1.
>>
>> Perl 6:
>>
>>  https://docs.perl6.org/routine/index
>>
>>  Documentation for sub index assembled from the following types:
>>  class Cool
>>
>>  From Cool
>>  (Cool) routine index
>>
>>  Defined as:
>>
>>  multi subindex(Str(Cool) $s, Str:D $needle, Int(Cool) $startpos
>> = 0 --> Int)
>>  multi method index(Str(Cool) $needle, Int(Cool) $startpos = 0 -->
>> Int)
>>
>>  Coerces the first two arguments (in method form, also counting
>>  the invocant) to Str, and searches for $needle in the string
>>  starting from $startpos. It returns the offset into the string
>>  where $needle was found, and an undefined value if it was not
>>  found.
>>
>>  See the documentation in type Str for examples.
>>
>>
>> "Cources"??? Seriously:
>>
>>  https://www.merriam-webster.com/dictionary/coerce
>>  Definition of coerce coerced; coercing
>> transitive verb
>> 1 : to compel to an act or choice
>> was coerced into agreeing
>> abusers who coerce their victims into silence
>>
>> 2 : to achieve by force or threat
>> coerce compliance
>> coerce obedience
>>
>> 3 : to restrain or dominate by force
>>
>> And what the heck is a "multi sub" and a "multi method" anyway?
>> AND WHY DO I EVEN CARE?  I just what to know how to use the
>> stinking thing!  Geepers Creapers !!!  (I am trying to avoid
>> swearing.)
>>
>> Perl 5's perldoc just tells you what you need to know to use the
>> stinker.  It is concise and to the point.  Perl 6 is a nightmare
>> to understand.
>>
>> Thank for putting up with my frustration.
>>
>> -T
>>
> --
Simon Proctor
Cognoscite aliquid novum cotidie


Re: Functions and subroutines?

2018-09-11 Thread Simon Proctor
There are also Blocks like : my $a = do { 5 }; say $a; (Gives 5);

Blocks turn up all over the place big different between blocks and Routines
(Sub or Method) is you can't return from them. They will return the last
thing evaluated within them though. But a return statement inside one
raises and Expection. (Might be a Failure)...

On Tue, 11 Sep 2018 at 16:24 yary  wrote:

> And looking at questions in other threads- there are subroutines declared
> with "sub", those get called without an invocant.
>
> sub i-am-a-sub() { say "Hi from subroutine land!" }
>
> i-am-a-sub; # says "Hi from subroutine land!"
>
> and methods are declared inside a class, and are called with an invocant
> of that class type.
>
> class sample-class {
>   method speak-to-me {say "We are classy"}
> }
> my sample-class $object;
> $object. speak-to-me; # Guess what it says
>
> ... subroutines and methods, in the perl6 class hierarchy, are both
> subclasses "Routine"
> maybe that's the word your looking for!
>
> -y
>
> On Tue, Sep 11, 2018 at 8:12 AM, yary  wrote:
>
>> I would call them subroutines, since that's the long form of "sub"
>>
>> -y
>>
>> On Tue, Sep 11, 2018 at 3:47 AM, ToddAndMargo 
>> wrote:
>>
>>> Hi All,
>>>
>>> I use subs like ducks use water.  It is about time
>>> I learned what to properly call them.
>>>
>>> I come from Modula2 and Pascal (as well as bash), "functions"
>>> return a value outside the declared parameters and "(sub)routines"
>>> only can modify values through the declarations parameters.
>>>
>>> Sort of like
>>> function:   sub add($a, $b){return $a+$b}
>>> routine:sub add($a, $b, rw $c){$c = $a+$b}
>>>
>>> In Perl, what is the proper terminology?
>>>
>>> Many thanks,
>>> -T
>>>
>>> I no longer use "rw $c".  I always use "return".
>>> The guys told me this was the best way on the
>>> chat line, so I adopted it.
>>>
>>
>>
> --
Simon Proctor
Cognoscite aliquid novum cotidie


Re: Functions and subroutines?

2018-09-11 Thread yary
And looking at questions in other threads- there are subroutines declared
with "sub", those get called without an invocant.

sub i-am-a-sub() { say "Hi from subroutine land!" }

i-am-a-sub; # says "Hi from subroutine land!"

and methods are declared inside a class, and are called with an invocant of
that class type.

class sample-class {
  method speak-to-me {say "We are classy"}
}
my sample-class $object;
$object. speak-to-me; # Guess what it says

... subroutines and methods, in the perl6 class hierarchy, are both
subclasses "Routine"
maybe that's the word your looking for!

-y

On Tue, Sep 11, 2018 at 8:12 AM, yary  wrote:

> I would call them subroutines, since that's the long form of "sub"
>
> -y
>
> On Tue, Sep 11, 2018 at 3:47 AM, ToddAndMargo 
> wrote:
>
>> Hi All,
>>
>> I use subs like ducks use water.  It is about time
>> I learned what to properly call them.
>>
>> I come from Modula2 and Pascal (as well as bash), "functions"
>> return a value outside the declared parameters and "(sub)routines"
>> only can modify values through the declarations parameters.
>>
>> Sort of like
>> function:   sub add($a, $b){return $a+$b}
>> routine:sub add($a, $b, rw $c){$c = $a+$b}
>>
>> In Perl, what is the proper terminology?
>>
>> Many thanks,
>> -T
>>
>> I no longer use "rw $c".  I always use "return".
>> The guys told me this was the best way on the
>> chat line, so I adopted it.
>>
>
>


Re: A comparison between P5 docs and p6 docs

2018-09-11 Thread Laurent Rosenfeld via perl6-users
Hi Todd,

I fully agree with Tom B.'s message that you should really set out to read
a Perl 6 book. Many of the things you asked are covered in most of the
available books. And the available books are easier than the official
documentation for a beginner to start understand the basic underlying
concepts.

I should add that you don't even have to *buy* one book, since my own *Think
Perl 6* book is freely available on the Internet (Creative Commons
license): https://greenteapress.com/wp/think-perl-6/. Well, if you are
interested in reading it, I'd suggest you look for the PDF on my Github
repository (https://github.com/LaurentRosenfeld/thinkperl6/tree/master/PDF),
because it is more up-to-date (number of small corrections made following
comments from readers).

So it would take you just a few minutes (at no cost) to download it and
start enjoying it.

Cheers,
Laurent.

Le mar. 11 sept. 2018 à 13:26, ToddAndMargo  a
écrit :

> Hi All,
>
> Not to beat a dead horse, but Perl 6's docs are
> miserably hard to understand.
>
> Here is a comparison of Perl 5's perldocs and Perl 6's
> docs:
>
> Perl 5:
>
> $ perldoc -f index
>  index STR,SUBSTR,POSITION
>  index STR,SUBSTR
> The index function searches for one string within another,
> but without the wildcard-like behavior of a full regular-
> expression pattern match. It returns the position of
> the first occurrence of SUBSTR in STR at or after POSITION.
> If POSITION is omitted, starts searching from the beginning
> of the string. POSITION before the beginning of the string
> or after its end is treated as if it were the beginning
> or the end, respectively. POSITION and the return value
> are based at zero. If the substring is not found, "index"
> returns -1.
>
> Perl 6:
>
>  https://docs.perl6.org/routine/index
>
>  Documentation for sub index assembled from the following types:
>  class Cool
>
>  From Cool
>  (Cool) routine index
>
>  Defined as:
>
>  multi subindex(Str(Cool) $s, Str:D $needle, Int(Cool) $startpos
> = 0 --> Int)
>  multi method index(Str(Cool) $needle, Int(Cool) $startpos = 0 --> Int)
>
>  Coerces the first two arguments (in method form, also counting
>  the invocant) to Str, and searches for $needle in the string
>  starting from $startpos. It returns the offset into the string
>  where $needle was found, and an undefined value if it was not
>  found.
>
>  See the documentation in type Str for examples.
>
>
> "Cources"??? Seriously:
>
>  https://www.merriam-webster.com/dictionary/coerce
>  Definition of coerce coerced; coercing
> transitive verb
> 1 : to compel to an act or choice
> was coerced into agreeing
> abusers who coerce their victims into silence
>
> 2 : to achieve by force or threat
> coerce compliance
> coerce obedience
>
> 3 : to restrain or dominate by force
>
> And what the heck is a "multi sub" and a "multi method" anyway?
> AND WHY DO I EVEN CARE?  I just what to know how to use the
> stinking thing!  Geepers Creapers !!!  (I am trying to avoid
> swearing.)
>
> Perl 5's perldoc just tells you what you need to know to use the
> stinker.  It is concise and to the point.  Perl 6 is a nightmare
> to understand.
>
> Thank for putting up with my frustration.
>
> -T
>


Re: how do I do this index in p6?

2018-09-11 Thread Timo Paulssen
On 11/09/18 17:11, yary wrote:
> "Nil... it's a constant, so you have to use =:= to check for equality."
>
> Can you elaborate on that requirement? == works for an equality checks
> with numeric constants- must be more than Nil's constant-ness that
> makes one use =:= - perhaps that Nil doesn't numify to anything?

Nil does numify, but using == comparison for this is still problematic
for two reasons:

1) Nil numifies to 0, which is a valid "true" result for the index
method and
2) it outputs a warning:

    Use of Nil in numeric context
      in block  at -e line 1

using ~~ instead of =:= should also be okay, or checking for definedness
with either .defined or using "with" instead of "if", which is very
useful especially for index and friends.

HTH
  - Timo


Re: how do I do this index in p6?

2018-09-11 Thread JJ Merelo
El mar., 11 sept. 2018 a las 17:12, yary () escribió:

> "Nil... it's a constant, so you have to use =:= to check for equality."
>
> Can you elaborate on that requirement? == works for an equality checks
> with numeric constants- must be more than Nil's constant-ness that makes
> one use =:= - perhaps that Nil doesn't numify to anything?
>

That's correct. It yields an error when you try to numify it.

Cheers

JJ


-- 
JJ


Re: Functions and subroutines?

2018-09-11 Thread yary
I would call them subroutines, since that's the long form of "sub"

-y

On Tue, Sep 11, 2018 at 3:47 AM, ToddAndMargo  wrote:

> Hi All,
>
> I use subs like ducks use water.  It is about time
> I learned what to properly call them.
>
> I come from Modula2 and Pascal (as well as bash), "functions"
> return a value outside the declared parameters and "(sub)routines"
> only can modify values through the declarations parameters.
>
> Sort of like
> function:   sub add($a, $b){return $a+$b}
> routine:sub add($a, $b, rw $c){$c = $a+$b}
>
> In Perl, what is the proper terminology?
>
> Many thanks,
> -T
>
> I no longer use "rw $c".  I always use "return".
> The guys told me this was the best way on the
> chat line, so I adopted it.
>


Re: how do I do this index in p6?

2018-09-11 Thread yary
"Nil... it's a constant, so you have to use =:= to check for equality."

Can you elaborate on that requirement? == works for an equality checks with
numeric constants- must be more than Nil's constant-ness that makes one use
=:= - perhaps that Nil doesn't numify to anything?


Re: Please explain this to me

2018-09-11 Thread Simon Proctor
Also Todd I gave a talk on signatures types and multi methods at The Perl
Conference this year.

https://www.youtube.com/watch?v=Sy-qb5nXKyc=8606s

That should be just before the start.

https://www.slideshare.net/SimonProctor8/perl6-signatures-types-and-multicall

Slides are here.

Hope this helps.

Simon

On Tue, 11 Sep 2018 at 13:05 Simon Proctor  wrote:

> 1) why is it a "method" and not a "function"?
>
> methods are all on instance of a Class (or Role) they can locally access
> the instances data via self or $ or ... see below.
>
> 1-1/2) why is there a color after a$?  What happens to $a?
>
> You can as an extra option give your instance object a different name, you
> seperate that from the rest of the args with a :
>
> 2) What is an "invocant"?  Does it mean I can access it
> by placing it after something with a dot?  Sort of
> like
>  contains("abc", "b")
>  "abc".contians("b")
>
> The incovant is the object you invoke the method on. It's the thing that
> gets assigned to self, $ (and whatever else you want to call it)
>
> 3) What makes the "invocant" special over the other second
> and third parameters?
>
> See about
>
>  > class Foo {
>
> 4) I see no class called "Foo" over on
> https://docs.perl6.org/type.html
>
> That's a class being defined for this example
>
> 5) Are they creating a new class?  If so, why?
>
> To make an example
>
>  >method whoami($me:) {
>
> 6) where is @b and %c?
>
> In this case thet aren't being passed.
>
>
>  >"Well I'm class $me.^name(), of course!"
>
> 7) why is there a caret in front of "name"?
>
> There are certain Meta Object methods that are access with a ^ infront of
> the name. I'd need to check the exact definition though.
>
> Please note the Perl5 docs have had decades of people working on them the
> Perl6 ones less so. There's bound to be some difference in scope.
>
> On Tue, 11 Sep 2018 at 12:11 ToddAndMargo  wrote:
>
>> On 09/11/2018 03:30 AM, JJ Merelo wrote:
>> > Also, "is no help whatsoever" is no help whatsoever. Saying what part
>> of
>> > it is not clear enough, or could be explained better, is.
>> >
>>
>> Well now,
>>
>>  >  method ($a: @b, %c) {};   # first argument is the invocant
>>
>> 1) why is it a "method" and not a "function"?
>>
>> 1-1/2) why is there a color after a$?  What happens to $a?
>>
>> 2) What is an "invocant"?  Does it mean I can access it
>> by placing it after something with a dot?  Sort of
>> like
>>  contains("abc", "b")
>>  "abc".contians("b")
>>
>> 3) What makes the "invocant" special over the other second
>> and third parameters?
>>
>>  > class Foo {
>>
>> 4) I see no class called "Foo" over on
>> https://docs.perl6.org/type.html
>>
>> 5) Are they creating a new class?  If so, why?
>>
>>  >method whoami($me:) {
>>
>> 6) where is @b and %c?
>>
>>  >"Well I'm class $me.^name(), of course!"
>>
>> 7) why is there a caret in front of "name"?
>>
>>  >}
>>  >  }
>>  >
>>  >
>>  >  say Foo.whoami; # OUTPUT: «Well I'm class Foo, of course!␤»
>>
>> 8) no clue how they got there
>>
>>
>> JJ, have you ever used Perl 5's perldocs?  They are a bazillion
>> times easier to understand than Perl 6's.
>>
>> Thank you for the help with this?
>>
>> -T
>>
> --
> Simon Proctor
> Cognoscite aliquid novum cotidie
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Re: Please explain this to me

2018-09-11 Thread Simon Proctor
 1) why is it a "method" and not a "function"?

methods are all on instance of a Class (or Role) they can locally access
the instances data via self or $ or ... see below.

1-1/2) why is there a color after a$?  What happens to $a?

You can as an extra option give your instance object a different name, you
seperate that from the rest of the args with a :

2) What is an "invocant"?  Does it mean I can access it
by placing it after something with a dot?  Sort of
like
 contains("abc", "b")
 "abc".contians("b")

The incovant is the object you invoke the method on. It's the thing that
gets assigned to self, $ (and whatever else you want to call it)

3) What makes the "invocant" special over the other second
and third parameters?

See about

 > class Foo {

4) I see no class called "Foo" over on
https://docs.perl6.org/type.html

That's a class being defined for this example

5) Are they creating a new class?  If so, why?

To make an example

 >method whoami($me:) {

6) where is @b and %c?

In this case thet aren't being passed.


 >"Well I'm class $me.^name(), of course!"

7) why is there a caret in front of "name"?

There are certain Meta Object methods that are access with a ^ infront of
the name. I'd need to check the exact definition though.

Please note the Perl5 docs have had decades of people working on them the
Perl6 ones less so. There's bound to be some difference in scope.

On Tue, 11 Sep 2018 at 12:11 ToddAndMargo  wrote:

> On 09/11/2018 03:30 AM, JJ Merelo wrote:
> > Also, "is no help whatsoever" is no help whatsoever. Saying what part of
> > it is not clear enough, or could be explained better, is.
> >
>
> Well now,
>
>  >  method ($a: @b, %c) {};   # first argument is the invocant
>
> 1) why is it a "method" and not a "function"?
>
> 1-1/2) why is there a color after a$?  What happens to $a?
>
> 2) What is an "invocant"?  Does it mean I can access it
> by placing it after something with a dot?  Sort of
> like
>  contains("abc", "b")
>  "abc".contians("b")
>
> 3) What makes the "invocant" special over the other second
> and third parameters?
>
>  > class Foo {
>
> 4) I see no class called "Foo" over on
> https://docs.perl6.org/type.html
>
> 5) Are they creating a new class?  If so, why?
>
>  >method whoami($me:) {
>
> 6) where is @b and %c?
>
>  >"Well I'm class $me.^name(), of course!"
>
> 7) why is there a caret in front of "name"?
>
>  >}
>  >  }
>  >
>  >
>  >  say Foo.whoami; # OUTPUT: «Well I'm class Foo, of course!␤»
>
> 8) no clue how they got there
>
>
> JJ, have you ever used Perl 5's perldocs?  They are a bazillion
> times easier to understand than Perl 6's.
>
> Thank you for the help with this?
>
> -T
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Re: A comparison between P5 docs and p6 docs

2018-09-11 Thread Tom Browder
Todd, some free advice:

1. DOCUMENTATION

The docs are a volunteer effort. You can help by contributing changes
and submitting issues.

Try to use the docs first instead of using an internet search.  That
will help you submit issues if you don't find what you are looking
for.

You really need to buy one of the fine Perl 6 books that are
available.  See the perl6.org webite and this page:

  https://perl6.org/resources/https://perl6.org/resources/ (look at
the bottom left-hand side)

See this page for book choice help:  https://perl6book.com/

Anyone on the #perl6 IRC (or this mailing list) will be happy to
explain their preferences.

2. DESIGN

The original Perl 6 specifications are here (linked from the
bottom-right of perl6.org):

  https://design.perl6.org/

The specifications are defined in the test suite (also linked from the
bottom-right of per6.org):

  https://github.com/perl6/roast

3. YOUR CODE USE

One of the great features of Perl 6, to me, is the ability to use kebab
case, e.g.,:

  my $some-var = 'a';

When you submit code examples, making them less wordy and "noisy"
would help us help you. Perl 6 code can be be written very sparsely.

Best regards,

-Tom


A comparison between P5 docs and p6 docs

2018-09-11 Thread ToddAndMargo

Hi All,

Not to beat a dead horse, but Perl 6's docs are
miserably hard to understand.

Here is a comparison of Perl 5's perldocs and Perl 6's
docs:

Perl 5:

$ perldoc -f index
index STR,SUBSTR,POSITION
index STR,SUBSTR
   The index function searches for one string within another,
   but without the wildcard-like behavior of a full regular-
   expression pattern match. It returns the position of
   the first occurrence of SUBSTR in STR at or after POSITION.
   If POSITION is omitted, starts searching from the beginning
   of the string. POSITION before the beginning of the string
   or after its end is treated as if it were the beginning
   or the end, respectively. POSITION and the return value
   are based at zero. If the substring is not found, "index"
   returns -1.

Perl 6:

https://docs.perl6.org/routine/index

Documentation for sub index assembled from the following types:
class Cool

From Cool
(Cool) routine index

Defined as:

multi subindex(Str(Cool) $s, Str:D $needle, Int(Cool) $startpos 
= 0 --> Int)

multi method index(Str(Cool) $needle, Int(Cool) $startpos = 0 --> Int)

Coerces the first two arguments (in method form, also counting
the invocant) to Str, and searches for $needle in the string
starting from $startpos. It returns the offset into the string
where $needle was found, and an undefined value if it was not
found.

See the documentation in type Str for examples.


"Cources"??? Seriously:

https://www.merriam-webster.com/dictionary/coerce
Definition of coerce coerced; coercing
   transitive verb
   1 : to compel to an act or choice
   was coerced into agreeing
   abusers who coerce their victims into silence

   2 : to achieve by force or threat
   coerce compliance
   coerce obedience

   3 : to restrain or dominate by force

And what the heck is a "multi sub" and a "multi method" anyway?
AND WHY DO I EVEN CARE?  I just what to know how to use the
stinking thing!  Geepers Creapers !!!  (I am trying to avoid
swearing.)

Perl 5's perldoc just tells you what you need to know to use the
stinker.  It is concise and to the point.  Perl 6 is a nightmare
to understand.

Thank for putting up with my frustration.

-T


Re: Please explain this to me

2018-09-11 Thread ToddAndMargo

On 09/11/2018 03:30 AM, JJ Merelo wrote:
Also, "is no help whatsoever" is no help whatsoever. Saying what part of 
it is not clear enough, or could be explained better, is.




Well now,

>  method ($a: @b, %c) {};   # first argument is the invocant

1) why is it a "method" and not a "function"?

1-1/2) why is there a color after a$?  What happens to $a?

2) What is an "invocant"?  Does it mean I can access it
   by placing it after something with a dot?  Sort of
   like
contains("abc", "b")
"abc".contians("b")

3) What makes the "invocant" special over the other second
   and third parameters?

> class Foo {

4) I see no class called "Foo" over on
   https://docs.perl6.org/type.html

5) Are they creating a new class?  If so, why?

>method whoami($me:) {

6) where is @b and %c?

>"Well I'm class $me.^name(), of course!"

7) why is there a caret in front of "name"?

>}
>  }
>
>
>  say Foo.whoami; # OUTPUT: «Well I'm class Foo, of course!␤»

8) no clue how they got there


JJ, have you ever used Perl 5's perldocs?  They are a bazillion
times easier to understand than Perl 6's.

Thank you for the help with this?

-T


Re: Please explain this to me

2018-09-11 Thread Timo Paulssen
On 11/09/18 12:50, ToddAndMargo wrote:
> On 09/11/2018 03:09 AM, ToddAndMargo wrote:
>> multi method contains(Str:D: Cool:D $needle, Int(Cool:D) $pos)
>
> What the heck (not my exact word) is "multi method"?
>
> What is wrong with calling it a "function"?

Multi Methods are methods that do "multiple dispatch", which means more
or less "there are different candidates that can be called, and it
depends on the arguments you pass. They are matched against the
signatures of the candidates and the most appropriate one is called for
you".

Here's an example:

class TestClass {
    multi method test-method(Str $input) {
        say "this version of test-method is for strings";
    }

    multi method test-method(Int $input) {
        say "this version of test-method is for integers"
    }
}

my $tc = TestClass.new;
$tc.test-method("hello");
$tc.test-method(1234);

So you have the same name, but multiple candidates that have different
signatures.

Does that help?
  - Timo


Re: Please explain this to me

2018-09-11 Thread ToddAndMargo

On 09/11/2018 03:09 AM, ToddAndMargo wrote:

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


What the heck (not my exact word) is "multi method"?

What is wrong with calling it a "function"?


Functions and subroutines?

2018-09-11 Thread ToddAndMargo

Hi All,

I use subs like ducks use water.  It is about time
I learned what to properly call them.

I come from Modula2 and Pascal (as well as bash), "functions"
return a value outside the declared parameters and "(sub)routines"
only can modify values through the declarations parameters.

Sort of like
function:   sub add($a, $b){return $a+$b}
routine:sub add($a, $b, rw $c){$c = $a+$b}

In Perl, what is the proper terminology?

Many thanks,
-T

I no longer use "rw $c".  I always use "return".
The guys told me this was the best way on the
chat line, so I adopted it.


Re: Please explain this to me

2018-09-11 Thread Timo Paulssen
On 11/09/18 12:38, Curt Tilmes wrote:
>
> On Tue, Sep 11, 2018 at 6:27 AM ToddAndMargo  > wrote:
>
> method ($a: @b, %c) {};       # first argument is the invocant
>
>
> I might say rather that $a is a parameter for the invocant.  The @b
> parameter holds all the positional arguments, %c holds the named
> arguments.

Just a little correction, @b and %c would contain the positionals and
nameds only if they have a * in front. In the example here they are both
just a single positional argument. I would claim this is misleading,
though, since "first an @ parameter, then a % parameter" is so often the
pattern for "take all positionals and all nameds" (in which case they
would each have a * in front), but here that's not the case.


Re: Please explain this to me

2018-09-11 Thread Curt Tilmes
On Tue, Sep 11, 2018 at 6:27 AM ToddAndMargo  wrote:

> method ($a: @b, %c) {};   # first argument is the invocant
>

I might say rather that $a is a parameter for the invocant.  The @b
parameter holds all the positional arguments, %c holds the named arguments.


> class Foo {
>  method whoami($me:) {
>  "Well I'm class $me.^name(), of course!"
>  }
> }
> say Foo.whoami; # OUTPUT: «Well I'm class Foo, of course!␤»
>
> is no help whatsoever.
>

Since $me is in front of the ':' in the signature, it is saying you want a
parameter to refer explicitly to the invocant.

In "Foo.whoami", "Foo" is the invocant, the thing on which the method is
executed.  The signature asks for it to
be passed in as "$me".


Re: Please explain this to me

2018-09-11 Thread JJ Merelo
El mar., 11 sept. 2018 a las 12:26, ToddAndMargo ()
escribió:

> On 09/11/2018 03:22 AM, Timo Paulssen wrote:
> > On 11/09/18 12:18, JJ Merelo wrote:
> >>
> >>
> >> El mar., 11 sept. 2018 a las 12:15, Timo Paulssen ( >> >) escribió:
> >>
> >> The colon at the end of "Str:D:" signifies that it's a type
> >> constraint on what you call the method on. For example:
> >>
> >>
> >> That, of course, is also in the documentation:
> >> https://docs.perl6.org/type/Signature#index-entry-type_constraint_%3AD
> >> (maybe not with the same words, and maybe it can be improved, but still)
> >>
> >> You just have to type :D in the search slot.
> >>
> >> JJ
> >>
> >
> > I believe you linked to the wrong section,
> > https://docs.perl6.org/type/Signature#Parameter_separators is where the
> > colon at the end is explained.
> >
> > Though you cannot search for :D: and get to somewhere that explains it,
> > and searching for :D:, which is a very common usage for the invocant
> > colon, doesn't lead you to this section, either.
> >-Timo
>
> Hi Timo,
>
> method ($a: @b, %c) {};   # first argument is the invocant
>
> class Foo {
>  method whoami($me:) {
>  "Well I'm class $me.^name(), of course!"
>  }
> }
> say Foo.whoami; # OUTPUT: «Well I'm class Foo, of course!␤»
>
> is no help whatsoever.
>
> Would you please explain it to me?


That's literally part of the documentation. If you want not only get help
yourself, but help others who come after you, the best thing is to ask that
question as an issue in the documentation repository, where we'll try our
best to help you.
Also, "is no help whatsoever" is no help whatsoever. Saying what part of it
is not clear enough, or could be explained better, is.

Cheers

JJ


Re: Please explain this to me

2018-09-11 Thread ToddAndMargo

On 09/11/2018 03:22 AM, Timo Paulssen wrote:

On 11/09/18 12:18, JJ Merelo wrote:



El mar., 11 sept. 2018 a las 12:15, Timo Paulssen (>) escribió:


The colon at the end of "Str:D:" signifies that it's a type
constraint on what you call the method on. For example:


That, of course, is also in the documentation: 
https://docs.perl6.org/type/Signature#index-entry-type_constraint_%3AD 
(maybe not with the same words, and maybe it can be improved, but still)


You just have to type :D in the search slot.

JJ



I believe you linked to the wrong section, 
https://docs.perl6.org/type/Signature#Parameter_separators is where the 
colon at the end is explained.


Though you cannot search for :D: and get to somewhere that explains it, 
and searching for :D:, which is a very common usage for the invocant 
colon, doesn't lead you to this section, either.

   -Timo


Hi Timo,

method ($a: @b, %c) {};   # first argument is the invocant

class Foo {
method whoami($me:) {
"Well I'm class $me.^name(), of course!"
}
}
say Foo.whoami; # OUTPUT: «Well I'm class Foo, of course!␤»

is no help whatsoever.

Would you please explain it to me?

-T


Re: Please explain this to me

2018-09-11 Thread ToddAndMargo

On 09/11/2018 03:14 AM, Timo Paulssen wrote:
The colon at the end of "Str:D:" signifies that it's a type constraint 
on what you call the method on. For example:


my Str $foo;
$foo.contains("hello", 0);

won't work because $foo is currently not defined, i.e. doesn't pass the 
:D constraint. The : at the end means that the constraint "Str:D" 
applies to what's before the method call, in this case $foo.


In this signature, the needle is not optional, and it doesn't make sense 
to me to have it optional. What would it mean to ask if a string 
contains, but not what it's supposed to contain?


Without having to look at the docs, I would expect $pos to mean the 
position in the string that should be checked for presence of the needle 
(as in: find a needle in a haystack).


The return value isn't shown in this definition, but I'd say that's an 
oversight that should be fixed.


I hope that helps!
   - Timo


On 11/09/18 12:09, ToddAndMargo wrote:

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

Okay, I know that
   Str is a string
   Cool is an object that can be treated as both a string and a number
   $needle is the second optional parameter

What is "D"?

$needle is optional, why is it not stated as "$needle?"

How is both Str:D: and Cool:D the first parameter?

Why does "Str:D:" have a colon on the end and "Cool:D" does not?

What is Int(Cool:D) ?

What is $pos ?

Where is it stated that it has a return a value?

Where is it state that the return value is a boolean?

Yours in confusion,
-T





A little bit.  Thank you!  I will have to read it over several times.
Thank you.

As I understand it $needle? is the second optional parameter
and it is an integer, not "Cool" (both a string and a number).

I presume "Cool" includes real numbers too.


I have no idea how they got from

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

to

$ p6 'say "abc".contains("b");'
True

Perl 6's function reference has got to be the hardest
to understand I have ever come across.  Perl 5's
"perldocs -v" were a bazillion times easier to understand.

-T


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


Re: Please explain this to me

2018-09-11 Thread Timo Paulssen
On 11/09/18 12:18, JJ Merelo wrote:
>
>
> El mar., 11 sept. 2018 a las 12:15, Timo Paulssen ( >) escribió:
>
> The colon at the end of "Str:D:" signifies that it's a type
> constraint on what you call the method on. For example:
>
>
> That, of course, is also in the documentation:
> https://docs.perl6.org/type/Signature#index-entry-type_constraint_%3AD
> (maybe not with the same words, and maybe it can be improved, but still)
>
> You just have to type :D in the search slot.
>
> JJ
>

I believe you linked to the wrong section,
https://docs.perl6.org/type/Signature#Parameter_separators is where the
colon at the end is explained.

Though you cannot search for :D: and get to somewhere that explains it,
and searching for :D:, which is a very common usage for the invocant
colon, doesn't lead you to this section, either.
  -Timo


Re: Please explain this to me

2018-09-11 Thread JJ Merelo
El mar., 11 sept. 2018 a las 12:15, Timo Paulssen ()
escribió:

> The colon at the end of "Str:D:" signifies that it's a type constraint on
> what you call the method on. For example:
>

That, of course, is also in the documentation:
https://docs.perl6.org/type/Signature#index-entry-type_constraint_%3AD
(maybe not with the same words, and maybe it can be improved, but still)

You just have to type :D in the search slot.

JJ


Re: how do I do this index in p6?

2018-09-11 Thread ToddAndMargo

On 09/11/2018 03:11 AM, Simon Proctor wrote:

Why not use contains though?


Because I am torturing myself.  I am trying to learn what
all this does.

I love contains, start-with, and ends with.  I need
to learn this other stuff too.


Re: how do I do this index in p6?

2018-09-11 Thread Simon Proctor
Why not use contains though?

perl6 -e 'say "abc".contains("z")'
False

Use index if the index is important. Use contains if you just want to know
if it's there.


On Tue, 11 Sep 2018 at 10:57 JJ Merelo  wrote:

> perl6 -e 'say "abc".index("z") =:= Nil  ?? "False" !! "True"'
>
> -e runs the script from the CL
> https://github.com/rakudo/rakudo/wiki/Running-rakudo-from-the-command-line
> "abc" is on front (but it could be in the same way)
> index return Nil if it does not found (more logical than -1)
> https://docs.perl6.org/routine/index; it's a constant, so you have to use
> =:= to check for equality. https://docs.perl6.org/routine/=:=
> ??!! is the ternary operator in Perl 6
> https://docs.perl6.org/language/operators#index-entry-operator_ternary-ternary_operator
>
>
> JJ
> PS: ObStackOverflow plug.
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Please explain this to me

2018-09-11 Thread ToddAndMargo

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

Okay, I know that
   Str is a string
   Cool is an object that can be treated as both a string and a number
   $needle is the second optional parameter

What is "D"?

$needle is optional, why is it not stated as "$needle?"

How is both Str:D: and Cool:D the first parameter?

Why does "Str:D:" have a colon on the end and "Cool:D" does not?

What is Int(Cool:D) ?

What is $pos ?

Where is it stated that it has a return a value?

Where is it state that the return value is a boolean?

Yours in confusion,
-T


Re: how do I do this index in p6?

2018-09-11 Thread JJ Merelo
perl6 -e 'say "abc".index("z") =:= Nil  ?? "False" !! "True"'

-e runs the script from the CL
https://github.com/rakudo/rakudo/wiki/Running-rakudo-from-the-command-line
"abc" is on front (but it could be in the same way)
index return Nil if it does not found (more logical than -1)
https://docs.perl6.org/routine/index; it's a constant, so you have to use
=:= to check for equality. https://docs.perl6.org/routine/=:=
??!! is the ternary operator in Perl 6
https://docs.perl6.org/language/operators#index-entry-operator_ternary-ternary_operator


JJ
PS: ObStackOverflow plug.


Re: Perl 6 Design specification?

2018-09-11 Thread JJ Merelo
> Hi JJ,
>
> Yes it helps a bunch.  Thank you!
>
> Follow up: where would I find the design specifications for the functions?


There's a search engine in design.perl.org, they should all be there. If
you want to see how they work, use the search facility in the Roast repo.
If you want to see how they are defined, use the search facility in the
Rakudo repo.

Cheers

JJ


Re: Perl 6 Design specification?

2018-09-11 Thread ToddAndMargo

On 09/11/2018 01:13 AM, JJ Merelo wrote:
Short answer: if you look up "perl 6 design specification" in any search 
engine (Google or Baidu) the 3-4 first results make sense.

Long answer: it's a bit more complicated than that.
First, there's the synopsis: (first result in Baidu) 
http://design.perl6.org/ Those are the initial guidelines that specify 
the language, the core modules, and the behavior of everything. That's 
the starting point.
Then, there's roast: https://github.com/perl6/roast Roast is rather 
ROAST, "Repository of All Spec Tests". Those are the tests that a 
compiler or interpreter must pass if it wants to be called Perl 6. So 
far, only Rakudo passes those tests.
And then, of course, there's Rakudo. There are some user-accessible 
classes and modules that you can use, but they are not part of the 
language itself, only part of the only language compiler existing for 
the time being.


Hope this helps

JJ

El mar., 11 sept. 2018 a las 10:04, ToddAndMargo (>) escribió:


Hi All,

Is the Perl 6 design specification (the one the developers use)
out there somewhere on the web that I could look at?

Many thanks,
-T



--
JJ


Hi JJ,

Yes it helps a bunch.  Thank you!

Follow up: where would I find the design specifications for the functions?

-T

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


how do I do this index in p6?

2018-09-11 Thread ToddAndMargo

Hi All,

How do I clean this up for use with Perl 6?

$ perl -E 'say index("abc", "z") == -1 ? "False" : "True"'
False

Many thanks,
-T


--

Yesterday it worked.
Today it is not working.
Windows is like that.



Re: Perl 6 Design specification?

2018-09-11 Thread JJ Merelo
Short answer: if you look up "perl 6 design specification" in any search
engine (Google or Baidu) the 3-4 first results make sense.
Long answer: it's a bit more complicated than that.
First, there's the synopsis: (first result in Baidu)
http://design.perl6.org/ Those are the initial guidelines that specify the
language, the core modules, and the behavior of everything. That's the
starting point.
Then, there's roast: https://github.com/perl6/roast Roast is rather ROAST,
"Repository of All Spec Tests". Those are the tests that a compiler or
interpreter must pass if it wants to be called Perl 6. So far, only Rakudo
passes those tests.
And then, of course, there's Rakudo. There are some user-accessible classes
and modules that you can use, but they are not part of the language itself,
only part of the only language compiler existing for the time being.

Hope this helps

JJ

El mar., 11 sept. 2018 a las 10:04, ToddAndMargo ()
escribió:

> Hi All,
>
> Is the Perl 6 design specification (the one the developers use)
> out there somewhere on the web that I could look at?
>
> Many thanks,
> -T
>


-- 
JJ


Perl 6 Design specification?

2018-09-11 Thread ToddAndMargo

Hi All,

Is the Perl 6 design specification (the one the developers use)
out there somewhere on the web that I could look at?

Many thanks,
-T