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


Reply via email to