develooper Front page | perl.perl6.users | Postings from December 2019

My keeper on "contains"

Thread Next
ToddAndMargo via perl6-users
December 9, 2019 01:45
My keeper on "contains"
Message ID:
Hi All,

I have 190 of these.  191 in the hopper for unicodes.
This is one of my better one.  It is also unique in
that it takes apart the IEEE-eese on the
documentation and explain what in the world is
going on.  Do you notice the ":" is sometimes a delimiter
and sometimes not.  Eee Gads!



perl 6: method:

Also: "starts-with" and "ends-with"

A method is a routine that you feed: .foo

    $ p6 'say "abc".contains( "a" );'

    $ p6 'say "abc".contains( "z" );'

    $ p6 'my $x="\na\nb\nc\n"; for $x.lines -> $i {print "<$i>\n"};'

Case insensitive contains:
     $ p6 'if "2018 Jul 7".fc.contains( "jul".fc ) {say "Yes";}'

     $ p6 'if "2018 xJul 7".fc.contains( "jul".fc ) {say "Yes";}'

     p6 'if "2018 xul 7".fc.contains( "jul".fc ) {say "Yes";}'

     $ p6 'my $x="strong>2018.2.0; Coming Soon</strong>"; say so 
$x.fc.contains("strong" & not "coming soon");'

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)

     means it want to be fed data as a string.

     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)

     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.

     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.

     means it return True or False

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About