Re: Please explain this to me

2018-09-16 Thread Brandon Allbery
Binding, iirc. You are binding a value directly instead of making a box to
assign it to.

On Mon, Sep 17, 2018 at 1:47 AM ToddAndMargo  wrote:

> >> On Sun, Sep 16, 2018 at 9:02 PM ToddAndMargo  >> > wrote:
> >>
> >> On 09/16/2018 05:58 PM, Curt Tilmes wrote:
> >>  > Read this:
> >>  >
> >>
> https://perl6advent.wordpress.com/2017/12/02/perl-6-sigils-variables-and-containers/
> >>  >
> >>  > Then go back and read it again.  It took me several times, and
> >> I'm still
> >>  > not sure I get it all :)
> >>
> >> I am spacing on the difference between
> >>
> >>   my $foo  = 42; and
> >>   my $foo := 42;
> >>
> >> To add insult to injury, I come from Modula2, where
> >> `:=` is `=` in Perl.
> >>
> >> -T
>
>
> On 9/16/18 9:06 PM, Brandon Allbery wrote:
> > If you say "my $foo = 42", you are saying that $x is a box, and you are
> > putting 42 into it. You can put something else into that box later.
> >
> > If you say "my $foo := 42", you are saying that $x is 42 itself, not a
> > box containing 42. You can think of it as a constant of sorts. Because
> > it's not a box, you can't change what's in the nonexistent box later.
> >
> >  From here on it gets trickier, because there are things that can use
> > the box instead of what the box contains, notably Hash elements, and
> > which can then be changed by changing what's in the box directly instead
> > of by changing the Hash element.
> >
>
> Does `:=` have an official name?
>
> So, kind of like a constant you that can sometimes change.
>
> What would be the use of such?
>
>
> $ p6 'constant t=1.414; dd t;'
> 1.414
>
> $ p6 'my $t := 1.414; dd $t;'
> 1.414
>
> $ p6 'my $t := 1.414; $t += 1; dd $t;'
> Cannot assign to an immutable value
>in block  at -e line 1
>
> $ p6 'my $t := 1.414; $t := 4.14; dd $t;'
> 4.14
>
> $ p6 'my $t := 1.414; say $t + 9;'
> 10.414
>


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


Re: Please explain this to me

2018-09-16 Thread Brad Gilbert
I think I have an idea of where your thinking is going wrong.
The trouble is going to be to describe it so that you can understand.

First, I think you may be misunderstanding what we mean by defined and
undefined.



So I will use "instance" and "class"

---

class Foo {};

say Foo;  # <- "class" value
say Foo.new(); # <- "instance" value

my $bar = Foo;   # <- "class" value
my $baz = Foo.new(); # <- "instance" value

Foo.defined.say;  # False  # <- "class" value
Foo.new().defined.say; # True  # <- "instance" value

---

In Perl 6 types are both types, and values:

You can store it as a value.

my $a = Int;

I am going to call that a "class" value.

In this example the value is of type "Int".

The "Int" ("class") value is also of type "Int".

You can even pass around "class" values with the type "smiley".

my $a = Int:D;

This is useful in the compiler.

---

If you use it as a type:

my Int $b;

You are saying that it must be an "instance" or a "class" value of that type.

The default value is the same as the type.

So that last example is the same as:

my Int $b = Int;

You can bring it back to the default by assigning a "class" value.

$b = 42;
$b = Int;

If you use a type "smiley" in the type, you constrain it further.

my Int:D $c;  # error

In this case you are saying only "instance" values are allowed.

In that last case the default value is "Int:D", which is a "class"
value, but only "instance" values are allowed by the type.

Note that again the default value is the same as the type, so it
produces an error.

---

The type/value "Nil" is special, as it changes the variable to it's default.

my Int $d is default(42);   # 42
$d = 10;# 10
$d = Nil;   # 42

In this example for it to hold a "class" value, you have to do so explicitly.

   $d = Int;   # Int

---

my Int:U $u;

