Re: I need help understanding ".contains" method construction

2020-12-28 Thread ToddAndMargo via perl6-users

On 12/28/20 7:11 AM, Parrot Raiser wrote:

"Definition of invoke

 transitive verb
1a : to petition for help or support
b  : to appeal to or cite as authority
2  : to call forth by incantation : conjure
3  : to make an earnest request for : solicit
4  : to put into effect or operation : implement
5  : bring about, cause"

2,3,4 and possibly even #5 relate to methods.

Simply referring to a method by name, like .rand invokes it directly.
Giving it a value (24.cos) is closer to #3 ("please give me this
value"), and it doesn't matter whether that's a literal or generated
from a variable of some sort.

" invocantn. One who calls upon or invokes."

It could be argued that the calling program is the invocant, but if a
process snoozes until something arrives in its in-box, then does an
action in response, it's a reasonable extension to call the
"something" an invocant. Think of dropping a coin into a soft-drink
machine; the coin invokes the can, even if the former owner of the
coin started the process.


Hi Parrot,

I feel a bit guilty as you put so much work and
thought into your response.  I still don't know
what you mean.

$A = 24.cos;
$B = .rand;

Who is invoking?  The "=" sign?  The "24"?
The ".cos" or ".rand"?  Or all of them.

I really do prefer the term "call".

Please do no feel frustrated though, in my Perl 5
days, I could never tell if I was being hosed
when I got told "it's lexiconical".  At least
"invokant" is a real word.

-T


Re: I need help understanding ".contains" method construction

2020-12-28 Thread Parrot Raiser
"Definition of invoke

transitive verb
   1a : to petition for help or support
   b  : to appeal to or cite as authority
   2  : to call forth by incantation : conjure
   3  : to make an earnest request for : solicit
   4  : to put into effect or operation : implement
   5  : bring about, cause"

2,3,4 and possibly even #5 relate to methods.

Simply referring to a method by name, like .rand invokes it directly.
Giving it a value (24.cos) is closer to #3 ("please give me this
value"), and it doesn't matter whether that's a literal or generated
from a variable of some sort.

" invocantn. One who calls upon or invokes."

It could be argued that the calling program is the invocant, but if a
process snoozes until something arrives in its in-box, then does an
action in response, it's a reasonable extension to call the
"something" an invocant. Think of dropping a coin into a soft-drink
machine; the coin invokes the can, even if the former owner of the
coin started the process.


