On 2020-08-27 16:53, Daniel Long Sockwell wrote:

Very few of the other [methods are documented] this way.
This one also started with an error in the cryptogram
as well.  (That is another complaint about the
documentation.  The cryptograms are often wrong.)
And there should be zero tolerance for "insider knowledge".

This might be a bit ironic, but I can't follow what you're saying here.
What do you mean by "cryptogram"?  To me, that strikes me as _much_ more
of an esoteric term than anything in the Raku docs -- but maybe it has a
common meaning in this context that I just haven't come across (and that
a basic Internet search didn't turn up).

Here is one.

multi method starts-with(Str:D: Str(Cool) $needle, :i(:$ignorecase), :m(:$ignoremark) --> Bool:D)

This one is pretty easy to figure out.  Most of the time
though, I get the "what is the world?" thing. When
I do figure them out and they are correct, they can
actually be very helpful.

And I never remember the official name.

And "in your face example" would be one of my all time
favorite routines which is "lines".  I use "lines"
ALL-THE-TIME.

https://docs.raku.org/routine/lines

This is so fascinating to me -- you provide that as an example of poor
documentation, but *I* would look at that as an area where Raku (with
the help of its docs) just clicks perfectly into place.  Everything that
the docs explain for this and related topics fits together into a
cohesive whole, and after reading the docs, I not only see how the language
works, but am also left with the feeling that the language couldn't
possibly work any other way.

I picked "lines" on purpose as I KNOW ow it operates.
It is one sweet function, especially when I am careening through raw web pages. I as not looking for help with it.



Without any arguments, sub lines operates on $*ARGFILES, which
defaults to $*IN in the absence of any filenames.

Be careful with that one, $*IN will lop of the first line
if you are not careful.


If you're willing to post your "keepers", I bet others would enjoy
reading them as well.

Most of them are written specifically for me.  As you can
tell, I am "weird".  It would be anenormous undertaking
for me to clean most of them up.

Usually, when someone asks about a specific thing I have
a keeper on, I will (clean it up and) post it back.
Or if I am just tickled with what I came up with.

When I do, I get all my misspelling pointed out an
any booboo annotated.  It does really help enormously.

Since you are working on the documentation, feel free to
ping me to see if I have something written on the subject.
I am more than happy to have you use from it.  Or maybe
just to see what I find important about he subject.


Hope that explains it.  I ADORE Raku.  The only thing
I dislike is the documentation.

I'm glad you like Raku -- I feel the same way.  Now, I'm going to get
back to trying to improve the documentation; I've submitted two pull
requests today, and am making decent progress towards a third.  Maybe
one day, you'll like the docs as much as you like the language itself.

I have programmed in several languages in my lifetime. I have to say, Raku is just damned fun to program in! And
the community is wonderful.

-T

p.s. my favorite variable is the Associative Array (hash).
(I like put both descriptions together as it nicely describes
what a has is.)

Here is my keeper on a hash:

12/08/2019:

Perl 6 Hashes (associative arrays):


References:
    https://docs.raku.org/language/subscripts#Basics
    https://docs.raku.org/type/Hash#___top
    https://docs.raku.org/type/Hash#:exists
    https://docs.raku.org/type/Hash#method_append



A hash "associates" a Name, called a "key" to a Value, called a "value"

   You assign them as follows:

      # use whatever is easiest on the eyes
      my %h =   a => "A", b => "B";      or
      my %h = ( a => "A", b => "B" );    or
      my %h = [ a => "A", b => "B" ];
      {a => A, b => B}

      say %h.keys
      (b a)

      say %h.values
      (B A)

   Confining hashes:
   Note: as of 2020-01-15, confining only works with Str and Int.
         And you must confine the entire hash, not each member

      my Str %h = A => "a"
      {A => a}

      my Int %h = A => 123
      {A => 123}

      my int %h = A => 123
      native value types for hashes not yet implemented. Sorry.


   You read them as follows:
      $v = %h<b>
      B

      When the key is a variable, your read them as follows
         $k = "a"
         $v = %h{$k}

   You write to them as follows:
       %h<b> = "B";

       When the key is a variable, your read them as follows
         $k = "a"
         %h{$k} = $v;


   To add or delete and element, see the sections below labeled
         Adding a key/value pair:
         Deleting a key/value pair:


   Looping through a hash:
Note: hashes DO NOT loop in the order that they were entered into the hash

       for %x.kv -> $key, $value {do something};

       For example:

          my %h = a => "x", b=>"r", c=>"z";
          for %h.kv ->  $key, $value {say "key = $key  value = $value"; }
          key = c  value = z
          key = a  value = x
          key = b  value = r

   Array's of hashes:
       To access values inside and array of hashes:
             my @a; my %h = a=>"A", b=>"B"; push @a, %h;
             Access:
                 $x = @a[0]{"a"}    # Note: you need the quotes

             modify:
                 @a[0]{"b"} = "BB"

       How to use arrays of hashes:
          my @a;
          my %h1; my %h2;

          %h1 = a => 0, b => 1, c => 2;
          %h2 = a => 9, b => 8, c => 7;

          push @a, {%h1};
          push @a, {%h2};

          say @a;
          [{a => 0, b => 1, c => 2} {a => 0, b => 1, c => 2}]

          for @a.kv -> $i, $h { say "$i\n" ~ "$h\n"; };
          # Note: the ~ is to make it easier to read
          #       even though $h is address as $ it is a hash
              0
              a 0
              b 1
              c 2

              1
              a 9
              b 8
              c 7


    Checking for the presence of a key/value:

      Warning: a Gotcha:
           if using the "if" statement to check for the existence
           of a key, it will return false if it does not find the key,
           but it will also return false if it finds the key and its
           value is a numerical zero, which "if" interprets as
           a Boolean false.

       Note: "exists" is called an "adverb" in this context
          my %h = a => "x", b=>0, c=>"z";

          if %h<d>:exists { say "exists"; } else { say "DOES NOT exist"; }
          DOES NOT exist

          if %h<b>:exists { say "exists"; } else { say "DOES NOT exist"; }
          exists



   Adding a key/value pair:
       my %h = a => "x", b=>"r", c=>"z";
       %h.append( 'd',  "D" )               # note: you need the ''
       {a => x, b => r, c => z, d => D}


   Deleting a key/value pair:
   Note: "delete" is called an "adverb" in this context
       my %h = a => "x", b=>"r", c=>"z";
       %h<b>:delete; say %h
       {a => x, c => z}


   Display a key/value pair  (:p adverb):
       my %h = a => "x", b=>"r", c=>"z";
       say %h<a>:p;
       a => x
       say %h<a b>:p;   # note: no comma between the a and the b
       (a => x b => r)


   Return the key and value with the :k and :v adverbs:
       my %h = a => 1, b => 2;
       say %h<a>:k;
       a

       say %h<a b>:k;
      (a b)

      say %h<a b>:v;
      (1 2)

      Empty <> return everything:
         say %h<>:v;
         (2 1)

         say %h<>:k;
         (b a)


"returns" hash on a sub declaration:
    Note: "Associative" will return a hash or a map or even a pair
    > sub x() returns Associative { my %h= A=>"a"; return %h}
    &x
    > x
    {A => a}

    > sub x(--> Hash) { my %h= A=>"a", B=>"b"; return %h}
    &x
    > x
    {A => a, B => b}
    >

    > sub x() returns Hash { my %h= A=>"a"; return %h}
    &x
    > x
    {A => a}

Reply via email to