The "class" values that can be stored in this variable are below

Int
Int:_ # same as previous
Int:U
Int:D

class Other-Int is Int {…}
Other-Int
Other-Int:_ # same as previous
Other-Int:U
Other-Int:D

my \foo = Int but 'Foo'
foo
foo:_ # same as previous
foo:U
foo:D

Note again that I am talking about them as values.

---

When you use a type in a declaration:

my Int $f;

You can think about it as a macro named "my" which takes two arguments.
The first one is a "class" value, and the second one is the name of
the variable.

This makes it so that you can have aliases.

constant Name = Str:D;

my Name $first-name = "Brad";

---

I think where you are going wrong is that other languages also use the
words "defined" and "undefined".

When we use them in Perl 6, we mean something slightly different.

===

You just added a question about :=

:= is the binding operator.

Normally scalar variables store a Scalar that you assign into.

Just think about this:

my $a = 0;

As being short for something like the following fake code:

(my $a := Scalar.new) = 0;

When you use :=, you are basically creating an alias:

my $b;
my $c := $b;

$c = 42;
say $b;  # 42

This also means that if you alias a value, the variable becomes readonly

my $d := 0;
$d = 0;  # error Cannot assign to an immutable value
On Sun, Sep 16, 2018 at 7:49 PM ToddAndMargo  wrote:
>
> On 09/14/2018 08:07 PM, ToddAndMargo wrote:
> > ":D"
> >  means it wants actual data in the string and not a Nil.
> >  The jargon for this requirement is that is is constrained
> >  to an actual value
> >
> >  If it wanted a Nil, it would say ":U" or constrained to
> >  a Nil
>
> Iteration 3:
>
>
> ":D"
>  means it wants the variable "Defined" (Constrained).
>  For example:
>my Str $x;
>my Int $i;
>
>  The value of the variable may be empty but the variable
>  does not become "defined" until a value is places in it.
>  ("Nil" is seen as "Undefined")
>
> ":U"
>  means the variable is "Undefined" (defaults to type "Any")
>
>  For example:
>my $x;
>my $i;
>
>
>
> $ p6 'my $x; if $x.defined {say "Defined"}else{say "Undefined"};'
> Undefined
>
> $ p6 'my Real $x; if $x.defined {say "Defined"}else{say "Undefined"};'
> Undefined
>
> $ p6 'my Real $x=3; if $x.defined {say "Defined"}else{say "Undefined"};'
> Defined
>
> $ p6 'my $x=3; if $x.defined {say "Defined"}else{say "Undefined"};'
> Defined
>
>
> $ p6 'my $x=3; dd $x'
> Int $x = 3
>
> $ p6 'my $x; dd $x'
> Any $x = Any
>
> $ p6 'my Real $x; dd $x'
> Real $x = Real
>
> $ p6 'my Real $x = 3; dd $x'
> Int $x = 3
>
> Huh ??


Re: Please explain this to me

2018-09-16 Thread ToddAndMargo
On Sun, Sep 16, 2018 at 9:02 PM ToddAndMargo > wrote:


On 09/16/2018 05:58 PM, Curt Tilmes wrote:
 > Read this:
 >

https://perl6advent.wordpress.com/2017/12/02/perl-6-sigils-variables-and-containers/
 >
 > Then go back and read it again.  It took me several times, and
I'm still
 > not sure I get it all :)

I am spacing on the difference between

  my $foo  = 42; and
  my $foo := 42;

To add insult to injury, I come from Modula2, where
`:=` is `=` in Perl.

-T



On 9/16/18 9:06 PM, Brandon Allbery wrote:
If you say "my $foo = 42", you are saying that $x is a box, and you are 
putting 42 into it. You can put something else into that box later.


If you say "my $foo := 42", you are saying that $x is 42 itself, not a 
box containing 42. You can think of it as a constant of sorts. Because 
it's not a box, you can't change what's in the nonexistent box later.


 From here on it gets trickier, because there are things that can use 
