Thank you Timo for the favor of a reply!

On Sat, Oct 10, 2020 at 3:35 PM Timo Paulssen <t...@wakelift.de> wrote:

> On 10/10/2020 23:21, William Michels via perl6-users wrote:
> > So I guess the first question I have is whether the 'auto-joining' of
> > array elements is specc'ed or not.
> >
> > What you seem to be saying is that when calling a function on an
> > array, the first response is for Raku to call something similar to
> > 'cat' on the array, then proceed to process the function call. As it
> > is my understanding that Raku incorporates a lot of different
> > programming paradigms (imperative, object-oriented, functional, etc.),
> > I'm not sure where this behavior falls on the 'paradigm ladder'.
>
> Hi Bill,
>
> the auto-joining of an array is a property of the split method, or more
> precisely, a result of split coming from Str.
>
> Cool has many methods and is in many things.
>
> You can call .split on Num or Rat, so 0.123451234512345.split("5") would
> give you strings, because split stringifies first.
>

Yes, but if I try to do a similar split() on an array, I end up combining
sub-elements of the array. See below where the three element [aXc dXf gXi]
becomes the four-element ("a", "c d", "f g", "i").Seq:

:~$ #test Timo's code
wmichels@bmacbook:~$ raku #enter the REPL
To exit type 'exit' or '^D'
> dd 0.123451234512345.split("5")
("0.1234", "1234", "1234", "").Seq
Nil
> dd "0.123451234512345".split("5")
("0.1234", "1234", "1234", "").Seq
Nil
> my @alpha = "aXc", "dXf", "gXi";
[aXc dXf gXi]
> dd @alpha.split("X")
("a", "c d", "f g", "i").Seq
Nil
> dd @alpha.split("Y")
("aXc dXf gXi",).Seq
Nil
>


Conversely, .join is "a listy cool method" (i just made that up) so what
> you call it on will be treated as if it were an array. "hello".join("X")
> will pretend you passed ["hello"] and just result in "hello" again.
>

Yes but...you've given a nice example where a failed join() gives you back
the same input. The same thing doesn't happen with split(). Below a failed
split() gives you back a joined string (one element):

> my @alpha = "aXc", "dXf", "gXi";
[aXc dXf gXi]
> say @alpha.elems
3
> dd @alpha.split("Y")
("aXc dXf gXi",).Seq
Nil
> say @alpha.split("Y").elems
1


Trigonometric methods like sin, cos, tan, are all "numerical cool
> methods" so the first thing they do is coerce to Numeric, that's why
> "99".tan.say gives you roughly -25.1.
>


Brian Duggan posted a short "π" array that's very nice; I've expanded it a
bit:

> my @nums = 0, π/2, 1 * π/2, 2 * π/2, 3 * π/2, 4 * π/2;
[0 1.5707963267948966 1.5707963267948966 3.141592653589793 4.71238898038469
6.283185307179586]
> dd @nums.sin
-0.27941549819892586e0
Nil
>
> my @ints = 0..9;
[0 1 2 3 4 5 6 7 8 9]
> dd @ints.log
2.302585092994046e0
Nil
>

With regards to the @nums array, I input 6 elements and I expected 6
elements back. With regards to the @ints array, I input 10 elements and I
expected 10 elements back. You may perceive an impedence-mismatch here, but
in my mind, I've created an array for the sole purpose of applying the log
function to each element of the array. I didn't use a `$`-sigiled scalar.
If I wanted the number of elements of the @ints array, I would have called
"@ints.elems". But it seems that Raku believes that I want the log of the
length of the @ints array: [ log(10) = approx 2.3025 ], when I really
wanted the ten numerics:

[-Inf, 0e0, 0.6931471805599453e0, 1.0986122886681098e0,
1.3862943611198906e0, 1.6094379124341003e0, 1.791759469228055e0,
1.9459101490553132e0, 2.0794415416798357e0, 2.1972245773362196e0]


Please check out the table near the beginning of this documentation page:
>
>     https://docs.raku.org/type/Cool
>
> hope that makes things more clear
>   - Timo
>

Thanks to you and Tobias for the Docs reference. I certainly tried
searching for "split" on https://docs.raku.org/ but ended up reading the
page below (and not the more general page on "Cool"):

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

Thanks for all your help Timo! --Best, Bill.

Reply via email to