On 12/28/20, ToddAndMargo via perl6-users  wrote:
> On 12/26/20 2:50 PM, Ralph Mellor wrote:
>>> Is this .self with a better name?
>> No.
>>
>> I know you've been progressing in your understanding of
>> OO in general, and Raku's in particular, since you wrote
>> this email. So I won't explain it for now, but rather just try
>> to confirm you now know what that bit of code is doing.
>>
>> So, would you say you now understand that `.value` is a
>> method call on an "invocant" that is either explicitly written
>> to the left of the `.` or is implicitly whatever the current topic
>> is where the `.value` appears?
>
> No idea since you hinted to a newbie like myself.
>
> I do know that .value comes from the class definition
>
> https://github.com/rakudo/rakudo/blob/5df809e29cd2e7ae496a33013b27d2f7b52c7f7d/src/Perl6/bootstrap.c/BOOTSTRAP.nqp#L3427
>
> 3427: Str.HOW.add_attribute(Str, BOOTSTRAPATTR.new(:name<$!value>,
> :type(str), :box_target(1), :package(Str)));
>
> And I would not say it was a method call.  I would say
> it is a "class" from
>
> https://github.com/rakudo/rakudo/blob/5df809e29cd2e7ae496a33013b27d2f7b52c7f7d/src/Perl6/bootstrap.c/BOOTSTRAP.nqp#L19
>
> 19: my class BOOTSTRAPATTR {
>
>
> So I still find the word "invocant" a bit bizarre.
>
>  https://www.merriam-webster.com/dictionary/invocant
>  Definition of invocant
> : one that invokes
>
>  https://www.merriam-webster.com/dictionary/invokes
>  Definition of invoke
>
>  transitive verb
> 1a : to petition for help or support
> b  : to appeal to or cite as authority
> 2  : to call forth by incantation : conjure
> 3  : to make an earnest request for : solicit
> 4  : to put into effect or operation : implement
> 5  : bring about, cause
>
> So from "context", what I pick up is that
>
>1. it is an awful term to have used
>
>2. that
>  24.cos
>   either the 24 appeals/requests to cos to do something
>   making the 24 the invocant,
>or
>   .cos is the invocant and takes the 24 and appeals to
>   the code inside the method to "bring about" something.
>   The 24 may or may not be needed for the appeal, as
>   in ".rand"
>
> So it is better to just tell me and not hint around.
> I do appreciate your efforts a lot though.  Who
> "executes what" who be a better tactic.
>
> -T
>
>
>
>


Re: I need help understanding ".contains" method construction

2020-12-27 Thread ToddAndMargo via perl6-users

On 12/26/20 2:50 PM, Ralph Mellor wrote:

Is this .self with a better name?

No.

I know you've been progressing in your understanding of
OO in general, and Raku's in particular, since you wrote
this email. So I won't explain it for now, but rather just try
to confirm you now know what that bit of code is doing.

So, would you say you now understand that `.value` is a
method call on an "invocant" that is either explicitly written
to the left of the `.` or is implicitly whatever the current topic
is where the `.value` appears?


No idea since you hinted to a newbie like myself.

I do know that .value comes from the class definition

https://github.com/rakudo/rakudo/blob/5df809e29cd2e7ae496a33013b27d2f7b52c7f7d/src/Perl6/bootstrap.c/BOOTSTRAP.nqp#L3427

3427: Str.HOW.add_attribute(Str, BOOTSTRAPATTR.new(:name<$!value>, 
:type(str), :box_target(1), :package(Str)));


And I would not say it was a method call.  I would say
it is a "class" from

https://github.com/rakudo/rakudo/blob/5df809e29cd2e7ae496a33013b27d2f7b52c7f7d/src/Perl6/bootstrap.c/BOOTSTRAP.nqp#L19

19: my class BOOTSTRAPATTR {


So I still find the word "invocant" a bit bizarre.

https://www.merriam-webster.com/dictionary/invocant
Definition of invocant
   : one that invokes

https://www.merriam-webster.com/dictionary/invokes
Definition of invoke

transitive verb
   1a : to petition for help or support
   b  : to appeal to or cite as authority
   2  : to call forth by incantation : conjure
   3  : to make an earnest request for : solicit
   4  : to put into effect or operation : implement
   5  : bring about, cause

So from "context", what I pick up is that

  1. it is an awful term to have used

  2. that
24.cos
 either the 24 appeals/requests to cos to do something
 making the 24 the invocant,
  or
 .cos is the invocant and takes the 24 and appeals to
 the code inside the method to "bring about" something.
 The 24 may or may not be needed for the appeal, as
 in ".rand"

So it is better to just tell me and not hint around.
I do appreciate your efforts a lot though.  Who
"executes what" who be a better tactic.

-T





Re: I need help understanding ".contains" method construction

2020-12-27 Thread ToddAndMargo via perl6-users

On 12/19/20 11:04 PM, ToddAndMargo via perl6-users wrote:

Hi All,

https://github.com/rakudo/rakudo/blob/master/src/core.c/Str.pm6

337:multi method contains(Str:D: Str:D $needle --> Bool:D) {

338:nqp::hllbool(nqp::isne_i(nqp::index($!value,$needle,0),-1))
339:}

I "presume" in

  "abcd".contains("bc")

"abcd" is `$!value`, and

"bc" is $needle.  Do I presume correctly?


Questions:


Follow up:

I am going to answer my own question here. I may
have errors in it, so take it with a grain of salt.

https://github.com/rakudo/rakudo/blob/master/src/core.c/Str.pm6


337:multi method contains(Str:D: Str:D $needle --> Bool:D) {
338:nqp::hllbool(nqp::isne_i(nqp::index($!value,$needle,0),-1))
339:}




1) why is it "$needle" and not "$!needle" on line 338?
    Is this because it is an internal variable and not
    a variable from the class declaration?


It is $needle" because it is a declared parameter passed to
the method ("Str:D $needle" is teh second parameters
on the defination line.)

337:  multi method contains(Str:D: Str:D $needle --> Bool:D)

The funny stuff happens when it is part of class structure



2) where is variable ".value" defined on line 338?
    What kind of variable is .value?




.value is part of a class structure.  It is defined:

https://github.com/rakudo/rakudo/blob/5df809e29cd2e7ae496a33013b27d2f7b52c7f7d/src/Perl6/bootstrap.c/BOOTSTRAP.nqp#L3427

3427: Str.HOW.add_attribute(Str, BOOTSTRAPATTR.new(:name<$!value>, 
:type(str), :box_target(1), :package(Str)));


and BOOTSTRAPATTR is defined:

https://github.com/rakudo/rakudo/blob/5df809e29cd2e7ae496a33013b27d2f7b52c7f7d/src/Perl6/bootstrap.c/BOOTSTRAP.nqp#L19

19: my class BOOTSTRAPATTR {
has $!name;
has $!type;
has $!box_target;
has $!package;
has $!inlined;
has $!dimensions;
method name() { $!name }
method type() { $!type }
method box_target() { $!box_target }
method package() { $!package }
method inlined() { $!inlined }
method dimensions() { $!dimensions }
method is_built() { 0 }
method is_bound() { 0 }
method has_accessor() { 0 }
method positional_delegate() { 0 }
method associative_delegate() { 0 }
method build() { }
method is_generic() { $!type.HOW.archetypes.generic }
method instantiate_generic($type_environment) {
my $ins := $!type.HOW.instantiate_generic($!type, 
$type_environment);

self.new(:name($!name), :box_target($!box_target), :type($ins))
}
method compose($obj, :$compiler_services) { }
method gist() { $!type.HOW.name($!type) ~ ' ' ~ $!name }
method perl() { 'BOOTSTRAPATTR.new' }
method raku() { 'BOOTSTRAPATTR.new' }
method Str()  { $!name }
48: }