the box instead of what the box contains, notably Hash elements, and 
which can then be changed by changing what's in the box directly instead 
of by changing the Hash element.




Does `:=` have an official name?

So, kind of like a constant you that can sometimes change.

What would be the use of such?


$ p6 'constant t=1.414; dd t;'
1.414

$ p6 'my $t := 1.414; dd $t;'
1.414

$ p6 'my $t := 1.414; $t += 1; dd $t;'
Cannot assign to an immutable value
  in block  at -e line 1

$ p6 'my $t := 1.414; $t := 4.14; dd $t;'
4.14

$ p6 'my $t := 1.414; say $t + 9;'
10.414


Re: Please explain this to me

2018-09-16 Thread Brandon Allbery
If you say "my $foo = 42", you are saying that $x is a box, and you are
putting 42 into it. You can put something else into that box later.

If you say "my $foo := 42", you are saying that $x is 42 itself, not a box
containing 42. You can think of it as a constant of sorts. Because it's not
a box, you can't change what's in the nonexistent box later.

>From here on it gets trickier, because there are things that can use the
box instead of what the box contains, notably Hash elements, and which can
then be changed by changing what's in the box directly instead of by
changing the Hash element.

On Sun, Sep 16, 2018 at 9:02 PM ToddAndMargo  wrote:

> On 09/16/2018 05:58 PM, Curt Tilmes wrote:
> > Read this:
> >
> https://perl6advent.wordpress.com/2017/12/02/perl-6-sigils-variables-and-containers/
> >
> > Then go back and read it again.  It took me several times, and I'm still
> > not sure I get it all :)
>
> I am spacing on the difference between
>
>  my $foo  = 42; and
>  my $foo := 42;
>
> To add insult to injury, I come from Modula2, where
> `:=` is `=` in Perl.
>
> -T
>


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


Re: Please explain this to me

2018-09-16 Thread ToddAndMargo

On 09/16/2018 06:41 PM, ToddAndMargo wrote:

Hi Mark,

I am sorry, but books don't work for me.  Manuals do.
And correspondences do too.   That is just the way my
brain works. And, yes, I know I am weird.

-T


Videos don't work either.  When I am forced to watch
one to figure something out (Inkscape), I nearly
go insane.  And my mother would wash my mouth out
with soap.


RE: Please explain this to me

2018-09-16 Thread Mark Devine
I get it.  Different angles of approach.  Some methods don't make a dent with 
me (I.e. rote).

Mark

-Original Message-
From: ToddAndMargo  
Sent: Sunday, September 16, 2018 21:42
To: perl6-users@perl.org
Subject: Re: Please explain this to me

On 09/16/2018 06:23 PM, Mark Devine wrote:
> foy, brian d. Learning Perl 6: Keeping the Easy, Hard, and Impossible Within 
> Reach (Kindle Location 557). O'Reilly Media. Kindle Edition.
> 
> Chapter 2: Binding and Assignment: "There’s an important concept here that 
> you should learn early."  [[ what follows in the most concise and 
> understandable explanation that I have found yet to the question you raised ]]
> 
> As I'm going through Learning Perl 6, he's really done a fantastic job of 
> answering tons of the questions that I've been tracking in this mailing list. 
>  Uncanny really.  The author rolls the angles just right and I'm having 
> mini-epiphanies one after another.
> 
> So recommended...
> 
> Mark

Hi Mark,

I am sorry, but books don't work for me.  Manuals do.
And correspondences do too.   That is just the way my
brain works. And, yes, I know I am weird.

-T


RE: Please explain this to me

2018-09-16 Thread Mark Devine
foy, brian d. Learning Perl 6: Keeping the Easy, Hard, and Impossible Within 
Reach (Kindle Location 557). O'Reilly Media. Kindle Edition.

Chapter 2: Binding and Assignment: "There’s an important concept here that you 
should learn early."  [[ what follows in the most concise and understandable 
explanation that I have found yet to the question you raised ]]

As I'm going through Learning Perl 6, he's really done a fantastic job of 
answering tons of the questions that I've been tracking in this mailing list.  
Uncanny really.  The author rolls the angles just right and I'm having 
mini-epiphanies one after another.

So recommended...

Mark

-Original Message-
From: ToddAndMargo  
Sent: Sunday, September 16, 2018 21:02
To: perl6-users@perl.org
Subject: Re: Please explain this to me

On 09/16/2018 05:58 PM, Curt Tilmes wrote:
> Read this:
> https://perl6advent.wordpress.com/2017/12/02/perl-6-sigils-variables-a
> nd-containers/
> 
> Then go back and read it again.  It took me several times, and I'm 
> still not sure I get it all :)

I am spacing on the difference between

 my $foo  = 42; and
 my $foo := 42;

To add insult to injury, I come from Modula2, where `:=` is `=` in Perl.

-T


Re: Please explain this to me

2018-09-16 Thread ToddAndMargo

On 09/16/2018 05:58 PM, Curt Tilmes wrote:

Read this:
https://perl6advent.wordpress.com/2017/12/02/perl-6-sigils-variables-and-containers/

Then go back and read it again.  It took me several times, and I'm still 
not sure I get it all :)


I am spacing on the difference between

my $foo  = 42; and
my $foo := 42;

To add insult to injury, I come from Modula2, where
`:=` is `=` in Perl.

-T


Re: Please explain this to me

2018-09-16 Thread Curt Tilmes
Read this:
https://perl6advent.wordpress.com/2017/12/02/perl-6-sigils-variables-and-containers/

Then go back and read it again.  It took me several times, and I'm still
not sure I get it all :)


On Sun, Sep 16, 2018 at 8:49 PM ToddAndMargo  wrote:

> On 09/14/2018 08:07 PM, ToddAndMargo wrote:
> > ":D"
> >  means it wants actual data in the string and not a Nil.
> >  The jargon for this requirement is that is is constrained
> >  to an actual value
> >
> >  If it wanted a Nil, it would say ":U" or constrained to
> >  a Nil
>
> Iteration 3:
>
>
> ":D"
>  means it wants the variable "Defined" (Constrained).
>  For example:
>my Str $x;
>my Int $i;
>
>  The value of the variable may be empty but the variable
>  does not become "defined" until a value is places in it.
>  ("Nil" is seen as "Undefined")
>
> ":U"
>  means the variable is "Undefined" (defaults to type "Any")
>
>  For example:
>my $x;
>my $i;
>
>
>
> $ p6 'my $x; if $x.defined {say "Defined"}else{say "Undefined"};'
> Undefined
>
> $ p6 'my Real $x; if $x.defined {say "Defined"}else{say "Undefined"};'
> Undefined
>
> $ p6 'my Real $x=3; if $x.defined {say "Defined"}else{say "Undefined"};'
> Defined
>
> $ p6 'my $x=3; if $x.defined {say "Defined"}else{say "Undefined"};'
> Defined
>
>
> $ p6 'my $x=3; dd $x'
> Int $x = 3
>
> $ p6 'my $x; dd $x'
> Any $x = Any
>
> $ p6 'my Real $x; dd $x'
> Real $x = Real
>
> $ p6 'my Real $x = 3; dd $x'
> Int $x = 3
>
> Huh ??
>


Re: Please explain this to me

2018-09-16 Thread ToddAndMargo

On 09/14/2018 08:07 PM, ToddAndMargo wrote:

":D"
     means it wants actual data in the string and not a Nil.
     The jargon for this requirement is that is is constrained
     to an actual value

     If it wanted a Nil, it would say ":U" or constrained to
     a Nil


Iteration 3:


":D"
means it wants the variable "Defined" (Constrained).
For example:
  my Str $x;
  my Int $i;

The value of the variable may be empty but the variable
does not become "defined" until a value is places in it.
("Nil" is seen as "Undefined")

":U"
means the variable is "Undefined" (defaults to type "Any")

For example:
  my $x;
  my $i;