3) the first "Str:D" goes to what on line 337?  To .value?


Eventually, yes


4) Is .value the default, if there is no name given?


.value comes from
BOOTSTRAPATTR.new(:name<$!value>

Gee Wiz!  This is as much fund as digging around time.h
to try and figure out what time_t is to feed NativeCall!
(it is an int64.)

Thank you all for your patience and help,
-T




Re: I need help understanding ".contains" method construction

2020-12-26 Thread Ralph Mellor
> >> What kind of variable is .value?
> >
> > I don't see a `.value`, only a `$!value`.
>
> Is this .self with a better name?

No.

I know you've been progressing in your understanding of
OO in general, and Raku's in particular, since you wrote
this email. So I won't explain it for now, but rather just try
to confirm you now know what that bit of code is doing.

So, would you say you now understand that `.value` is a
method call on an "invocant" that is either explicitly written
to the left of the `.` or is implicitly whatever the current topic
is where the `.value` appears?

> >> 3) the first "Str:D" goes to what on line 337?  To .value?
> >
> > No, to the invocant.
>
> Would you define "invocant" so I stop guessing?

Would you say you now understand what "invocant" means?

love, raiph


Re: I need help understanding ".contains" method construction

2020-12-23 Thread Todd Chester via perl6-users



On 12/23/20 4:39 PM, Ralph Mellor wrote:

1) why is it "$needle" and not "$!needle" on line 338?
Is this because it is an internal variable and not
a variable from the class declaration?


Got it



It's a parameter from line 337. If that's what you mean by
"an internal variable", then yes. :)


Apparently some other programming language do not give your
the option of internal variables in side class declarations:
everything is visable




2) where is variable ".value" defined on line 338?
What kind of variable is .value?


I don't see a `.value`, only a `$!value`. But if I did, and had that
sort of name, it would typically be a method call that returns an
attribute of the same name -- like `$!value`.


Is this .self with a better name?




3) the first "Str:D" goes to what on line 337?  To .value?


No, to the invocant.


Would you define "invocant" so I stop guessing?




4) Is .value the default, if there is no name given?


I don't see a `.value`, nor what you mean by "name".


Re: I need help understanding ".contains" method construction

2020-12-23 Thread Ralph Mellor
>1) why is it "$needle" and not "$!needle" on line 338?
>Is this because it is an internal variable and not
>a variable from the class declaration?

It's a parameter from line 337. If that's what you mean by
"an internal variable", then yes. :)

>2) where is variable ".value" defined on line 338?
>What kind of variable is .value?

I don't see a `.value`, only a `$!value`. But if I did, and had that
sort of name, it would typically be a method call that returns an
attribute of the same name -- like `$!value`.

>3) the first "Str:D" goes to what on line 337?  To .value?

No, to the invocant.

>4) Is .value the default, if there is no name given?

I don't see a `.value`, nor what you mean by "name".

On Sun, Dec 20, 2020 at 7:05 AM ToddAndMargo via perl6-users
 wrote:
>
> Hi All,
>
> https://github.com/rakudo/rakudo/blob/master/src/core.c/Str.pm6
>
> 337:multi method contains(Str:D: Str:D $needle --> Bool:D) {
>
> 338:nqp::hllbool(nqp::isne_i(nqp::index($!value,$needle,0),-1))
> 339:}
>
> I "presume" in
>
>   "abcd".contains("bc")
>
> "abcd" is `$!value`, and
>
> "bc" is $needle.  Do I presume correctly?
>
>
> Questions:
>
> 1) why is it "$needle" and not "$!needle" on line 338?
> Is this because it is an internal variable and not
> a variable from the class declaration?
>
> 2) where is variable ".value" defined on line 338?
> What kind of variable is .value?
>
> 3) the first "Str:D" goes to what on line 337?  To .value?
>
> 4) Is .value the default, if there is no name given?
>
> Many thanks,
> -T


I need help understanding ".contains" method construction

2020-12-19 Thread ToddAndMargo via perl6-users

Hi All,

https://github.com/rakudo/rakudo/blob/master/src/core.c/Str.pm6

337:multi method contains(Str:D: Str:D $needle --> Bool:D) {

338:nqp::hllbool(nqp::isne_i(nqp::index($!value,$needle,0),-1))
339:}

I "presume" in

 "abcd".contains("bc")

"abcd" is `$!value`, and

"bc" is $needle.  Do I presume correctly?


Questions:

1) why is it "$needle" and not "$!needle" on line 338?
   Is this because it is an internal variable and not
   a variable from the class declaration?

2) where is variable ".value" defined on line 338?
   What kind of variable is .value?

3) the first "Str:D" goes to what on line 337?  To .value?

4) Is .value the default, if there is no name given?

Many thanks,
-T