$ p6 'my $x; if $x.defined {say "Defined"}else{say "Undefined"};'
Undefined

$ p6 'my Real $x; if $x.defined {say "Defined"}else{say "Undefined"};'
Undefined

$ p6 'my Real $x=3; if $x.defined {say "Defined"}else{say "Undefined"};'
Defined

$ p6 'my $x=3; if $x.defined {say "Defined"}else{say "Undefined"};'
Defined


$ p6 'my $x=3; dd $x'
Int $x = 3

$ p6 'my $x; dd $x'
Any $x = Any

$ p6 'my Real $x; dd $x'
Real $x = Real

$ p6 'my Real $x = 3; dd $x'
Int $x = 3

Huh ??


Re: Please explain this to me

2018-09-16 Thread yary
":D"
means it wants actual data in the string and not a Nil.
The jargon for this requirement is that is is constrained
to an actual value

If it wanted a Nil, it would say ":U" or constrained to
a Nil

Think of :D as a"defined" and :U as "Undefined" - Nil is a special thing,
even though Nil is undefined, it is one of many undefined things, and Nil
has some special uses. A better match for Perl5's "undef" is "Any".

In particular, this!

> my $example is default(5); say $example
5
> $example=Any; say $example
(Any)
> say $example.defined
False
> $example=Nil; say $example
5
> say $example.defined
True

-y


Re: Please explain this to me

2018-09-14 Thread ToddAndMargo

Okay,  see if I got it right, finally:


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

"multi method"
This means there are multiple ways to address this, as in

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

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

"Str"
means it want to be fed data as a string.  Str.foo

":D"
means it wants actual data in the string and not a Nil.
The jargon for this requirement is that is is constrained
to an actual value

If it wanted a Nil, it would say ":U" or constrained to
a Nil

":"
is the delimiter that tells you it is finished defining
what is wants to be fed

"Cool:D $needle"
means it wants a type Cool (string or number) for the
substring ($needle) it is looking for in the Haystack (Str)

"Int(Cool:D)"
Means it will change a type Cool into a type Int (integer)
and the ":D" means it want some actual data and not a Nil.

"$pos"
Is short of Position.  It is the starting index in the
haystack (Str) to start looking for the substring
(needle).  Index starts at zero by way of string
convention in Perl 6

$pos is an optional parameter.  Instead of $pos?
for optional, they stated it with several "multi method"
that do not include $pos.

"-->Bool"
means it return True or False


How did I do?

Thank you all for all the help with this!

-T


Re: Please explain this to me

2018-09-14 Thread ToddAndMargo

On 09/11/2018 10:41 AM, 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.


I never used a method in p5.  When I found them in
P6, I adored them.

Methods increase readability for me a lot.


Re: Please explain this to me

2018-09-14 Thread Todd Chester




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


Is there some where I can look at these comments?


That's rather a dynamic way of not budging.


True.  I was over reacting


Re: Please explain this to me

2018-09-14 Thread Todd Chester




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


Hi Simon,

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

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

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

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


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

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

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


Re: Please explain this to me

2018-09-13 Thread Todd Chester




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


Cheers

JJ


I wrote you off list giving you my reasoning.


Re: Please explain this to me

2018-09-13 Thread Todd Chester




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

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

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

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

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

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

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

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

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

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

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

Larry




Hi Larry,

Thank you!

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

-T


Re: Please explain this to me

2018-09-13 Thread JJ Merelo
Hi,

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

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

Cheers

JJ


Re: Please explain this to me

2018-09-13 Thread Todd Chester




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


Hi Simon,

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

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

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

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

-T


Re: Please explain this to me

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

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

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

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

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

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

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

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

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

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

Larry


Re: Please explain this to me

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



On Wed, 12 Sep 2018 at 06:29 ToddAndMargo  wrote:

> 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
> ~~
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


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: 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: 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: 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"?


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 ( >> <mailto:t...@wakelift.de>>) 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 (<mailto:t...@wakelift.de>>) 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


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