Language Design: 'special casing' of split()? (i.e. .split performs concomitant .join? )

--0000000000008c28f805b1067d0d
Content-Type: text/plain; charset="UTF-8"

Hello All,

I'm trying to understand Raku's split/join rules. Below is REPL code and
output.

I start by studying a 2-element Array in line A (three letters separated by
commas in each element, 6 letters total). In line B, I perform a split/join
and end up with a 1 element result. Since I started with a 2-element Array,
this result suggests that Raku performs a silent join independent of the
join("_") explicitly coded for. In line C, I try looking at split()
independent of join(). Splitting on comma gives me a 5-element result, not
6 elements as I might have expected. Looking at the 5-element result in
line D, I see that "z a" has been joined together into a single element,
head-to-tail.

I further examine these results in lines E and F. In line E, I reverse the
order and do join/split. Again I see a 5-element result, this time with
"z_a" as an element of the result as shown in line F. Because I see a
5-element result in lines C/D without calling join() and a 5 element result
in lines E/F with an explicit call to join(), I conclude that an explicit
call to join() is not necessary for joining together multiple elements of
an array. In other words, split() performs an implied join of Array
elements:

> $*VM
moar (2020.06)
A> my @a = "x,y,z", "a,b,c"; @a.elems.say;
2
B> my @a = "x,y,z", "a,b,c"; @a.split(",").join("_").raku.say;
"x_y_z a_b_c"
C> my @a = "x,y,z", "a,b,c"; @a.split(",").elems.say;
5
D> my @a = "x,y,z", "a,b,c"; @a.split(",").raku.say;
("x", "y", "z a", "b", "c").Seq
E> my @a = "x,y,z", "a,b,c"; @a.join("_").split(",").elems.say;
5
F> my @a = "x,y,z", "a,b,c"; @a.join("_").split(",").raku.say;
("x", "y", "z_a", "b", "c").Seq

So far so good. Now I try looking at some real world data. Below I use the
exact same code on two strings, one with three words and the other with two
words. I assign these strings to an Array as above, then split on
whitespace because these strings are whitespace-delimited and not
comma-delimited as above. What I'm seeing below in lines G/H seems a little
unusual. I would have expected to see a 4 element result with the words
"Valentine Sonic" together in one element. However in line G, I see a 5
element result with each word distinctly separated as shown in line H.

G> my @a = "My Bloody Valentine", "Sonic Youth"; @a.split(" ").elems.say;
5
H> my @a = "My Bloody Valentine", "Sonic Youth"; @a.split(" ").raku.say;
("My", "Bloody", "Valentine", "Sonic", "Youth").Seq

So my question regards "special-casing" of split/join in Raku. Is the first
result on comma-delimited data the default, i.e. joining disparate elements
of an array together head-to-tail? Or is the second result on
whitespace-delimited data the default (i.e. no joining of disparate
elements together head-to-tail)? Which one is special-cased? If the second
one is special-cased, is that why Raku returns 5 elements and not 4
elements as in lines C/D (implied join)?

Finally, when would I ever need/want to have two disparate "terminal"
elements of an Array joined head-to-tail ("z_a") together into a single
element, as in lines A-thru-F?  For example, that means the 2-element array
"'Name1,Password1' 'Name 2,Password2'" becomes the 3-element "'Name1',
Password1 Name 2', Password2'" after a routine split, which seems a little
insecure.

Any insight appreciated,

Best Regards,

Bill.

W. Michels, Ph.D.

--0000000000008c28f805b1067d0d
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hello All,</div><div><br></div><div>I&#39;m trying to=
 understand Raku&#39;s split/join rules. Below is REPL code and output. <br=
></div><div><br></div><div>I start by studying a 2-element Array in line A =
(three letters separated by commas in each element, 6 letters total). In li=
ne B, I perform a split/join and end up with a 1 element result. Since I st=
arted with a 2-element Array, this result suggests that Raku performs a sil=
ent join independent of the join(&quot;_&quot;) explicitly coded for. In li=
ne C, I try looking at split() independent of join(). Splitting on comma gi=
ves me a 5-element result, not 6 elements as I might have expected. Looking=
 at the 5-element result in line D, I see that &quot;z a&quot; has been joi=
ned together into a single element, head-to-tail.</div><div><br></div><div>=
I further examine these results in lines E and F. In line E, I reverse the =
order and do join/split. Again I see a 5-element result, this time with &qu=
ot;z_a&quot; as an element of the result as shown in line F. Because I see =
a 5-element result in lines C/D without calling join() and a 5 element resu=
lt in lines E/F with an explicit call to join(), I conclude that an explici=
t call to join() is not necessary for joining together multiple elements of=
 an array. In other words, split() performs an implied join of Array elemen=
ts:</div><div><br></div><div>&gt; $*VM<br>moar (2020.06)<br></div><div>A&gt=
; my @a =3D &quot;x,y,z&quot;, &quot;a,b,c&quot;; @a.elems.say;</div>2<br>B=
&gt; my @a =3D &quot;x,y,z&quot;, &quot;a,b,c&quot;; @a.split(&quot;,&quot;=
).join(&quot;_&quot;).raku.say;<br>&quot;x_y_z a_b_c&quot;<br>C&gt; my @a =
=3D &quot;x,y,z&quot;, &quot;a,b,c&quot;; @a.split(&quot;,&quot;).elems.say=
;<br>5<br>D&gt; my @a =3D &quot;x,y,z&quot;, &quot;a,b,c&quot;; @a.split(&q=
uot;,&quot;).raku.say;<br>(&quot;x&quot;, &quot;y&quot;, &quot;z a&quot;, &=
quot;b&quot;, &quot;c&quot;).Seq<br>E&gt; my @a =3D &quot;x,y,z&quot;, &quo=
t;a,b,c&quot;; @a.join(&quot;_&quot;).split(&quot;,&quot;).elems.say;<br>5<=
br>F&gt; my @a =3D &quot;x,y,z&quot;, &quot;a,b,c&quot;; @a.join(&quot;_&qu=
ot;).split(&quot;,&quot;).raku.say;<br><div>(&quot;x&quot;, &quot;y&quot;, =
&quot;z_a&quot;, &quot;b&quot;, &quot;c&quot;).Seq</div><div><br></div><div=
>So far so good. Now I try looking at some real world data. Below I use the=
 exact same code on two strings, one with three words and the other with tw=
o words. I assign these strings to an Array as above, then split on whitesp=
ace because these strings are whitespace-delimited and not comma-delimited =
as above. What I&#39;m seeing below in lines G/H seems a little unusual. I =
would have=20
expected to see a 4 element result with the words &quot;Valentine Sonic&quo=
t;=20
together in one element. However in line G, I see a 5 element result=20
with each word distinctly separated as shown in line H.</div><div><br></div=
><div>G&gt; my @a =3D &quot;My Bloody Valentine&quot;, &quot;Sonic Youth&qu=
ot;; @a.split(&quot; &quot;).elems.say;<br>5<br>H&gt; my @a =3D &quot;My Bl=
oody Valentine&quot;, &quot;Sonic Youth&quot;; @a.split(&quot; &quot;).raku=
..say;<br>(&quot;My&quot;, &quot;Bloody&quot;, &quot;Valentine&quot;, &quot;=
Sonic&quot;, &quot;Youth&quot;).Seq<br></div><div><br></div><div>So my ques=
tion regards &quot;special-casing&quot; of split/join in Raku. Is the first=
 result on comma-delimited data the default, i.e. joining disparate element=
s of an array together head-to-tail? Or is the second result on whitespace-=
delimited data the default (i.e. no joining of disparate elements together =
head-to-tail)? Which one is special-cased? If the second one is special-cas=
ed, is that why Raku returns 5 elements and not 4 elements as in lines C/D =
(implied join)? <br></div><div><br></div><div>Finally, when would I ever ne=
ed/want to have two disparate &quot;terminal&quot; elements of an Array joi=
ned head-to-tail (&quot;z_a&quot;) together into a single element, as in li=
nes A-thru-F?=C2=A0 For example, that means the 2-element array &quot;&#39;=
Name1,Password1&#39; &#39;Name 2,Password2&#39;&quot; becomes the 3-element=
  &quot;&#39;Name1&#39;, Password1 Name 2&#39;, Password2&#39;&quot; after =
a routine split, which seems a little insecure.</div><div><br></div><div>An=
y insight appreciated, <br></div><div><br></div><div>Best Regards, <br></di=
v><div><br></div><div>Bill.</div><div><br></div><div>W. Michels, Ph.D.</div=
><div><br></div></div>

--0000000000008c28f805b1067d0d--
0
perl6
10/6/2020 8:31:21 PM
perl.perl6.users 1487 articles. 0 followers. Follow

21 Replies
26 Views

Similar Articles

[PageSpeed] 51

On Tue, 06 Oct 2020, William Michels via perl6-users wrote:
> [...]
>
> So my question regards "special-casing" of split/join in Raku. Is the first
> result on comma-delimited data the default, i.e. joining disparate elements
> of an array together head-to-tail? Or is the second result on
> whitespace-delimited data the default (i.e. no joining of disparate
> elements together head-to-tail)? Which one is special-cased? If the second
> one is special-cased, is that why Raku returns 5 elements and not 4
> elements as in lines C/D (implied join)?
> 

My answer is going to be that there is *no* special-casing. You have an
array of strings @a and you call the `split` and `join` methods on it.
These two methods are not alike. `join` is a proper method of List and
it joins stringifications of the elements of that list.

Crucially, the `split` method comes from somewhere else: Array inherits
it from the Cool class. When you call Array.split, what happens is that
your entire array gets stringified first (joining stringifications of
its elements with spaces) and then Cool.split is called on that string
representation of your array. This is even mentioned in the introductory
paragraph about Cool [1].

This is the strangely consistent explanation of the effects you observed.
You see, the only "special" thing is that Array.split being a Cool method
causes the array to be joined with *spaces* before the splitting starts,
but this always happens, independently of the join/split arguments.

Array.split does in particular *not* "pass on" the split call to the
elements of the array. For that you would use @a�.split, although this
would cause (itemized) Seqs for each element of @a to end up in the
returned list, so what you actually thought you were doing may be
written as

  @a�.&{ .split(",").Slip }

I am sure there are ways to write it more alphabetically.

Best,
Tobias

[1] https://docs.raku.org/type/Cool

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
0
tobs
10/6/2020 8:59:30 PM
--000000000000e55dc205b157a9d6
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

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'.

I can point to the (functional) R-programming language to show what happens
there. When manipulating "array-like" (i.e. vector) objects in R, you can
do nested function calls, or sequential (piped) function calls, and still
get the same data structure out at the end. So a 10-element input gives a
10-element output. In the R-GUI (i.e. REPL):

> 0:9
 [1] 0 1 2 3 4 5 6 7 8 9
> x <- 0:9
> is.vector(x)
[1] TRUE
> length(x)
[1] 10
> # using base-R:
> sqrt(tan(cos(sin(x))))
 [1] 1.2479614276 0.8867679488 0.8398446968 1.2344525173 0.9431819962
0.8044843661 1.1966884594
 [8] 1.0064589934 0.7823305851 1.1415611482
> x ->.; sin(.) ->.; cos(.) ->.; tan(.) ->.; sqrt(.)
 [1] 1.2479614276 0.8867679488 0.8398446968 1.2344525173 0.9431819962
0.8044843661 1.1966884594
 [8] 1.0064589934 0.7823305851 1.1415611482
> library(magrittr) # add a "piping" library:
> x %>% sin %>% cos %>% tan %>% sqrt
 [1] 1.2479614276 0.8867679488 0.8398446968 1.2344525173 0.9431819962
0.8044843661 1.1966884594
 [8] 1.0064589934 0.7823305851 1.1415611482
> y <- x %>% sin %>% cos %>% tan %>% sqrt
> is.vector(y)
[1] TRUE
> length(y)
[1] 10
>

Now it's true that R has a greatly simplified memory/storage model compared
to Raku. But it's not hard to follow the R-code above, even if you don't
know the language. If at the end of all your function calls you want to
stringify and 'collapse' your 10 element vector into a single element
string, you call paste() on your object, which has a user-definable
'collapse' argument that defaults to NULL. [For anyone worried about
formatting actual output, R has print() and sprintf() and cat() functions
as well]:

> length(paste(0:9, y))
[1] 10
> paste(0:9, y)
 [1] "0 1.24796142755091"  "1 0.886767948777031" "2 0.839844696795443" "3
1.23445251727454"
 [5] "4 0.943181996210625" "5 0.804484366108825" "6 1.19668845937773"  "7
1.00645899343325"
 [9] "8 0.782330585082487" "9 1.14156114815661"
> length(paste(0:9, "=3D", y, collapse=3D ";  "))
[1] 1
> paste(0:9, "=3D", y, collapse=3D ";  ")
[1] "0 =3D 1.24796142755091;  1 =3D 0.886767948777031;  2 =3D 0.83984469679=
5443;
 3 =3D 1.23445251727454;  4 =3D 0.943181996210625;  5 =3D 0.804484366108825=
;  6 =3D
1.19668845937773;  7 =3D 1.00645899343325;  8 =3D 0.782330585082487;  9 =3D
1.14156114815661"
>

When I started learning Perl6/Raku a few years ago I actually wondered
where the different programming paradigms would be delineated. Would
imperative/structural/procedural code be 'closer to the metal' while
functional code would be applied to higher-order data structures like
arrays, arrays-of-lists, arrays-of-hashes, and arrays-of-arrays? And those
higher-order data structures would then be utilized in object-oriented
code, i.e. the programmer would be manipulating classes and class-based
objects of varying complexity to produce a robust and secure program? Or
would Raku implement a different (i.e. better) paradigm hierarchy that I
hadn't anticipated?

Best Regards, Bill.

W. Michels, Ph.D.





On Tue, Oct 6, 2020 at 1:59 PM Tobias Boege <tobs@taboege.de> wrote:

> On Tue, 06 Oct 2020, William Michels via perl6-users wrote:
> > [...]
> >
> > So my question regards "special-casing" of split/join in Raku. Is the
> first
> > result on comma-delimited data the default, i.e. joining disparate
> elements
> > of an array together head-to-tail? Or is the second result on
> > whitespace-delimited data the default (i.e. no joining of disparate
> > elements together head-to-tail)? Which one is special-cased? If the
> second
> > one is special-cased, is that why Raku returns 5 elements and not 4
> > elements as in lines C/D (implied join)?
> >
>
> My answer is going to be that there is *no* special-casing. You have an
> array of strings @a and you call the `split` and `join` methods on it.
> These two methods are not alike. `join` is a proper method of List and
> it joins stringifications of the elements of that list.
>
> Crucially, the `split` method comes from somewhere else: Array inherits
> it from the Cool class. When you call Array.split, what happens is that
> your entire array gets stringified first (joining stringifications of
> its elements with spaces) and then Cool.split is called on that string
> representation of your array. This is even mentioned in the introductory
> paragraph about Cool [1].
>
> This is the strangely consistent explanation of the effects you observed.
> You see, the only "special" thing is that Array.split being a Cool method
> causes the array to be joined with *spaces* before the splitting starts,
> but this always happens, independently of the join/split arguments.
>
> Array.split does in particular *not* "pass on" the split call to the
> elements of the array. For that you would use @a=C2=BB.split, although th=
is
> would cause (itemized) Seqs for each element of @a to end up in the
> returned list, so what you actually thought you were doing may be
> written as
>
>   @a=C2=BB.&{ .split(",").Slip }
>
> I am sure there are ways to write it more alphabetically.
>
> Best,
> Tobias
>
> [1] https://docs.raku.org/type/Cool
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>

--000000000000e55dc205b157a9d6
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr">So I guess the first question I have is w=
hether the &#39;auto-joining&#39; of array elements is specc&#39;ed or not.=
<br><br>What you seem to be saying is that when calling a function on an ar=
ray, the first response is for Raku to call something similar to &#39;cat&#=
39; on the array, then proceed to process the function call. As it is my un=
derstanding that Raku incorporates a lot of different programming paradigms=
 (imperative, object-oriented, functional, etc.), I&#39;m not sure where th=
is behavior falls on the &#39;paradigm ladder&#39;.<br><br>I can point to t=
he (functional) R-programming language to show what happens there. When man=
ipulating &quot;array-like&quot; (i.e. vector) objects in R, you can do nes=
ted function calls, or sequential (piped) function calls, and still get the=
 same data structure out at the end. So a 10-element input gives a 10-eleme=
nt output. In the R-GUI (i.e. REPL):<br><br>&gt; 0:9<br>=C2=A0[1] 0 1 2 3 4=
 5 6 7 8 9<br>&gt; x &lt;- 0:9<br>&gt; is.vector(x)<br><div>[1] TRUE</div><=
div>&gt; length(x)<br>[1] 10</div>&gt; # using base-R:<br>&gt; sqrt(tan(cos=
(sin(x))))<br>=C2=A0[1] 1.2479614276 0.8867679488 0.8398446968 1.2344525173=
 0.9431819962 0.8044843661 1.1966884594<br>=C2=A0[8] 1.0064589934 0.7823305=
851 1.1415611482<br>&gt; x -&gt;.; sin(.) -&gt;.; cos(.) -&gt;.; tan(.) -&g=
t;.; sqrt(.)<br>=C2=A0[1] 1.2479614276 0.8867679488 0.8398446968 1.23445251=
73 0.9431819962 0.8044843661 1.1966884594<br>=C2=A0[8] 1.0064589934 0.78233=
05851 1.1415611482<br>&gt; library(magrittr) # add a &quot;piping&quot; lib=
rary:<br>&gt; x %&gt;% sin %&gt;% cos %&gt;% tan %&gt;% sqrt<br>=C2=A0[1] 1=
..2479614276 0.8867679488 0.8398446968 1.2344525173 0.9431819962 0.804484366=
1 1.1966884594<br>=C2=A0[8] 1.0064589934 0.7823305851 1.1415611482<br>&gt; =
y &lt;- x %&gt;% sin %&gt;% cos %&gt;% tan %&gt;% sqrt<br>&gt; is.vector(y)=
<br><div>[1] TRUE</div><div>&gt; length(y)<br>[1] 10<br></div><div>&gt; <br=
></div><div><br></div><div>Now it&#39;s true that R has a greatly simplifie=
d memory/storage model compared to Raku. But it&#39;s not hard to follow th=
e R-code above, even if you don&#39;t know the language. If at the end of a=
ll your function calls you want to stringify and &#39;collapse&#39; your 10=
 element vector into a single element string, you call paste() on your obje=
ct, which has a user-definable &#39;collapse&#39; argument that defaults to=
 NULL. [For anyone worried about formatting actual output, R has print() an=
d sprintf() and cat() functions as well]:<br></div><div><br></div><div>&gt;=
 length(paste(0:9, y))<br>[1] 10<br>&gt; paste(0:9, y)<br>=C2=A0[1] &quot;0=
 1.24796142755091&quot; =C2=A0&quot;1 0.886767948777031&quot; &quot;2 0.839=
844696795443&quot; &quot;3 1.23445251727454&quot; <br>=C2=A0[5] &quot;4 0.9=
43181996210625&quot; &quot;5 0.804484366108825&quot; &quot;6 1.196688459377=
73&quot; =C2=A0&quot;7 1.00645899343325&quot; <br>=C2=A0[9] &quot;8 0.78233=
0585082487&quot; &quot;9 1.14156114815661&quot; <br>&gt; length(paste(0:9, =
&quot;=3D&quot;, y, collapse=3D &quot;; =C2=A0&quot;))<br>[1] 1<br>&gt; pas=
te(0:9, &quot;=3D&quot;, y, collapse=3D &quot;; =C2=A0&quot;)<br>[1] &quot;=
0 =3D 1.24796142755091; =C2=A01 =3D 0.886767948777031; =C2=A02 =3D 0.839844=
696795443; =C2=A03 =3D 1.23445251727454; =C2=A04 =3D 0.943181996210625; =C2=
=A05 =3D 0.804484366108825; =C2=A06 =3D 1.19668845937773; =C2=A07 =3D 1.006=
45899343325; =C2=A08 =3D 0.782330585082487; =C2=A09 =3D 1.14156114815661&qu=
ot;<br>&gt; <br></div><div><br></div><div>When I started learning Perl6/Rak=
u a few years ago I actually wondered where the different programming parad=
igms would be delineated. Would imperative/structural/procedural code be &#=
39;closer to the metal&#39; while functional code would be applied to highe=
r-order data structures like arrays, arrays-of-lists, arrays-of-hashes, and=
 arrays-of-arrays? And those higher-order data structures would then be uti=
lized in object-oriented code, i.e. the programmer would be manipulating cl=
asses and class-based objects of varying complexity to produce a robust and=
 secure program? Or would Raku implement a different (i.e. better) paradigm=
 hierarchy that I hadn&#39;t anticipated?<br></div><div><br></div><div>Best=
 Regards, Bill.</div><div><br></div><div>W. Michels, Ph.D.<br></div><div><b=
r></div><div><br></div><div><br></div></div><br><br><div class=3D"gmail_quo=
te"><div dir=3D"ltr" class=3D"gmail_attr">On Tue, Oct 6, 2020 at 1:59 PM To=
bias Boege &lt;<a href=3D"mailto:tobs@taboege.de" target=3D"_blank">tobs@ta=
boege.de</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D=
"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-le=
ft:1ex">On Tue, 06 Oct 2020, William Michels via perl6-users wrote:<br>
&gt; [...]<br>
&gt;<br>
&gt; So my question regards &quot;special-casing&quot; of split/join in Rak=
u. Is the first<br>
&gt; result on comma-delimited data the default, i.e. joining disparate ele=
ments<br>
&gt; of an array together head-to-tail? Or is the second result on<br>
&gt; whitespace-delimited data the default (i.e. no joining of disparate<br=
>
&gt; elements together head-to-tail)? Which one is special-cased? If the se=
cond<br>
&gt; one is special-cased, is that why Raku returns 5 elements and not 4<br=
>
&gt; elements as in lines C/D (implied join)?<br>
&gt; <br>
<br>
My answer is going to be that there is *no* special-casing. You have an<br>
array of strings @a and you call the `split` and `join` methods on it.<br>
These two methods are not alike. `join` is a proper method of List and<br>
it joins stringifications of the elements of that list.<br>
<br>
Crucially, the `split` method comes from somewhere else: Array inherits<br>
it from the Cool class. When you call Array.split, what happens is that<br>
your entire array gets stringified first (joining stringifications of<br>
its elements with spaces) and then Cool.split is called on that string<br>
representation of your array. This is even mentioned in the introductory<br=
>
paragraph about Cool [1].<br>
<br>
This is the strangely consistent explanation of the effects you observed.<b=
r>
You see, the only &quot;special&quot; thing is that Array.split being a Coo=
l method<br>
causes the array to be joined with *spaces* before the splitting starts,<br=
>
but this always happens, independently of the join/split arguments.<br>
<br>
Array.split does in particular *not* &quot;pass on&quot; the split call to =
the<br>
elements of the array. For that you would use @a=C2=BB.split, although this=
<br>
would cause (itemized) Seqs for each element of @a to end up in the<br>
returned list, so what you actually thought you were doing may be<br>
written as<br>
<br>
=C2=A0 @a=C2=BB.&amp;{ .split(&quot;,&quot;).Slip }<br>
<br>
I am sure there are ways to write it more alphabetically.<br>
<br>
Best,<br>
Tobias<br>
<br>
[1] <a href=3D"https://docs.raku.org/type/Cool" rel=3D"noreferrer" target=
=3D"_blank">https://docs.raku.org/type/Cool</a><br>
<br>
-- <br>
&quot;There&#39;s an old saying: Don&#39;t change anything... ever!&quot; -=
- Mr. Monk<br>
</blockquote></div>
</div>

--000000000000e55dc205b157a9d6--
0
perl6
10/10/2020 9:21:58 PM
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.

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.

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.

Please check out the table near the beginning of this documentation page:

=C2=A0=C2=A0=C2=A0 https://docs.raku.org/type/Cool

hope that makes things more clear
=C2=A0 - Timo
0
timo
10/10/2020 10:26:50 PM
William Michels wrote:

>I actually wondered where the different programming paradigms
>would be delineated

I think were the present topic has to do more with the
strong/weak/gradual typing debates-- here Raku is doing an
automatic type conversion that a "strong-typing" fanatic
would sneer at.  Though, the way this behavior is implemented
is via the "(almost) everything is an object" philosophy
that Tobias was describing.

Willima Michels wrote:
> split() performs an implied join of Array elements

Yes, that's right, because split is a *string* method, it's as
though you called .Str on the array first.

What would you *want* to happen when someone treats an array as a
string?

   my @monsters =3D < blob kong mothera fingfangfoom >;
   put @monsters;        # blob kong mothera fingfangfoom
   say "{ @monsters }";  # blob kong mothera fingfangfoom

What Raku does is a DWIM move: it joins the array on spaces when
you use the array as a string.  So these do the same things:

   my $s1 =3D @monsters.Str;
   my $s2 =3D @monsters.join(" ");
   dd( $s1 );  # Str $s1 =3D "blob kong mothera fingfangfoom"
   dd( $s2 );  # Str $s2 =3D "blob kong mothera fingfangfoom"

You need to use .join explicitly if you want different behavior:

   my $s3 =3D @monsters.join(", ");
   dd( $s3 );  # Str $s3 =3D "blob, kong, mothera, fingfangfoom"

All three of these do the same things:

   my @r1 =3D  @monsters.split("a");
   my @r2 =3D  @monsters.Str.split("a");
   my @r3 =3D  @monsters.join(" ").split("a");

The each result in and array like:

  ["blob kong mother", " fingf", "ngfoom"]

In this example of yours:

  my @a =3D "My Bloody Valentine", "Sonic Youth";

When you call split on @a, it joins on spaces first (and probably
inadvertantly, throws away the division between 3 elements),
then the actual split operation results in 5 elements:

  @a.split(" ").raku.say;
  # ("My", "Bloody", "Valentine", "Sonic", "Youth").Seq

You might play with an explicit join to see what it does:

  my @r;
  @r =3D @a.join("|").split(" ");
  dd( @r ); # Array @r =3D ["My", "Bloody", "Valentine|Sonic", "Youth"]

Myself, I think I'd be inclined to loop over the elements, e.g. with map:

  @r =3D @a.map({ [ .split(" ") ] });
  dd(@r);
  # Array @r =3D [["My", "Bloody", "Valentine"], ["Sonic", "Youth"]]

That's an array of arrays: two top-level elements,
each split into 3 and 2 words respectively

Note: split does stringification because it's intended to be run
on strings, or things that can become strings-- map doesn't do
this because it's intended to be run on things like Arrays.  This
probably is "specced" though not down on the level you're
probably thinking of: it's not in the "split" documentation, for
example, because it's not really specific to that method.

You *could* argue that if you call a string method on an array,
that's simply a mistake and it should error out.  I think that's
what "strong-typing" crowd would say-- they would point out you
might have realized faster what was going on in that case.


On 10/10/20, William Michels <wjm1@caa.columbia.edu> wrote:
> So I guess the first question I have is whether the 'auto-joining' of arr=
ay
> elements is specc'ed or not.
>
> What you seem to be saying is that when calling a function on an array, t=
he
> first response is for Raku to call something similar to 'cat' on the arra=
y,
> 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 fall=
s
> on the 'paradigm ladder'.
>
> I can point to the (functional) R-programming language to show what happe=
ns
> there. When manipulating "array-like" (i.e. vector) objects in R, you can
> do nested function calls, or sequential (piped) function calls, and still
> get the same data structure out at the end. So a 10-element input gives a
> 10-element output. In the R-GUI (i.e. REPL):
>
>> 0:9
>  [1] 0 1 2 3 4 5 6 7 8 9
>> x <- 0:9
>> is.vector(x)
> [1] TRUE
>> length(x)
> [1] 10
>> # using base-R:
>> sqrt(tan(cos(sin(x))))
>  [1] 1.2479614276 0.8867679488 0.8398446968 1.2344525173 0.9431819962
> 0.8044843661 1.1966884594
>  [8] 1.0064589934 0.7823305851 1.1415611482
>> x ->.; sin(.) ->.; cos(.) ->.; tan(.) ->.; sqrt(.)
>  [1] 1.2479614276 0.8867679488 0.8398446968 1.2344525173 0.9431819962
> 0.8044843661 1.1966884594
>  [8] 1.0064589934 0.7823305851 1.1415611482
>> library(magrittr) # add a "piping" library:
>> x %>% sin %>% cos %>% tan %>% sqrt
>  [1] 1.2479614276 0.8867679488 0.8398446968 1.2344525173 0.9431819962
> 0.8044843661 1.1966884594
>  [8] 1.0064589934 0.7823305851 1.1415611482
>> y <- x %>% sin %>% cos %>% tan %>% sqrt
>> is.vector(y)
> [1] TRUE
>> length(y)
> [1] 10
>>
>
> Now it's true that R has a greatly simplified memory/storage model compar=
ed
> to Raku. But it's not hard to follow the R-code above, even if you don't
> know the language. If at the end of all your function calls you want to
> stringify and 'collapse' your 10 element vector into a single element
> string, you call paste() on your object, which has a user-definable
> 'collapse' argument that defaults to NULL. [For anyone worried about
> formatting actual output, R has print() and sprintf() and cat() functions
> as well]:
>
>> length(paste(0:9, y))
> [1] 10
>> paste(0:9, y)
>  [1] "0 1.24796142755091"  "1 0.886767948777031" "2 0.839844696795443" "3
> 1.23445251727454"
>  [5] "4 0.943181996210625" "5 0.804484366108825" "6 1.19668845937773"  "7
> 1.00645899343325"
>  [9] "8 0.782330585082487" "9 1.14156114815661"
>> length(paste(0:9, "=3D", y, collapse=3D ";  "))
> [1] 1
>> paste(0:9, "=3D", y, collapse=3D ";  ")
> [1] "0 =3D 1.24796142755091;  1 =3D 0.886767948777031;  2 =3D 0.839844696=
795443;
>  3 =3D 1.23445251727454;  4 =3D 0.943181996210625;  5 =3D 0.8044843661088=
25;  6 =3D
> 1.19668845937773;  7 =3D 1.00645899343325;  8 =3D 0.782330585082487;  9 =
=3D
> 1.14156114815661"
>>
>
> When I started learning Perl6/Raku a few years ago I actually wondered
> where the different programming paradigms would be delineated. Would
> imperative/structural/procedural code be 'closer to the metal' while
> functional code would be applied to higher-order data structures like
> arrays, arrays-of-lists, arrays-of-hashes, and arrays-of-arrays? And thos=
e
> higher-order data structures would then be utilized in object-oriented
> code, i.e. the programmer would be manipulating classes and class-based
> objects of varying complexity to produce a robust and secure program? Or
> would Raku implement a different (i.e. better) paradigm hierarchy that I
> hadn't anticipated?
>
> Best Regards, Bill.
>
> W. Michels, Ph.D.
>
>
>
>
>
> On Tue, Oct 6, 2020 at 1:59 PM Tobias Boege <tobs@taboege.de> wrote:
>
>> On Tue, 06 Oct 2020, William Michels via perl6-users wrote:
>> > [...]
>> >
>> > So my question regards "special-casing" of split/join in Raku. Is the
>> first
>> > result on comma-delimited data the default, i.e. joining disparate
>> elements
>> > of an array together head-to-tail? Or is the second result on
>> > whitespace-delimited data the default (i.e. no joining of disparate
>> > elements together head-to-tail)? Which one is special-cased? If the
>> second
>> > one is special-cased, is that why Raku returns 5 elements and not 4
>> > elements as in lines C/D (implied join)?
>> >
>>
>> My answer is going to be that there is *no* special-casing. You have an
>> array of strings @a and you call the `split` and `join` methods on it.
>> These two methods are not alike. `join` is a proper method of List and
>> it joins stringifications of the elements of that list.
>>
>> Crucially, the `split` method comes from somewhere else: Array inherits
>> it from the Cool class. When you call Array.split, what happens is that
>> your entire array gets stringified first (joining stringifications of
>> its elements with spaces) and then Cool.split is called on that string
>> representation of your array. This is even mentioned in the introductory
>> paragraph about Cool [1].
>>
>> This is the strangely consistent explanation of the effects you observed=
..
>> You see, the only "special" thing is that Array.split being a Cool metho=
d
>> causes the array to be joined with *spaces* before the splitting starts,
>> but this always happens, independently of the join/split arguments.
>>
>> Array.split does in particular *not* "pass on" the split call to the
>> elements of the array. For that you would use @a=C2=BB.split, although t=
his
>> would cause (itemized) Seqs for each element of @a to end up in the
>> returned list, so what you actually thought you were doing may be
>> written as
>>
>>   @a=C2=BB.&{ .split(",").Slip }
>>
>> I am sure there are ways to write it more alphabetically.
>>
>> Best,
>> Tobias
>>
>> [1] https://docs.raku.org/type/Cool
>>
>> --
>> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>>
>
0
doomvox
10/10/2020 10:38:06 PM
--00000000000070380705b1592050
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Functions in Raku tend to have one job and one job only.

`split` splits a string.

So if you call `split` on something that is not a string it gets turned
into one if it can.

This happens for most functions.

Having `split` be the only function that auto-vectorizes against an array
would be very confusing.

If it isn't the only function, then you have to come up with some list of
functions which do vectorize.

Then every single person has to memorize that list in its entirety. Which
can be difficult even for experts.

Perl has a similar list of functions which automatically work on `$_`, and
almost no one has that list memorized.
Raku very specifically did not copy that idea.

---

Raku instead has high level concepts that it uses consistently.

One of those concepts is that functions have one job and one job only.

So if you call `chars` on anything it gets turned into a string first.

On Sat, Oct 10, 2020 at 4:23 PM William Michels via perl6-users <
perl6-users@perl.org> 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 understandi=
ng
> 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'.
>
> I can point to the (functional) R-programming language to show what
> happens there. When manipulating "array-like" (i.e. vector) objects in R,
> you can do nested function calls, or sequential (piped) function calls, a=
nd
> still get the same data structure out at the end. So a 10-element input
> gives a 10-element output. In the R-GUI (i.e. REPL):
>
> > 0:9
>  [1] 0 1 2 3 4 5 6 7 8 9
> > x <- 0:9
> > is.vector(x)
> [1] TRUE
> > length(x)
> [1] 10
> > # using base-R:
> > sqrt(tan(cos(sin(x))))
>  [1] 1.2479614276 0.8867679488 0.8398446968 1.2344525173 0.9431819962
> 0.8044843661 1.1966884594
>  [8] 1.0064589934 0.7823305851 1.1415611482
> > x ->.; sin(.) ->.; cos(.) ->.; tan(.) ->.; sqrt(.)
>  [1] 1.2479614276 0.8867679488 0.8398446968 1.2344525173 0.9431819962
> 0.8044843661 1.1966884594
>  [8] 1.0064589934 0.7823305851 1.1415611482
> > library(magrittr) # add a "piping" library:
> > x %>% sin %>% cos %>% tan %>% sqrt
>  [1] 1.2479614276 0.8867679488 0.8398446968 1.2344525173 0.9431819962
> 0.8044843661 1.1966884594
>  [8] 1.0064589934 0.7823305851 1.1415611482
> > y <- x %>% sin %>% cos %>% tan %>% sqrt
> > is.vector(y)
> [1] TRUE
> > length(y)
> [1] 10
> >
>
> Now it's true that R has a greatly simplified memory/storage model
> compared to Raku. But it's not hard to follow the R-code above, even if y=
ou
> don't know the language. If at the end of all your function calls you wan=
t
> to stringify and 'collapse' your 10 element vector into a single element
> string, you call paste() on your object, which has a user-definable
> 'collapse' argument that defaults to NULL. [For anyone worried about
> formatting actual output, R has print() and sprintf() and cat() functions
> as well]:
>
> > length(paste(0:9, y))
> [1] 10
> > paste(0:9, y)
>  [1] "0 1.24796142755091"  "1 0.886767948777031" "2 0.839844696795443" "3
> 1.23445251727454"
>  [5] "4 0.943181996210625" "5 0.804484366108825" "6 1.19668845937773"  "7
> 1.00645899343325"
>  [9] "8 0.782330585082487" "9 1.14156114815661"
> > length(paste(0:9, "=3D", y, collapse=3D ";  "))
> [1] 1
> > paste(0:9, "=3D", y, collapse=3D ";  ")
> [1] "0 =3D 1.24796142755091;  1 =3D 0.886767948777031;  2 =3D 0.839844696=
795443;
>  3 =3D 1.23445251727454;  4 =3D 0.943181996210625;  5 =3D 0.8044843661088=
25;  6 =3D
> 1.19668845937773;  7 =3D 1.00645899343325;  8 =3D 0.782330585082487;  9 =
=3D
> 1.14156114815661"
> >
>
> When I started learning Perl6/Raku a few years ago I actually wondered
> where the different programming paradigms would be delineated. Would
> imperative/structural/procedural code be 'closer to the metal' while
> functional code would be applied to higher-order data structures like
> arrays, arrays-of-lists, arrays-of-hashes, and arrays-of-arrays? And thos=
e
> higher-order data structures would then be utilized in object-oriented
> code, i.e. the programmer would be manipulating classes and class-based
> objects of varying complexity to produce a robust and secure program? Or
> would Raku implement a different (i.e. better) paradigm hierarchy that I
> hadn't anticipated?
>
> Best Regards, Bill.
>
> W. Michels, Ph.D.
>
>
>
>
>
> On Tue, Oct 6, 2020 at 1:59 PM Tobias Boege <tobs@taboege.de> wrote:
>
>> On Tue, 06 Oct 2020, William Michels via perl6-users wrote:
>> > [...]
>> >
>> > So my question regards "special-casing" of split/join in Raku. Is the
>> first
>> > result on comma-delimited data the default, i.e. joining disparate
>> elements
>> > of an array together head-to-tail? Or is the second result on
>> > whitespace-delimited data the default (i.e. no joining of disparate
>> > elements together head-to-tail)? Which one is special-cased? If the
>> second
>> > one is special-cased, is that why Raku returns 5 elements and not 4
>> > elements as in lines C/D (implied join)?
>> >
>>
>> My answer is going to be that there is *no* special-casing. You have an
>> array of strings @a and you call the `split` and `join` methods on it.
>> These two methods are not alike. `join` is a proper method of List and
>> it joins stringifications of the elements of that list.
>>
>> Crucially, the `split` method comes from somewhere else: Array inherits
>> it from the Cool class. When you call Array.split, what happens is that
>> your entire array gets stringified first (joining stringifications of
>> its elements with spaces) and then Cool.split is called on that string
>> representation of your array. This is even mentioned in the introductory
>> paragraph about Cool [1].
>>
>> This is the strangely consistent explanation of the effects you observed=
..
>> You see, the only "special" thing is that Array.split being a Cool metho=
d
>> causes the array to be joined with *spaces* before the splitting starts,
>> but this always happens, independently of the join/split arguments.
>>
>> Array.split does in particular *not* "pass on" the split call to the
>> elements of the array. For that you would use @a=C2=BB.split, although t=
his
>> would cause (itemized) Seqs for each element of @a to end up in the
>> returned list, so what you actually thought you were doing may be
>> written as
>>
>>   @a=C2=BB.&{ .split(",").Slip }
>>
>> I am sure there are ways to write it more alphabetically.
>>
>> Best,
>> Tobias
>>
>> [1] https://docs.raku.org/type/Cool
>>
>> --
>> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>>
>

--00000000000070380705b1592050
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Functions in Raku tend to have one job and one job only.<d=
iv><br></div><div>`split` splits a string.</div><div><br></div><div>So if y=
ou call `split` on something that is not a string it gets turned into one i=
f it can.</div><div><br></div><div>This happens for most functions.</div><d=
iv><br></div><div>Having `split` be the only function that auto-vectorizes =
against an array would be very confusing.</div><div><br></div><div>If it is=
n&#39;t the only function, then you have to come up with some list of funct=
ions which do vectorize.</div><div><br></div><div>Then every single person =
has to memorize that list in its entirety. Which can be difficult even for =
experts.</div><div><br></div><div>Perl has a similar list of functions whic=
h automatically work on `$_`, and almost no one has that list memorized.</d=
iv><div>Raku very specifically did not copy that idea.</div><div><br></div>=
<div>---</div><div><br></div><div>Raku instead has high level concepts that=
 it uses consistently.</div><div><br></div><div>One of those concepts is th=
at functions have one job and one job only.</div><div><br></div><div>So if =
you call `chars` on anything it gets turned into a string first.</div></div=
><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Sa=
t, Oct 10, 2020 at 4:23 PM William Michels via perl6-users &lt;<a href=3D"m=
ailto:perl6-users@perl.org">perl6-users@perl.org</a>&gt; wrote:<br></div><b=
lockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-le=
ft:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div dir=
=3D"ltr">So I guess the first question I have is whether the &#39;auto-join=
ing&#39; of array elements is specc&#39;ed or not.<br><br>What you seem to =
be saying is that when calling a function on an array, the first response i=
s for Raku to call something similar to &#39;cat&#39; on the array, then pr=
oceed to process the function call. As it is my understanding that Raku inc=
orporates a lot of different programming paradigms (imperative, object-orie=
nted, functional, etc.), I&#39;m not sure where this behavior falls on the =
&#39;paradigm ladder&#39;.<br><br>I can point to the (functional) R-program=
ming language to show what happens there. When manipulating &quot;array-lik=
e&quot; (i.e. vector) objects in R, you can do nested function calls, or se=
quential (piped) function calls, and still get the same data structure out =
at the end. So a 10-element input gives a 10-element output. In the R-GUI (=
i.e. REPL):<br><br>&gt; 0:9<br>=C2=A0[1] 0 1 2 3 4 5 6 7 8 9<br>&gt; x &lt;=
- 0:9<br>&gt; is.vector(x)<br><div>[1] TRUE</div><div>&gt; length(x)<br>[1]=
 10</div>&gt; # using base-R:<br>&gt; sqrt(tan(cos(sin(x))))<br>=C2=A0[1] 1=
..2479614276 0.8867679488 0.8398446968 1.2344525173 0.9431819962 0.804484366=
1 1.1966884594<br>=C2=A0[8] 1.0064589934 0.7823305851 1.1415611482<br>&gt; =
x -&gt;.; sin(.) -&gt;.; cos(.) -&gt;.; tan(.) -&gt;.; sqrt(.)<br>=C2=A0[1]=
 1.2479614276 0.8867679488 0.8398446968 1.2344525173 0.9431819962 0.8044843=
661 1.1966884594<br>=C2=A0[8] 1.0064589934 0.7823305851 1.1415611482<br>&gt=
; library(magrittr) # add a &quot;piping&quot; library:<br>&gt; x %&gt;% si=
n %&gt;% cos %&gt;% tan %&gt;% sqrt<br>=C2=A0[1] 1.2479614276 0.8867679488 =
0.8398446968 1.2344525173 0.9431819962 0.8044843661 1.1966884594<br>=C2=A0[=
8] 1.0064589934 0.7823305851 1.1415611482<br>&gt; y &lt;- x %&gt;% sin %&gt=
;% cos %&gt;% tan %&gt;% sqrt<br>&gt; is.vector(y)<br><div>[1] TRUE</div><d=
iv>&gt; length(y)<br>[1] 10<br></div><div>&gt; <br></div><div><br></div><di=
v>Now it&#39;s true that R has a greatly simplified memory/storage model co=
mpared to Raku. But it&#39;s not hard to follow the R-code above, even if y=
ou don&#39;t know the language. If at the end of all your function calls yo=
u want to stringify and &#39;collapse&#39; your 10 element vector into a si=
ngle element string, you call paste() on your object, which has a user-defi=
nable &#39;collapse&#39; argument that defaults to NULL. [For anyone worrie=
d about formatting actual output, R has print() and sprintf() and cat() fun=
ctions as well]:<br></div><div><br></div><div>&gt; length(paste(0:9, y))<br=
>[1] 10<br>&gt; paste(0:9, y)<br>=C2=A0[1] &quot;0 1.24796142755091&quot; =
=C2=A0&quot;1 0.886767948777031&quot; &quot;2 0.839844696795443&quot; &quot=
;3 1.23445251727454&quot; <br>=C2=A0[5] &quot;4 0.943181996210625&quot; &qu=
ot;5 0.804484366108825&quot; &quot;6 1.19668845937773&quot; =C2=A0&quot;7 1=
..00645899343325&quot; <br>=C2=A0[9] &quot;8 0.782330585082487&quot; &quot;9=
 1.14156114815661&quot; <br>&gt; length(paste(0:9, &quot;=3D&quot;, y, coll=
apse=3D &quot;; =C2=A0&quot;))<br>[1] 1<br>&gt; paste(0:9, &quot;=3D&quot;,=
 y, collapse=3D &quot;; =C2=A0&quot;)<br>[1] &quot;0 =3D 1.24796142755091; =
=C2=A01 =3D 0.886767948777031; =C2=A02 =3D 0.839844696795443; =C2=A03 =3D 1=
..23445251727454; =C2=A04 =3D 0.943181996210625; =C2=A05 =3D 0.8044843661088=
25; =C2=A06 =3D 1.19668845937773; =C2=A07 =3D 1.00645899343325; =C2=A08 =3D=
 0.782330585082487; =C2=A09 =3D 1.14156114815661&quot;<br>&gt; <br></div><d=
iv><br></div><div>When I started learning Perl6/Raku a few years ago I actu=
ally wondered where the different programming paradigms would be delineated=
.. Would imperative/structural/procedural code be &#39;closer to the metal&#=
39; while functional code would be applied to higher-order data structures =
like arrays, arrays-of-lists, arrays-of-hashes, and arrays-of-arrays? And t=
hose higher-order data structures would then be utilized in object-oriented=
 code, i.e. the programmer would be manipulating classes and class-based ob=
jects of varying complexity to produce a robust and secure program? Or woul=
d Raku implement a different (i.e. better) paradigm hierarchy that I hadn&#=
39;t anticipated?<br></div><div><br></div><div>Best Regards, Bill.</div><di=
v><br></div><div>W. Michels, Ph.D.<br></div><div><br></div><div><br></div><=
div><br></div></div><br><br><div class=3D"gmail_quote"><div dir=3D"ltr" cla=
ss=3D"gmail_attr">On Tue, Oct 6, 2020 at 1:59 PM Tobias Boege &lt;<a href=
=3D"mailto:tobs@taboege.de" target=3D"_blank">tobs@taboege.de</a>&gt; wrote=
:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.=
8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, 06 Oct=
 2020, William Michels via perl6-users wrote:<br>
&gt; [...]<br>
&gt;<br>
&gt; So my question regards &quot;special-casing&quot; of split/join in Rak=
u. Is the first<br>
&gt; result on comma-delimited data the default, i.e. joining disparate ele=
ments<br>
&gt; of an array together head-to-tail? Or is the second result on<br>
&gt; whitespace-delimited data the default (i.e. no joining of disparate<br=
>
&gt; elements together head-to-tail)? Which one is special-cased? If the se=
cond<br>
&gt; one is special-cased, is that why Raku returns 5 elements and not 4<br=
>
&gt; elements as in lines C/D (implied join)?<br>
&gt; <br>
<br>
My answer is going to be that there is *no* special-casing. You have an<br>
array of strings @a and you call the `split` and `join` methods on it.<br>
These two methods are not alike. `join` is a proper method of List and<br>
it joins stringifications of the elements of that list.<br>
<br>
Crucially, the `split` method comes from somewhere else: Array inherits<br>
it from the Cool class. When you call Array.split, what happens is that<br>
your entire array gets stringified first (joining stringifications of<br>
its elements with spaces) and then Cool.split is called on that string<br>
representation of your array. This is even mentioned in the introductory<br=
>
paragraph about Cool [1].<br>
<br>
This is the strangely consistent explanation of the effects you observed.<b=
r>
You see, the only &quot;special&quot; thing is that Array.split being a Coo=
l method<br>
causes the array to be joined with *spaces* before the splitting starts,<br=
>
but this always happens, independently of the join/split arguments.<br>
<br>
Array.split does in particular *not* &quot;pass on&quot; the split call to =
the<br>
elements of the array. For that you would use @a=C2=BB.split, although this=
<br>
would cause (itemized) Seqs for each element of @a to end up in the<br>
returned list, so what you actually thought you were doing may be<br>
written as<br>
<br>
=C2=A0 @a=C2=BB.&amp;{ .split(&quot;,&quot;).Slip }<br>
<br>
I am sure there are ways to write it more alphabetically.<br>
<br>
Best,<br>
Tobias<br>
<br>
[1] <a href=3D"https://docs.raku.org/type/Cool" rel=3D"noreferrer" target=
=3D"_blank">https://docs.raku.org/type/Cool</a><br>
<br>
-- <br>
&quot;There&#39;s an old saying: Don&#39;t change anything... ever!&quot; -=
- Mr. Monk<br>
</blockquote></div>
</div>
</blockquote></div>

--00000000000070380705b1592050--
0
b2gills
10/10/2020 11:07:07 PM
On Sat, 10 Oct 2020, 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.
> 

I did not find anything that explicitly requires @array.split() to force
@array into a string, but there are tests in S02-types/list.t asserting
that stringified lists must use a space as delimiter.

> 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,

No, definitely not. At least not "any function". Only functions (or methods
or operators) by which you express the intent to treat the array as a string.

> 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'.
> 

If you want to view it as a matter of paradigm, I guess it would be the
"operator-centric paradigm", except that it is a method and not an operator.

The Array class inherits methods from Cool and when you call a method from
Cool on the Array, the Cool part of the array will answer the call. The
Array is Cool to advertise that it can be evaluated in numeric and string
"context". In string context, the array becomes joined using spaces as
delimiters. Put more bluntly: when you treat an array like a string
(by calling a string-related method of Cool on it), then Raku treats it
as a string, even if it must convert it to one before. [ This may sound
magical, but in reality Array just obtains the method .split from Cool
and its implementation explicitly converts the invocant, whatever it
may be, to a Stringy on which a sensible split is defined. ]

The same principle makes code like `"2" ** 5` or `2.map: * ** 5` work,
where in the first case a string 2 is treated as, and hence converted to,
a number, and in the second case an integer is treated like a list and
indeed Raku will arrange for that to happen on the fly.

In those two cases it is exponentiation that forces the invocant to become
a numberic and it is mapping that forces the invocant to become a listy
thing transparently. In the same way splitting something forces it to
become a string first. [ Again, it is not the language that somehow picks
up *syntactical* clues from your code about what to convert to what, but
it is the core implementation of, e.g., Any.map which is inherited by Int,
in the above example, and converts whatever its invocant is to something
that is iterable, because iteration is what you wanted to happen by calling
..map on it. ]

> I can point to the (functional) R-programming language to show what happens
> there. When manipulating "array-like" (i.e. vector) objects in R, you can
> do nested function calls, or sequential (piped) function calls, and still
> get the same data structure out at the end. So a 10-element input gives a
> 10-element output. In the R-GUI (i.e. REPL):
> 
> > 0:9
>  [1] 0 1 2 3 4 5 6 7 8 9
> > x <- 0:9
> > is.vector(x)
> [1] TRUE
> > length(x)
> [1] 10
> > # using base-R:
> > sqrt(tan(cos(sin(x))))
>  [1] 1.2479614276 0.8867679488 0.8398446968 1.2344525173 0.9431819962
> 0.8044843661 1.1966884594
>  [8] 1.0064589934 0.7823305851 1.1415611482

Yes, so it seems that R prefers to vectorize function calls over arrays.
In Raku, if you want to apply a method or sub or operator to every element
of a list instead of the list object itself (which may have its own over-
load or inherited version of that method causing it to behave strangely,
which is the topic of this thread), you ought to use `map` or a hyper
operator.

In Raku, if you call sin on an array, that puts the array in a numeric
context which makes the array collapse to the closest numeric thing
that Raku makes the convention to associate with it: the number of its
elements. Behold:

  my @x = 0..9;
  say @x.sin; #= -0.5440211108893698 = sin(10)

This is an excellent example you chose, because .sin and .split both
become methods of Array because Array inherits Cool. They both do not
apply element-wise but cause the entire invocant array to adapt to
context -- they become a number or a string depending on how you want
to treat it.

Best,
Tobias

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
0
tobs
10/10/2020 11:30:59 PM
On Sun, 11 Oct 2020, Tobias Boege wrote:
> On Sat, 10 Oct 2020, William Michels via perl6-users wrote:
> > 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'.
> > 
> 
> If you want to view it as a matter of paradigm, I guess it would be the
> "operator-centric paradigm", except that it is a method and not an operator.
> 
> The Array class inherits methods from Cool and when you call a method from
> Cool on the Array, the Cool part of the array will answer the call. The
> Array is Cool to advertise that it can be evaluated in numeric and string
> "context". In string context, the array becomes joined using spaces as
> delimiters. Put more bluntly: when you treat an array like a string
> (by calling a string-related method of Cool on it), then Raku treats it
> as a string, even if it must convert it to one before. [ This may sound
> magical, but in reality Array just obtains the method .split from Cool
> and its implementation explicitly converts the invocant, whatever it
> may be, to a Stringy on which a sensible split is defined. ]
> 

Oh, it seems like I was far too slow. From all the other answers, I think
Brad put best what I tried to express using many redundant words. And he
avoided the historically charged and probably inaccurate term "context".

Best,
Tobias
0
tobs
10/10/2020 11:49:31 PM
On Saturday, October 10, William Michels via perl6-users wrote:=20
> I can point to the (functional) R-programming language to show what hap=
pens
> there. When manipulating "array-like" (i.e. vector) objects in R, you c=
an
> do nested function calls, or sequential (piped) function calls, and sti=
ll
> get the same data structure out at the end. So a 10-element input gives=
 a
> 10-element output.

This seems pretty convenient and intuitive.  At least, it is possible
to mimic that behavior in Raku:

	List.^find_method('split').wrap: { $^a.map: *.split($^b) }
	List.^find_method('sin').wrap: *.map: *.sin;

	my @words =3D <a,b c,d>;
	my @nums =3D 0, =CF=80/2, 3 * =CF=80/2;

	say @words.split(',');
	say @nums.sin;

gives us

  ((a b) (c d))
  (0 1 -1)

Brian
0
bduggan
10/12/2020 1:02:17 PM
--00000000000044e15005b17b9780
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Mon, Oct 12, 2020 at 10:03 AM Brian Duggan <bduggan@matatu.org> wrote:

> On Saturday, October 10, William Michels via perl6-users wrote:
> > I can point to the (functional) R-programming language to show what
> happens
> > there. When manipulating "array-like" (i.e. vector) objects in R, you c=
an
> > do nested function calls, or sequential (piped) function calls, and sti=
ll
> > get the same data structure out at the end. So a 10-element input gives=
 a
> > 10-element output.
>
> This seems pretty convenient and intuitive.  At least, it is possible
> to mimic that behavior in Raku:
>
>         List.^find_method('split').wrap: { $^a.map: *.split($^b) }
>         List.^find_method('sin').wrap: *.map: *.sin;
>
This is like overwrite the function?
Might be better just implement a new function, I mean, a new verb as is
called in R.


>         my @words =3D <a,b c,d>;
>         my @nums =3D 0, =CF=80/2, 3 * =CF=80/2;
>
>         say @words.split(',');
>         say @nums.sin;
>
> gives us
>
>   ((a b) (c d))
>   (0 1 -1)
>
> Brian
>


--=20
Aureliano Guedes
skype: aureliano.guedes
contato:  (11) 94292-6110
whatsapp +5511942926110

--00000000000044e15005b17b9780
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">=
<div dir=3D"ltr" class=3D"gmail_attr">On Mon, Oct 12, 2020 at 10:03 AM Bria=
n Duggan &lt;<a href=3D"mailto:bduggan@matatu.org">bduggan@matatu.org</a>&g=
t; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0p=
x 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Sat=
urday, October 10, William Michels via perl6-users wrote: <br>
&gt; I can point to the (functional) R-programming language to show what ha=
ppens<br>
&gt; there. When manipulating &quot;array-like&quot; (i.e. vector) objects =
in R, you can<br>
&gt; do nested function calls, or sequential (piped) function calls, and st=
ill<br>
&gt; get the same data structure out at the end. So a 10-element input give=
s a<br>
&gt; 10-element output.<br>
<br>
This seems pretty convenient and intuitive.=C2=A0 At least, it is possible<=
br>
to mimic that behavior in Raku:<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 List.^find_method(&#39;split&#39;).wrap: { $^a.=
map: *.split($^b) }<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 List.^find_method(&#39;sin&#39;).wrap: *.map: *=
..sin;<br></blockquote><div>This is like overwrite the function?=C2=A0=C2=A0=
</div><div>Might be better just implement a new function, I mean, a new ver=
b as is called in R.</div><div><br></div><div></div><blockquote class=3D"gm=
ail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,=
204,204);padding-left:1ex">
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 my @words =3D &lt;a,b c,d&gt;;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 my @nums =3D 0, =CF=80/2, 3 * =CF=80/2;<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 say @words.split(&#39;,&#39;);<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 say @nums.sin;<br>
<br>
gives us<br>
<br>
=C2=A0 ((a b) (c d))<br>
=C2=A0 (0 1 -1)<br>
<br>
Brian<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"gmail_signature"><div dir=3D"ltr"><div><div dir=3D"ltr"><div><div=
 dir=3D"ltr"><div><div dir=3D"ltr"><div style=3D"text-align:center">Aurelia=
no Guedes</div><div style=3D"text-align:center"></div><div style=3D"text-al=
ign:center">skype: aureliano.guedes</div><div style=3D"text-align:center">c=
ontato: =C2=A0(11) 94292-6110</div><div style=3D"text-align:center">whatsap=
p +5511942926110</div></div></div></div></div></div></div></div></div></div=
>

--00000000000044e15005b17b9780--
0
guedes
10/12/2020 4:14:09 PM
On Mon, Oct 12, 2020 at 01:14:09PM -0300, Aureliano Guedes wrote:
: > This seems pretty convenient and intuitive.  At least, it is possible
: > to mimic that behavior in Raku:
: >
: >         List.^find_method('split').wrap: { $^a.map: *.split($^b) }
: >         List.^find_method('sin').wrap: *.map: *.sin;
: >
: This is like overwrite the function?
: Might be better just implement a new function, I mean, a new verb as is
: called in R.

In Raku these functions already have names, if you count metaoperators as a fancy
way to name anonymous functions:

    say <a,b c,d>».split(',');
    say (0, (π/2, 3 * π/2))».sin;

    ((a b) (c d))
    (0 (1 -1))

As shown by the ».sin example, unary hypers will distribute over
multi-dimensional structures for you, just as an APL or R programmer
would expect.  But that behavior is not intuitively obvious to everyone,
so the vector-processing paradigm is not the default.  (But we make it
really easy to get to when you want it, as you can see.  And arguably
the explicit presence of » or >> makes your intent clearer to the naïve
reader, who at least has something to look up or ask about if they don't
understand it.)

Larry
0
larry
10/12/2020 4:53:33 PM
--00000000000051876d05b17c31bf
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

These behave like overwriting

> List.^find_method('split').wrap: { $^a.map: *.split($^b) }
> List.^find_method('sin').wrap: *.map: *.sin;
>

but they don't have to, since Aureliano started with "wrap" they can be
actual wrappers:

sub map-over-arg(\A) {my &nextone=3Dnextcallee; A.map:{nextone $_}}
List.^find_method('sin').wrap: &map-over-arg;
List.^find_method('cos').wrap: &map-over-arg;
my @nums =3D 0, =CF=80/2, 3 * =CF=80/2;
say @nums.sin;  *# (0 1 -1)*
say @nums.cos; *# (1 6.123233995736766e-17 -1.8369701987210297e-16)*

I'm not sure if that can be simplified to use "nextwith" instead of
"nextcallee"=E2=80=93the "map" introduces a new scope which seems to requir=
e
"nextcallee"

The example with "split" is complicated by having 2 positionals only the
first of which needs a map, not going to play with that at the moment, left
as exercise to interested readers!

-y


On Mon, Oct 12, 2020 at 9:15 AM Aureliano Guedes <guedes.aureliano@gmail.co=
m>
wrote:

>
>
> On Mon, Oct 12, 2020 at 10:03 AM Brian Duggan <bduggan@matatu.org> wrote:
>
>> On Saturday, October 10, William Michels via perl6-users wrote:
>> > I can point to the (functional) R-programming language to show what
>> happens
>> > there. When manipulating "array-like" (i.e. vector) objects in R, you
>> can
>> > do nested function calls, or sequential (piped) function calls, and
>> still
>> > get the same data structure out at the end. So a 10-element input give=
s
>> a
>> > 10-element output.
>>
>> This seems pretty convenient and intuitive.  At least, it is possible
>> to mimic that behavior in Raku:
>>
>>         List.^find_method('split').wrap: { $^a.map: *.split($^b) }
>>         List.^find_method('sin').wrap: *.map: *.sin;
>>
> This is like overwrite the function?
> Might be better just implement a new function, I mean, a new verb as is
> called in R.
>
>
>>         my @words =3D <a,b c,d>;
>>         my @nums =3D 0, =CF=80/2, 3 * =CF=80/2;
>>
>>         say @words.split(',');
>>         say @nums.sin;
>>
>> gives us
>>
>>   ((a b) (c d))
>>   (0 1 -1)
>>
>> Brian
>>
>
>
> --
> Aureliano Guedes
> skype: aureliano.guedes
> contato:  (11) 94292-6110
> whatsapp +5511942926110
>

--00000000000051876d05b17c31bf
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div di=
r=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"lt=
r"><div dir=3D"ltr">These behave like overwriting<div><span class=3D"gmail-=
im"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bor=
der-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,20=
4);padding-left:1ex">List.^find_method(&#39;split&#39;).wrap: { $^a.map: *.=
split($^b) }<br>List.^find_method(&#39;sin&#39;).wrap: *.map: *.sin;<br></b=
lockquote><div><br></div></span></div><div>but they don&#39;t have to, sinc=
e Aureliano started with &quot;wrap&quot; they can be actual wrappers:</div=
><div><br></div><font face=3D"times new roman, serif">sub map-over-arg(\A) =
{my &amp;nextone=3Dnextcallee; A.map:{nextone $_}}<br>List.^find_method(&#3=
9;sin&#39;).wrap: &amp;map-over-arg;<br>List.^find_method(&#39;cos&#39;).wr=
ap: &amp;map-over-arg;<br>my @nums =3D 0, =CF=80/2, 3 * =CF=80/2;<br>say @n=
ums.sin; =C2=A0<i># (0 1 -1)</i><br>say @nums.cos; <i># (1 6.12323399573676=
6e-17 -1.8369701987210297e-16)</i></font><br></div><div dir=3D"ltr"><div><b=
r></div><div>I&#39;m not sure if that can be simplified to use &quot;nextwi=
th&quot; instead of &quot;nextcallee&quot;=E2=80=93the &quot;map&quot; intr=
oduces a new scope which seems to require &quot;nextcallee&quot;</div><div>=
<br></div><div>The example with &quot;split&quot; is complicated by having =
2 positionals only the first of which needs a map, not going to play with t=
hat at the moment, left as exercise to interested readers!</div><div><br cl=
ear=3D"all"><div><div dir=3D"ltr" class=3D"gmail_signature">-y<br></div></d=
iv><br></div></div></div></div></div></div></div></div></div></div></div><b=
r><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Mon, =
Oct 12, 2020 at 9:15 AM Aureliano Guedes &lt;<a href=3D"mailto:guedes.aurel=
iano@gmail.com">guedes.aureliano@gmail.com</a>&gt; wrote:<br></div><blockqu=
ote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-wid=
th:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-l=
eft:1ex"><div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmai=
l_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Mon, Oct 12, 2020 at 10:0=
3 AM Brian Duggan &lt;<a href=3D"mailto:bduggan@matatu.org" target=3D"_blan=
k">bduggan@matatu.org</a>&gt; wrote:<br></div><blockquote class=3D"gmail_qu=
ote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-st=
yle:solid;border-left-color:rgb(204,204,204);padding-left:1ex">On Saturday,=
 October 10, William Michels via perl6-users wrote: <br>
&gt; I can point to the (functional) R-programming language to show what ha=
ppens<br>
&gt; there. When manipulating &quot;array-like&quot; (i.e. vector) objects =
in R, you can<br>
&gt; do nested function calls, or sequential (piped) function calls, and st=
ill<br>
&gt; get the same data structure out at the end. So a 10-element input give=
s a<br>
&gt; 10-element output.<br>
<br>
This seems pretty convenient and intuitive.=C2=A0 At least, it is possible<=
br>
to mimic that behavior in Raku:<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 List.^find_method(&#39;split&#39;).wrap: { $^a.=
map: *.split($^b) }<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 List.^find_method(&#39;sin&#39;).wrap: *.map: *=
..sin;<br></blockquote><div>This is like overwrite the function?=C2=A0=C2=A0=
</div><div>Might be better just implement a new function, I mean, a new ver=
b as is called in R.</div><div><br></div><div></div><blockquote class=3D"gm=
ail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-l=
eft-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 my @words =3D &lt;a,b c,d&gt;;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 my @nums =3D 0, =CF=80/2, 3 * =CF=80/2;<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 say @words.split(&#39;,&#39;);<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 say @nums.sin;<br>
<br>
gives us<br>
<br>
=C2=A0 ((a b) (c d))<br>
=C2=A0 (0 1 -1)<br>
<br>
Brian<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
><div dir=3D"ltr"><div><div dir=3D"ltr"><div><div dir=3D"ltr"><div><div dir=
=3D"ltr"><div style=3D"text-align:center">Aureliano Guedes</div><div style=
=3D"text-align:center"></div><div style=3D"text-align:center">skype: aureli=
ano.guedes</div><div style=3D"text-align:center">contato: =C2=A0(11) 94292-=
6110</div><div style=3D"text-align:center">whatsapp +5511942926110</div></d=
iv></div></div></div></div></div></div></div></div>
</blockquote></div>

--00000000000051876d05b17c31bf--
0
not
10/12/2020 4:57:13 PM
--00000000000002922205b17e7306
Content-Type: text/plain; charset="UTF-8"

Thank you, Joe, for taking the time to write such a cogent reply. And
thanks to Tobias and everyone else who has taken the time to reply to my
questions.

On Sat, Oct 10, 2020 at 3:38 PM Joseph Brenner <doomvox@gmail.com> wrote:

> William Michels wrote:
>
> >I actually wondered where the different programming paradigms
> >would be delineated
>
> I think were the present topic has to do more with the
> strong/weak/gradual typing debates-- here Raku is doing an
> automatic type conversion that a "strong-typing" fanatic
> would sneer at.  Though, the way this behavior is implemented
> is via the "(almost) everything is an object" philosophy
> that Tobias was describing.
>
> William Michels wrote:
> > split() performs an implied join of Array elements
>
> Yes, that's right, because split is a *string* method, it's as
> though you called .Str on the array first.
>

Playing devil's-advocate here, I don't *know* that split() is a string
method. For all I know, there could be a form of split() which splits on
bytes, or graphemes, or nulls. I can, for example, split on nulls:
 split("\0"). Does that properly qualify as a string method? If I call
split("\0").WHAT, I'm told I've produced a (Seq), not a string. So when do
I *know* that Raku's split() is confined to string substrates? (Substrate
is a biochemistry term but I'm sure you get the .gist).

What about awk that can apparently split on bytes? Does Raku behave like
awk? Or Golang which has a split function that acts on bytes? Does Raku
behave like Golang? What about Python that (apparently) can't split on
bytes without a prior .decode() step? Is Raku more capable than Python? Or
maybe Raku's split() is analogous to Elixir's .slice/x, where a data
structure can be "split" into 2 or 3 or x Int parts. Does Raku's split()
act like Elixr's .slice? And if Raku's split() acts like Elixr's .slice,
who's to say it doesn't act element-wise on each element of an array?

https://unix.stackexchange.com/questions/583716/awk-split-each-byte-to-their-own-file-while-specifying-created-filename-to-std
https://golang.org/pkg/bytes/
https://stackoverflow.com/questions/13857856/split-byte-string-into-lines
https://hexdocs.pm/elixir/1.0.5/String.html

What would you *want* to happen when someone treats an array as a
> string?
>
>    my @monsters = < blob kong mothera fingfangfoom >;
>    put @monsters;        # blob kong mothera fingfangfoom
>    say "{ @monsters }";  # blob kong mothera fingfangfoom
>

Again, I don't know anything about Raku's storage model. Does Raku
efficiently pack arrays like PDL (Perl Data Language)? Even if it doesn't,
surely the double-quotes and commas are screen-sugar, decorating print
calls but otherwise not stored with the object. I might imagine that each
element of a Raku array is separated by an ASCII record separator: US
(ASCII_31). So when I call Raku's split(), it applies split to each element
of the array, and leaves the US record separator (ASCII_31) untouched:

https://www.unicode.org/charts/PDF/U0000.pdf
https://www.cisco.com/c/en/us/td/docs/ios/12_4/cfg_fund/command/reference/cfnapph.html#
https://www.lammertbies.nl/comm/info/ascii-characters
https://ronaldduncan.wordpress.com/2009/10/31/text-file-formats-ascii-delimited-text-not-csv-or-tab-delimited-text/



> What Raku does is a DWIM move: it joins the array on spaces when
> you use the array as a string.  So these do the same things:
>
>    my $s1 = @monsters.Str;
>    my $s2 = @monsters.join(" ");
>    dd( $s1 );  # Str $s1 = "blob kong mothera fingfangfoom"
>    dd( $s2 );  # Str $s2 = "blob kong mothera fingfangfoom"
>
> You need to use .join explicitly if you want different behavior:
>
>    my $s3 = @monsters.join(", ");
>    dd( $s3 );  # Str $s3 = "blob, kong, mothera, fingfangfoom"
>
> All three of these do the same things:
>
>    my @r1 =  @monsters.split("a");
>    my @r2 =  @monsters.Str.split("a");
>    my @r3 =  @monsters.join(" ").split("a");
>
> The each result in and array like:
>
>   ["blob kong mother", " fingf", "ngfoom"]
>

Yes, but you've overlooked the obvious test, which is, what happens when I
try to split on a character that DOES NOT exist in the array. In that case
I end up destroying my array and creating a single element string. So a
failed split actually joins (code/results below from the Raku REPL):

> say @monsters.Str.split("Z").elems;
1
> dd @monsters.Str.split("Z");
("blob kong mothera fingfangfoom",).Seq
Nil
>


In this example of yours:
>
>   my @a = "My Bloody Valentine", "Sonic Youth";
>
> When you call split on @a, it joins on spaces first (and probably
> inadvertantly, throws away the division between 3 elements),
> then the actual split operation results in 5 elements:
>
>   @a.split(" ").raku.say;
>   # ("My", "Bloody", "Valentine", "Sonic", "Youth").Seq
>

Yes, the call above appears to 'flatten' the array, which isn't what I
desired. [ Had I desired to flatten the array, I would probably take a wild
guess and call flat(). ].  But I guess that really isn't the end of it:  if
you try  to do the same call on a comma-separated list using split(",") you
get two different elements joined together, "Valentine Sonic". Meaning
whitespace separated strings (combined with splitting on whitespace) are
special-cased relative to non-whitespace separated strings (combined with
splitting on non-whitespace):

> dd @a
Array @a = ["My Bloody Valentine", "Sonic Youth"]
Nil
> dd @a.split(" ")
("My", "Bloody", "Valentine", "Sonic", "Youth").Seq
Nil
> dd @a.split(" ").elems
5
Nil

> my @b = "My,Bloody,Valentine", "Sonic,Youth";
[My,Bloody,Valentine Sonic,Youth]
> dd @b.split(",")
("My", "Bloody", "Valentine Sonic", "Youth").Seq
Nil
> dd @b.split(",").elems
4
Nil

If I try to write code that takes in arbitrary text and splits on arbitrary
characters, I'll have to write two subs at the very least--one to handle
splitting on whitespace, and the other splitting on non-whitespace.



> You might play with an explicit join to see what it does:
>
>   my @r;
>   @r = @a.join("|").split(" ");
>   dd( @r ); # Array @r = ["My", "Bloody", "Valentine|Sonic", "Youth"]
>
> Myself, I think I'd be inclined to loop over the elements, e.g. with map:
>
>   @r = @a.map({ [ .split(" ") ] });
>   dd(@r);
>   # Array @r = [["My", "Bloody", "Valentine"], ["Sonic", "Youth"]]
>
> That's an array of arrays: two top-level elements,
> each split into 3 and 2 words respectively
>

> Note: split does stringification because it's intended to be run
> on strings, or things that can become strings-- map doesn't do
> this because it's intended to be run on things like Arrays.  This
> probably is "specced" though not down on the level you're
> probably thinking of: it's not in the "split" documentation, for
> example, because it's not really specific to that method.
>
> You *could* argue that if you call a string method on an array,
> that's simply a mistake and it should error out.  I think that's
> what "strong-typing" crowd would say-- they would point out you
> might have realized faster what was going on in that case.
>

Yes, the faster I can dispel my confusion the better. Thanks, Bill.

PS. Thanks also to Bruce Gray, who contributed greatly to this conversation
during our weekly Raku Meetup (online, Zoom).


> On 10/10/20, William Michels <wjm1@caa.columbia.edu> wrote:
> > On Tue, Oct 6, 2020 at 1:59 PM Tobias Boege <tobs@taboege.de> wrote:
>

--00000000000002922205b17e7306
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr">Thank you, Joe, for taking the time to wr=
ite such a cogent reply. And thanks to Tobias and everyone else who has tak=
en the time to reply to my questions.<br></div><br><div class=3D"gmail_quot=
e"><div dir=3D"ltr" class=3D"gmail_attr">On Sat, Oct 10, 2020 at 3:38 PM Jo=
seph Brenner &lt;<a href=3D"mailto:doomvox@gmail.com">doomvox@gmail.com</a>=
&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px =
0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Will=
iam Michels wrote:<br>
<br>
&gt;I actually wondered where the different programming paradigms<br>
&gt;would be delineated<br>
<br>
I think were the present topic has to do more with the<br>
strong/weak/gradual typing debates-- here Raku is doing an<br>
automatic type conversion that a &quot;strong-typing&quot; fanatic<br>
would sneer at.=C2=A0 Though, the way this behavior is implemented<br>
is via the &quot;(almost) everything is an object&quot; philosophy<br>
that Tobias was describing.<br>
<br>
William Michels wrote:<br>
&gt; split() performs an implied join of Array elements<br>
<br>
Yes, that&#39;s right, because split is a *string* method, it&#39;s as<br>
though you called .Str on the array first.<br></blockquote><div><br></div><=
div>Playing devil&#39;s-advocate here, I don&#39;t *know* that split() is a=
 string method. For all I know, there could be a form of split() which spli=
ts on bytes, or graphemes, or nulls. I can, for example, split on nulls: =
=C2=A0split(&quot;\0&quot;). Does that properly qualify as a string method?=
 If I call split(&quot;\0&quot;).WHAT, I&#39;m told I&#39;ve produced a (Se=
q), not a string. So when do I *know* that Raku&#39;s split() is confined t=
o string substrates? (Substrate is a biochemistry term but I&#39;m sure you=
 get the .gist).</div><div><br></div><div>What about awk that can apparentl=
y split on bytes? Does Raku behave like awk? Or Golang which has a split fu=
nction that acts on bytes? Does Raku behave like Golang? What about Python =
that (apparently) can&#39;t split on bytes without a prior .decode() step? =
Is Raku more capable than Python? Or maybe Raku&#39;s split() is analogous =
to Elixir&#39;s .slice/x, where a data structure can be &quot;split&quot; i=
nto 2 or 3 or x Int parts. Does Raku&#39;s split() act like Elixr&#39;s .sl=
ice? And if Raku&#39;s split() acts like Elixr&#39;s .slice, who&#39;s to s=
ay it doesn&#39;t act element-wise on each element of an array?<br><br><a h=
ref=3D"https://unix.stackexchange.com/questions/583716/awk-split-each-byte-=
to-their-own-file-while-specifying-created-filename-to-std">https://unix.st=
ackexchange.com/questions/583716/awk-split-each-byte-to-their-own-file-whil=
e-specifying-created-filename-to-std</a><br><a href=3D"https://golang.org/p=
kg/bytes/">https://golang.org/pkg/bytes/</a><br><a href=3D"https://stackove=
rflow.com/questions/13857856/split-byte-string-into-lines">https://stackove=
rflow.com/questions/13857856/split-byte-string-into-lines</a><br><a href=3D=
"https://hexdocs.pm/elixir/1.0.5/String.html">https://hexdocs.pm/elixir/1.0=
..5/String.html</a><br><br></div><blockquote class=3D"gmail_quote" style=3D"=
margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-lef=
t:1ex">
What would you *want* to happen when someone treats an array as a<br>
string?<br>
<br>
=C2=A0 =C2=A0my @monsters =3D &lt; blob kong mothera fingfangfoom &gt;;<br>
=C2=A0 =C2=A0put @monsters;=C2=A0 =C2=A0 =C2=A0 =C2=A0 # blob kong mothera =
fingfangfoom<br>
=C2=A0 =C2=A0say &quot;{ @monsters }&quot;;=C2=A0 # blob kong mothera fingf=
angfoom<br></blockquote><div><br></div><div>Again, I don&#39;t know anythin=
g about Raku&#39;s storage model. Does Raku efficiently pack arrays like PD=
L (Perl Data Language)? Even if it doesn&#39;t, surely the double-quotes an=
d commas are screen-sugar, decorating print calls but otherwise not stored =
with the object. I might imagine that each element of a Raku array is separ=
ated by an ASCII record separator: US (ASCII_31). So when I call Raku&#39;s=
 split(), it applies split to each element of the array, and leaves the US =
record separator (ASCII_31) untouched:<br><br><a href=3D"https://www.unicod=
e.org/charts/PDF/U0000.pdf">https://www.unicode.org/charts/PDF/U0000.pdf</a=
><br><a href=3D"https://www.cisco.com/c/en/us/td/docs/ios/12_4/cfg_fund/com=
mand/reference/cfnapph.html#">https://www.cisco.com/c/en/us/td/docs/ios/12_=
4/cfg_fund/command/reference/cfnapph.html#</a><br><a href=3D"https://www.la=
mmertbies.nl/comm/info/ascii-characters">https://www.lammertbies.nl/comm/in=
fo/ascii-characters</a><br><a href=3D"https://ronaldduncan.wordpress.com/20=
09/10/31/text-file-formats-ascii-delimited-text-not-csv-or-tab-delimited-te=
xt/">https://ronaldduncan.wordpress.com/2009/10/31/text-file-formats-ascii-=
delimited-text-not-csv-or-tab-delimited-text/</a><br><br></div><div>=C2=A0<=
/div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bo=
rder-left:1px solid rgb(204,204,204);padding-left:1ex">
What Raku does is a DWIM move: it joins the array on spaces when<br>
you use the array as a string.=C2=A0 So these do the same things:<br>
<br>
=C2=A0 =C2=A0my $s1 =3D @monsters.Str;<br>
=C2=A0 =C2=A0my $s2 =3D @monsters.join(&quot; &quot;);<br>
=C2=A0 =C2=A0dd( $s1 );=C2=A0 # Str $s1 =3D &quot;blob kong mothera fingfan=
gfoom&quot;<br>
=C2=A0 =C2=A0dd( $s2 );=C2=A0 # Str $s2 =3D &quot;blob kong mothera fingfan=
gfoom&quot;<br>
<br>
You need to use .join explicitly if you want different behavior:<br>
<br>
=C2=A0 =C2=A0my $s3 =3D @monsters.join(&quot;, &quot;);<br>
=C2=A0 =C2=A0dd( $s3 );=C2=A0 # Str $s3 =3D &quot;blob, kong, mothera, fing=
fangfoom&quot;<br>
<br>
All three of these do the same things:<br>
<br>
=C2=A0 =C2=A0my @r1 =3D=C2=A0 @monsters.split(&quot;a&quot;);<br>
=C2=A0 =C2=A0my @r2 =3D=C2=A0 @monsters.Str.split(&quot;a&quot;);<br>
=C2=A0 =C2=A0my @r3 =3D=C2=A0 @monsters.join(&quot; &quot;).split(&quot;a&q=
uot;);<br>
<br>
The each result in and array like:<br>
<br>
=C2=A0 [&quot;blob kong mother&quot;, &quot; fingf&quot;, &quot;ngfoom&quot=
;]<br></blockquote><div><br></div><div>Yes, but you&#39;ve overlooked the o=
bvious test, which is, what happens when I try to split on a character that=
 DOES NOT exist in the array. In that case I end up destroying my array and=
 creating a single element string. So a failed split actually joins (code/r=
esults below from the Raku REPL):<br><br>&gt; say @monsters.Str.split(&quot=
;Z&quot;).elems;<br>1<br>&gt; dd @monsters.Str.split(&quot;Z&quot;);<br>(&q=
uot;blob kong mothera fingfangfoom&quot;,).Seq<br>Nil<br>&gt;</div><div><br=
></div><div> <br></div><blockquote class=3D"gmail_quote" style=3D"margin:0p=
x 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
In this example of yours:<br>
<br>
=C2=A0 my @a =3D &quot;My Bloody Valentine&quot;, &quot;Sonic Youth&quot;;<=
br>
<br>
When you call split on @a, it joins on spaces first (and probably<br>
inadvertantly, throws away the division between 3 elements),<br>
then the actual split operation results in 5 elements:<br>
<br>
=C2=A0 @a.split(&quot; &quot;).raku.say;<br>
=C2=A0 # (&quot;My&quot;, &quot;Bloody&quot;, &quot;Valentine&quot;, &quot;=
Sonic&quot;, &quot;Youth&quot;).Seq<br></blockquote><div><br></div><div>Yes=
, the call above appears to &#39;flatten&#39; the array, which isn&#39;t wh=
at I desired. [ Had I desired to flatten the array, I would probably take a=
 wild guess and call flat(). ].=C2=A0 But I guess that really isn&#39;t the=
 end of it: =C2=A0if you try =C2=A0to do the same call on a comma-separated=
 list using split(&quot;,&quot;) you get two different elements joined toge=
ther, &quot;Valentine Sonic&quot;. Meaning whitespace separated strings (co=
mbined with splitting on whitespace) are special-cased relative to non-whit=
espace separated strings (combined with splitting on non-whitespace):<br><b=
r>&gt; dd @a<br>Array @a =3D [&quot;My Bloody Valentine&quot;, &quot;Sonic =
Youth&quot;]<br>Nil<br>&gt; dd @a.split(&quot; &quot;)<br>(&quot;My&quot;, =
&quot;Bloody&quot;, &quot;Valentine&quot;, &quot;Sonic&quot;, &quot;Youth&q=
uot;).Seq<br>Nil<br>&gt; dd @a.split(&quot; &quot;).elems<br>5<br>Nil<br><b=
r>&gt; my @b =3D &quot;My,Bloody,Valentine&quot;, &quot;Sonic,Youth&quot;;<=
br>[My,Bloody,Valentine Sonic,Youth]<br>&gt; dd @b.split(&quot;,&quot;)<br>=
(&quot;My&quot;, &quot;Bloody&quot;, &quot;Valentine Sonic&quot;, &quot;You=
th&quot;).Seq<br>Nil<br>&gt; dd @b.split(&quot;,&quot;).elems<br>4<br>Nil<b=
r><br>If I try to write code that takes in arbitrary text and splits on arb=
itrary characters, I&#39;ll have to write two subs at the very least--one t=
o handle splitting on whitespace, and the other splitting on non-whitespace=
..<br><br>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0px =
0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
You might play with an explicit join to see what it does:<br>
<br>
=C2=A0 my @r;<br>
=C2=A0 @r =3D @a.join(&quot;|&quot;).split(&quot; &quot;);<br>
=C2=A0 dd( @r ); # Array @r =3D [&quot;My&quot;, &quot;Bloody&quot;, &quot;=
Valentine|Sonic&quot;, &quot;Youth&quot;]<br>
<br>
Myself, I think I&#39;d be inclined to loop over the elements, e.g. with ma=
p:<br>
<br>
=C2=A0 @r =3D @a.map({ [ .split(&quot; &quot;) ] });<br>
=C2=A0 dd(@r);<br>
=C2=A0 # Array @r =3D [[&quot;My&quot;, &quot;Bloody&quot;, &quot;Valentine=
&quot;], [&quot;Sonic&quot;, &quot;Youth&quot;]]<br>
<br>
That&#39;s an array of arrays: two top-level elements,<br>
each split into 3 and 2 words respectively=C2=A0 <br></blockquote><blockquo=
te class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px =
solid rgb(204,204,204);padding-left:1ex">
<br>
Note: split does stringification because it&#39;s intended to be run<br>
on strings, or things that can become strings-- map doesn&#39;t do<br>
this because it&#39;s intended to be run on things like Arrays.=C2=A0 This<=
br>
probably is &quot;specced&quot; though not down on the level you&#39;re<br>
probably thinking of: it&#39;s not in the &quot;split&quot; documentation, =
for<br>
example, because it&#39;s not really specific to that method.<br>
<br>
You *could* argue that if you call a string method on an array,<br>
that&#39;s simply a mistake and it should error out.=C2=A0 I think that&#39=
;s<br>
what &quot;strong-typing&quot; crowd would say-- they would point out you<b=
r>
might have realized faster what was going on in that case.<br></blockquote>=
<div><br></div><div>Yes, the faster I can dispel my confusion the better. T=
hanks, Bill. <br></div><div><br></div><div>PS. Thanks also to Bruce Gray, w=
ho contributed greatly to this conversation during our weekly Raku Meetup (=
online, Zoom).<br></div><div>=C2=A0</div><blockquote class=3D"gmail_quote" =
style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);pa=
dding-left:1ex">
On 10/10/20, William Michels &lt;<a href=3D"mailto:wjm1@caa.columbia.edu" t=
arget=3D"_blank">wjm1@caa.columbia.edu</a>&gt; wrote:<br>&gt; On Tue, Oct 6=
, 2020 at 1:59 PM Tobias Boege &lt;<a href=3D"mailto:tobs@taboege.de" targe=
t=3D"_blank">tobs@taboege.de</a>&gt; wrote:<br>
</blockquote></div></div>

--00000000000002922205b17e7306--
0
perl6
10/12/2020 7:38:21 PM
--000000000000f6e43b05b17e7dd4
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Mon, Oct 12, 2020 at 6:02 AM Brian Duggan <bduggan@matatu.org> wrote:

> On Saturday, October 10, William Michels via perl6-users wrote:
> > I can point to the (functional) R-programming language to show what
> happens
> > there. When manipulating "array-like" (i.e. vector) objects in R, you c=
an
> > do nested function calls, or sequential (piped) function calls, and sti=
ll
> > get the same data structure out at the end. So a 10-element input gives=
 a
> > 10-element output.
>
> This seems pretty convenient and intuitive.  At least, it is possible
> to mimic that behavior in Raku:
>
>         List.^find_method('split').wrap: { $^a.map: *.split($^b) }
>         List.^find_method('sin').wrap: *.map: *.sin;
>
>         my @words =3D <a,b c,d>;
>         my @nums =3D 0, =CF=80/2, 3 * =CF=80/2;
>
>         say @words.split(',');
>         say @nums.sin;
>
> gives us
>
>   ((a b) (c d))
>   (0 1 -1)
>
> Brian
>

Thank you for your reply, Brian!

user@mbook:~$ #test Brian Duggan code:
user@mbook:~$ raku  #enter REPL
To exit type 'exit' or '^D'
>  List.^find_method('split').wrap: { $^a.map: *.split($^b) }
Routine::WrapHandle.new
>  List.^find_method('sin').wrap: *.map: *.sin;
Routine::WrapHandle.new
> my @words =3D <a,b c,d>;
[a,b c,d]
> my @nums =3D 0, =CF=80/2, 3 * =CF=80/2;
[0 1.5707963267948966 4.71238898038469]

> say @words.elems;
2
> say @words.split('Z').elems;
2
> say @words.split(',').elems;
2
> dd @words.split(',');
(("a", "b").Seq, ("c", "d").Seq).Seq
Nil

> say @nums.elems;
3
> say @nums.sin.elems;
3
> dd @nums.sin;
(0e0, 1e0, -1e0).Seq
Nil

Yes, that works very nicely. There is no longer a difference between
splitting on commas vs splitting on whitespace. And I especially like the
fact that a failed call to split() no longer joins all array elements into
a single string (see examples above and below when attempting to split on
'Z'):

> my @words2 =3D "a b", "c d e";
[a b c d e]
> dd @words2
Array @words2 =3D ["a b", "c d e"]
Nil
> say @words2.elems;
2
> say @words2.split('Z').elems;
2
> say @words2.split(' ').elems;
2
> dd @words2.split(' ');
(("a", "b").Seq, ("c", "d", "e").Seq).Seq
Nil

Thanks again, Brian!

Best, Bill.

--000000000000f6e43b05b17e7dd4
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">=
<div dir=3D"ltr" class=3D"gmail_attr">On Mon, Oct 12, 2020 at 6:02 AM Brian=
 Duggan &lt;<a href=3D"mailto:bduggan@matatu.org" target=3D"_blank">bduggan=
@matatu.org</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding=
-left:1ex">On Saturday, October 10, William Michels via perl6-users wrote: =
<br>
&gt; I can point to the (functional) R-programming language to show what ha=
ppens<br>
&gt; there. When manipulating &quot;array-like&quot; (i.e. vector) objects =
in R, you can<br>
&gt; do nested function calls, or sequential (piped) function calls, and st=
ill<br>
&gt; get the same data structure out at the end. So a 10-element input give=
s a<br>
&gt; 10-element output.<br>
<br>
This seems pretty convenient and intuitive.=C2=A0 At least, it is possible<=
br>
to mimic that behavior in Raku:<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 List.^find_method(&#39;split&#39;).wrap: { $^a.=
map: *.split($^b) }<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 List.^find_method(&#39;sin&#39;).wrap: *.map: *=
..sin;<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 my @words =3D &lt;a,b c,d&gt;;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 my @nums =3D 0, =CF=80/2, 3 * =CF=80/2;<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 say @words.split(&#39;,&#39;);<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 say @nums.sin;<br>
<br>
gives us<br>
<br>
=C2=A0 ((a b) (c d))<br>
=C2=A0 (0 1 -1)<br>
<br>
Brian<br></blockquote><div><br></div><div>Thank you for your reply, Brian!<=
/div><div><br></div><div>user@mbook:~$ #test Brian Duggan code:<br>user@mbo=
ok:~$ raku=C2=A0 #enter REPL<br>To exit type &#39;exit&#39; or &#39;^D&#39;=
<br>&gt; =C2=A0List.^find_method(&#39;split&#39;).wrap: { $^a.map: *.split(=
$^b) }<br>Routine::WrapHandle.new<br>&gt; =C2=A0List.^find_method(&#39;sin&=
#39;).wrap: *.map: *.sin;<br>Routine::WrapHandle.new<br>&gt; my @words =3D =
&lt;a,b c,d&gt;;<br>[a,b c,d]<br>&gt; my @nums =3D 0, =CF=80/2, 3 * =CF=80/=
2;<br>[0 1.5707963267948966 4.71238898038469]</div><div><br></div><div>&gt;=
 say @words.elems;<br>2</div><div>&gt; say @words.split(&#39;Z&#39;).elems;=
<br>2</div><div>&gt; say @words.split(&#39;,&#39;).elems;<br>2</div><div>&g=
t; dd @words.split(&#39;,&#39;);<br>((&quot;a&quot;, &quot;b&quot;).Seq, (&=
quot;c&quot;, &quot;d&quot;).Seq).Seq<br>Nil</div><div><br></div><div>&gt; =
say @nums.elems;<br>3<br>&gt; say @nums.sin.elems;<br>3<br>&gt; dd @nums.si=
n;<br>(0e0, 1e0, -1e0).Seq<br>Nil<br></div><div><br></div><div>Yes, that wo=
rks very nicely. There is no longer a difference between splitting on comma=
s vs splitting on whitespace. And I especially like the fact that a failed =
call to split() no longer joins all array elements into a single string (se=
e examples above and below when attempting to split on &#39;Z&#39;):<br></d=
iv><div><br></div>&gt; my @words2 =3D &quot;a b&quot;, &quot;c d e&quot;;<b=
r>[a b c d e]<br>&gt; dd @words2<br>Array @words2 =3D [&quot;a b&quot;, &qu=
ot;c d e&quot;]<br>Nil</div><div class=3D"gmail_quote">&gt; say @words2.ele=
ms;<br>2<br>&gt; say @words2.split(&#39;Z&#39;).elems;<br>2<br>&gt; say @wo=
rds2.split(&#39; &#39;).elems;<br>2</div><div class=3D"gmail_quote">&gt; dd=
 @words2.split(&#39; &#39;);<br>((&quot;a&quot;, &quot;b&quot;).Seq, (&quot=
;c&quot;, &quot;d&quot;, &quot;e&quot;).Seq).Seq<br>Nil</div><div class=3D"=
gmail_quote"><br></div><div class=3D"gmail_quote">Thanks again, Brian!</div=
><div class=3D"gmail_quote"><br></div><div class=3D"gmail_quote">Best, Bill=
..<br></div><div class=3D"gmail_quote"> <br></div></div>

--000000000000f6e43b05b17e7dd4--
0
perl6
10/12/2020 7:41:24 PM
--000000000000fad78e05b17f463f
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Thank you Timo for the favor of a reply!

On Sat, Oct 10, 2020 at 3:35 PM Timo Paulssen <timo@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 =3D "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 =3D "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 "=CF=80" array that's very nice; I've expanded =
it a
bit:

> my @nums =3D 0, =CF=80/2, 1 * =CF=80/2, 2 * =CF=80/2, 3 * =CF=80/2, 4 * =
=CF=80/2;
[0 1.5707963267948966 1.5707963267948966 3.141592653589793 4.71238898038469
6.283185307179586]
> dd @nums.sin
-0.27941549819892586e0
Nil
>
> my @ints =3D 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) =3D 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.

--000000000000fad78e05b17f463f
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Thank you Timo for the favor of a reply!<br></div><br=
><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Sat, O=
ct 10, 2020 at 3:35 PM Timo Paulssen &lt;<a href=3D"mailto:timo@wakelift.de=
">timo@wakelift.de</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote=
" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);=
padding-left:1ex">On 10/10/2020 23:21, William Michels via perl6-users wrot=
e:<br>
&gt; So I guess the first question I have is whether the &#39;auto-joining&=
#39; of<br>
&gt; array elements is specc&#39;ed or not.<br>
&gt;<br>
&gt; What you seem to be saying is that when calling a function on an<br>
&gt; array, the first response is for Raku to call something similar to<br>
&gt; &#39;cat&#39; on the array, then proceed to process the function call.=
 As it<br>
&gt; is my understanding that Raku incorporates a lot of different<br>
&gt; programming paradigms (imperative, object-oriented, functional, etc.),=
<br>
&gt; I&#39;m not sure where this behavior falls on the &#39;paradigm ladder=
&#39;.<br>
<br>
Hi Bill,<br>
<br>
the auto-joining of an array is a property of the split method, or more<br>
precisely, a result of split coming from Str.<br>
<br>
Cool has many methods and is in many things.<br>
<br>
You can call .split on Num or Rat, so 0.123451234512345.split(&quot;5&quot;=
) would<br>
give you strings, because split stringifies first.<br></blockquote><div><br=
></div><div>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 [aX=
c dXf gXi] becomes the four-element (&quot;a&quot;, &quot;c d&quot;, &quot;=
f g&quot;, &quot;i&quot;).Seq:</div><div><br></div><div>:~$ #test Timo&#39;=
s code<br>wmichels@bmacbook:~$ raku #enter the REPL<br>To exit type &#39;ex=
it&#39; or &#39;^D&#39;<br>&gt; dd 0.123451234512345.split(&quot;5&quot;)<b=
r>(&quot;0.1234&quot;, &quot;1234&quot;, &quot;1234&quot;, &quot;&quot;).Se=
q<br>Nil<br>&gt; dd &quot;0.123451234512345&quot;.split(&quot;5&quot;)<br>(=
&quot;0.1234&quot;, &quot;1234&quot;, &quot;1234&quot;, &quot;&quot;).Seq<b=
r>Nil<br>&gt; my @alpha =3D &quot;aXc&quot;, &quot;dXf&quot;, &quot;gXi&quo=
t;;<br>[aXc dXf gXi]<br>&gt; dd @alpha.split(&quot;X&quot;)<br>(&quot;a&quo=
t;, &quot;c d&quot;, &quot;f g&quot;, &quot;i&quot;).Seq<br>Nil<br>&gt; dd =
@alpha.split(&quot;Y&quot;)<br>(&quot;aXc dXf gXi&quot;,).Seq<br>Nil<br>&gt=
;</div><div><br></div><div><br></div><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);paddin=
g-left:1ex">
Conversely, .join is &quot;a listy cool method&quot; (i just made that up) =
so what<br>
you call it on will be treated as if it were an array. &quot;hello&quot;.jo=
in(&quot;X&quot;)<br>
will pretend you passed [&quot;hello&quot;] and just result in &quot;hello&=
quot; again.<br></blockquote><div><br></div><div>Yes but...you&#39;ve given=
 a nice example where a failed join() gives you back the same input. The sa=
me thing doesn&#39;t happen with split(). Below a failed split() gives you =
back a joined string (one element):<br></div><div><br></div><div>&gt; my @a=
lpha =3D &quot;aXc&quot;, &quot;dXf&quot;, &quot;gXi&quot;;<br>[aXc dXf gXi=
]</div><div>&gt; say @alpha.elems<br>3</div><div>&gt; dd @alpha.split(&quot=
;Y&quot;)<br>(&quot;aXc dXf gXi&quot;,).Seq<br>Nil<br>&gt; say @alpha.split=
(&quot;Y&quot;).elems<br>1<br></div><div><br></div><div><br></div><blockquo=
te class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px =
solid rgb(204,204,204);padding-left:1ex">
Trigonometric methods like sin, cos, tan, are all &quot;numerical cool<br>
methods&quot; so the first thing they do is coerce to Numeric, that&#39;s w=
hy<br>
&quot;99&quot;.tan.say gives you roughly -25.1.<br></blockquote><div>=C2=A0=
</div><div><br></div><div>Brian Duggan posted a short &quot;=CF=80&quot; ar=
ray that&#39;s very nice; I&#39;ve expanded it a bit:</div><div><br></div><=
div>&gt; my @nums =3D 0, =CF=80/2, 1 * =CF=80/2, 2 * =CF=80/2, 3 * =CF=80/2=
, 4 * =CF=80/2;<br>[0 1.5707963267948966 1.5707963267948966 3.1415926535897=
93 4.71238898038469 6.283185307179586]</div><div>&gt; dd @nums.sin<br>-0.27=
941549819892586e0<br>Nil<br>&gt; <br>&gt; my @ints =3D 0..9;<br>[0 1 2 3 4 =
5 6 7 8 9]<br>&gt; dd @ints.log<br>2.302585092994046e0<br>Nil<br>&gt;</div>=
<div><br></div><div>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 e=
lements and I expected 10 elements back. You may perceive an impedence-mism=
atch here, but in my mind, I&#39;ve created an array for the sole purpose o=
f applying the log function to each element of the array. I didn&#39;t use =
a `$`-sigiled scalar. If I wanted the number of elements of the @ints array=
, I would have called &quot;@ints.elems&quot;. But it seems that Raku belie=
ves that I want the log of the length of the @ints array: [ log(10) =3D app=
rox 2.3025 ], when I really wanted the ten numerics:<br></div><div><br>[-In=
f, 0e0, 0.6931471805599453e0, 1.0986122886681098e0, 1.3862943611198906e0, 1=
..6094379124341003e0, 1.791759469228055e0, 1.9459101490553132e0, 2.079441541=
6798357e0, 2.1972245773362196e0]</div><div><br></div><div><br></div><blockq=
uote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1p=
x solid rgb(204,204,204);padding-left:1ex">
Please check out the table near the beginning of this documentation page:<b=
r>
<br>
=C2=A0=C2=A0=C2=A0 <a href=3D"https://docs.raku.org/type/Cool" rel=3D"noref=
errer" target=3D"_blank">https://docs.raku.org/type/Cool</a><br>
<br>
hope that makes things more clear<br>
=C2=A0 - Timo<br></blockquote><div><br></div><div>Thanks to you and Tobias =
for the Docs reference. I certainly tried searching for &quot;split&quot; o=
n <a href=3D"https://docs.raku.org/">https://docs.raku.org/</a> but ended u=
p reading the page below (and not the more general page on &quot;Cool&quot;=
):<br></div><div><br></div><div><a href=3D"https://docs.raku.org/routine/sp=
lit">https://docs.raku.org/routine/split</a></div><div><br></div><div>Thank=
s for all your help Timo! --Best, Bill.<br></div></div></div>

--000000000000fad78e05b17f463f--
0
perl6
10/12/2020 8:37:37 PM
--0000000000007e722d05b1838d5f
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Sat, Oct 10, 2020 at 4:49 PM Tobias Boege <tobs@taboege.de> wrote:

> On Sun, 11 Oct 2020, Tobias Boege wrote:
> > On Sat, 10 Oct 2020, William Michels via perl6-users wrote:
> > > then proceed to process the function call. As it is my understanding
> that
> > > Raku incorporates a lot of different programming paradigms (imperativ=
e,
> > > object-oriented, functional, etc.), I'm not sure where this behavior
> falls
> > > on the 'paradigm ladder'.
> > >
> >
> > If you want to view it as a matter of paradigm, I guess it would be the
> > "operator-centric paradigm", except that it is a method and not an
> operator.
> >
> > The Array class inherits methods from Cool and when you call a method
> from
> > Cool on the Array, the Cool part of the array will answer the call. The
> > Array is Cool to advertise that it can be evaluated in numeric and stri=
ng
> > "context". In string context, the array becomes joined using spaces as
> > delimiters. Put more bluntly: when you treat an array like a string
> > (by calling a string-related method of Cool on it), then Raku treats it
> > as a string, even if it must convert it to one before. [ This may sound
> > magical, but in reality Array just obtains the method .split from Cool
> > and its implementation explicitly converts the invocant, whatever it
> > may be, to a Stringy on which a sensible split is defined. ]
> >
>
> Oh, it seems like I was far too slow. From all the other answers, I think
> Brad put best what I tried to express using many redundant words. And he
> avoided the historically charged and probably inaccurate term "context".
>
> Best,
> Tobias
>


Thank you, Tobias!

user@mbook~$ raku  #test numeric function calls on array
user@mbook~$ raku  #enter REPL
To exit type 'exit' or '^D'
> my @nums =3D 0, =CF=80/2, 3 * =CF=80/2;
[0 1.5707963267948966 4.71238898038469]
> say @nums.elems
3
> say @nums.sin.elems
1
> say @nums.sin
0.1411200080598672
> say @nums.elems.sin
0.1411200080598672
> say sin(3)
0.1411200080598672
> $*VM
moar (2020.06)
>

At first perusal one might conclude that calling .sin on an array
"auto-joins" the arrays elements, but in fact, calling .sin on an array
returns the sin() of the number of array elements. The two calls
"@nums.sin" and "@nums.elems.sin" give exactly the same result.

I'm ignorant of the 'historically charged' use of the term 'context',
although I interpret your comment to suggest that the term 'context' now
may be a disfavored concept. If so, then all the more reason to obviate the
need to explain this concept to new Raku programmers.

--Best, Bill.

--0000000000007e722d05b1838d5f
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">=
<div dir=3D"ltr" class=3D"gmail_attr">On Sat, Oct 10, 2020 at 4:49 PM Tobia=
s Boege &lt;<a href=3D"mailto:tobs@taboege.de" target=3D"_blank">tobs@taboe=
ge.de</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"ma=
rgin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:=
1ex">On Sun, 11 Oct 2020, Tobias Boege wrote:<br>
&gt; On Sat, 10 Oct 2020, William Michels via perl6-users wrote:<br>
&gt; &gt; then proceed to process the function call. As it is my understand=
ing that<br>
&gt; &gt; Raku incorporates a lot of different programming paradigms (imper=
ative,<br>
&gt; &gt; object-oriented, functional, etc.), I&#39;m not sure where this b=
ehavior falls<br>
&gt; &gt; on the &#39;paradigm ladder&#39;.<br>
&gt; &gt; <br>
&gt; <br>
&gt; If you want to view it as a matter of paradigm, I guess it would be th=
e<br>
&gt; &quot;operator-centric paradigm&quot;, except that it is a method and =
not an operator.<br>
&gt; <br>
&gt; The Array class inherits methods from Cool and when you call a method =
from<br>
&gt; Cool on the Array, the Cool part of the array will answer the call. Th=
e<br>
&gt; Array is Cool to advertise that it can be evaluated in numeric and str=
ing<br>
&gt; &quot;context&quot;. In string context, the array becomes joined using=
 spaces as<br>
&gt; delimiters. Put more bluntly: when you treat an array like a string<br=
>
&gt; (by calling a string-related method of Cool on it), then Raku treats i=
t<br>
&gt; as a string, even if it must convert it to one before. [ This may soun=
d<br>
&gt; magical, but in reality Array just obtains the method .split from Cool=
<br>
&gt; and its implementation explicitly converts the invocant, whatever it<b=
r>
&gt; may be, to a Stringy on which a sensible split is defined. ]<br>
&gt; <br>
<br>
Oh, it seems like I was far too slow. From all the other answers, I think<b=
r>
Brad put best what I tried to express using many redundant words. And he<br=
>
avoided the historically charged and probably inaccurate term &quot;context=
&quot;.<br>
<br>
Best,<br>
Tobias<br></blockquote><div><br></div><div>=C2=A0</div><div>Thank you, Tobi=
as!<br></div><div><br></div><div>user@mbook~$ raku =C2=A0#test numeric func=
tion calls on array<br></div><div>user@mbook~$ raku =C2=A0#enter REPL<br>To=
 exit type &#39;exit&#39; or &#39;^D&#39;<br>&gt; my @nums =3D 0, =CF=80/2,=
 3 * =CF=80/2;<br>[0 1.5707963267948966 4.71238898038469]<br>&gt; say @nums=
..elems<br>3<br>&gt; say @nums.sin.elems<br>1</div><div>&gt; say @nums.sin</=
div><div>0.1411200080598672</div><div>&gt; say @nums.elems.sin<br>0.1411200=
080598672</div><div>&gt; say sin(3)<br>0.1411200080598672</div><div>&gt; $*=
VM<br>moar (2020.06)<br>&gt;</div><div><br></div><div>At first perusal one =
might conclude that calling .sin on an array &quot;auto-joins&quot; the arr=
ays elements, but in fact, calling .sin on an array returns the sin() of th=
e number of array elements. The two calls &quot;@nums.sin&quot; and &quot;@=
nums.elems.sin&quot; give exactly the same result. <br></div><div><br></div=
><div>I&#39;m ignorant of the &#39;historically charged&#39; use of the ter=
m &#39;context&#39;, although I interpret your comment to suggest that the =
term &#39;context&#39; now may be a disfavored concept. If so, then all the=
 more reason to obviate the need to explain this concept to new Raku progra=
mmers. <br></div><div><br></div><div>--Best, Bill. <br></div></div></div>

--0000000000007e722d05b1838d5f--
0
perl6
10/13/2020 1:43:40 AM
--0000000000008b6a8205b1858367
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Here's another way of phrasing these answers-

Some routines like "join" operate on strings, and thus coerce their
argument to a string.

Some routines like "sin" operate on numbers, and thus coerce their argument
to a number.

Each class defines how it coerces to Str or Num, regardless of what is
doing the coercing. Array defines its Str coersion as *.join(' ') and its
Num coercion as *.items

Sometimes those coercions are very helpful, like letting "put" write string
representations of all sorts of things with no extra work for the developer=
..

Other times, they are not so helpful, instead be explicit what you want the
routine to work on- don't rely on coercion to the string or num the routine
expects. With arrays, follow Larry's advice and use the >> hyperoperator,
if that's what you want.

There's no "context" in the Perl sense, that history refers to a
"wantarray" built-in where a subroutine would ask if the return value was
assigned to an array or not, and then behave differently. Raku doesn't have
that.
https://docs.raku.org/language/5to6-perlfunc#index-entry-wantarray_-_perlfu=
nc

-y


On Mon, Oct 12, 2020 at 6:44 PM William Michels via perl6-users <
perl6-users@perl.org> wrote:

>
>
> On Sat, Oct 10, 2020 at 4:49 PM Tobias Boege <tobs@taboege.de> wrote:
>
>> On Sun, 11 Oct 2020, Tobias Boege wrote:
>> > On Sat, 10 Oct 2020, William Michels via perl6-users wrote:
>> > > 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'.
>> > >
>> >
>> > If you want to view it as a matter of paradigm, I guess it would be th=
e
>> > "operator-centric paradigm", except that it is a method and not an
>> operator.
>> >
>> > The Array class inherits methods from Cool and when you call a method
>> from
>> > Cool on the Array, the Cool part of the array will answer the call. Th=
e
>> > Array is Cool to advertise that it can be evaluated in numeric and
>> string
>> > "context". In string context, the array becomes joined using spaces as
>> > delimiters. Put more bluntly: when you treat an array like a string
>> > (by calling a string-related method of Cool on it), then Raku treats i=
t
>> > as a string, even if it must convert it to one before. [ This may soun=
d
>> > magical, but in reality Array just obtains the method .split from Cool
>> > and its implementation explicitly converts the invocant, whatever it
>> > may be, to a Stringy on which a sensible split is defined. ]
>> >
>>
>> Oh, it seems like I was far too slow. From all the other answers, I thin=
k
>> Brad put best what I tried to express using many redundant words. And he
>> avoided the historically charged and probably inaccurate term "context".
>>
>> Best,
>> Tobias
>>
>
>
> Thank you, Tobias!
>
> user@mbook~$ raku  #test numeric function calls on array
> user@mbook~$ raku  #enter REPL
> To exit type 'exit' or '^D'
> > my @nums =3D 0, =CF=80/2, 3 * =CF=80/2;
> [0 1.5707963267948966 4.71238898038469]
> > say @nums.elems
> 3
> > say @nums.sin.elems
> 1
> > say @nums.sin
> 0.1411200080598672
> > say @nums.elems.sin
> 0.1411200080598672
> > say sin(3)
> 0.1411200080598672
> > $*VM
> moar (2020.06)
> >
>
> At first perusal one might conclude that calling .sin on an array
> "auto-joins" the arrays elements, but in fact, calling .sin on an array
> returns the sin() of the number of array elements. The two calls
> "@nums.sin" and "@nums.elems.sin" give exactly the same result.
>
> I'm ignorant of the 'historically charged' use of the term 'context',
> although I interpret your comment to suggest that the term 'context' now
> may be a disfavored concept. If so, then all the more reason to obviate t=
he
> need to explain this concept to new Raku programmers.
>
> --Best, Bill.
>

--0000000000008b6a8205b1858367
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr">Here&#39;s another way o=
f phrasing these answers-<div><br></div><div>Some routines like &quot;join&=
quot; operate on strings, and thus coerce their argument to a string.</div>=
<div><br></div><div>Some routines like &quot;sin&quot; operate on numbers, =
and thus coerce their argument to a number.</div><div><br></div><div>Each c=
lass defines how it coerces to Str or Num, regardless of what is doing the =
coercing. Array defines its Str coersion as *.join(&#39; &#39;) and its Num=
=C2=A0coercion=C2=A0as *.items</div><div><br></div><div>Sometimes those coe=
rcions are very helpful, like letting &quot;put&quot; write string represen=
tations of all sorts of things with no extra work for the developer.</div><=
div><br></div><div>Other times, they are not so helpful, instead be explici=
t what you want the routine to work on- don&#39;t rely on coercion to the s=
tring or num the routine expects. With arrays, follow Larry&#39;s advice an=
d use the &gt;&gt; hyperoperator, if that&#39;s what you want. </div><div><=
br></div><div>There&#39;s no &quot;context&quot; in the Perl sense, that hi=
story refers to a &quot;wantarray&quot; built-in where a subroutine would a=
sk if the return value was assigned to an array or not, and then behave dif=
ferently. Raku doesn&#39;t have that.=C2=A0<a href=3D"https://docs.raku.org=
/language/5to6-perlfunc#index-entry-wantarray_-_perlfunc">https://docs.raku=
..org/language/5to6-perlfunc#index-entry-wantarray_-_perlfunc</a></div><div>=
<br clear=3D"all"><div><div dir=3D"ltr" class=3D"gmail_signature">-y<br></d=
iv></div><br></div></div></div></div><br><div class=3D"gmail_quote"><div di=
r=3D"ltr" class=3D"gmail_attr">On Mon, Oct 12, 2020 at 6:44 PM William Mich=
els via perl6-users &lt;<a href=3D"mailto:perl6-users@perl.org">perl6-users=
@perl.org</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;=
border-left-color:rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div =
dir=3D"ltr"><br></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=
=3D"gmail_attr">On Sat, Oct 10, 2020 at 4:49 PM Tobias Boege &lt;<a href=3D=
"mailto:tobs@taboege.de" target=3D"_blank">tobs@taboege.de</a>&gt; wrote:<b=
r></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex=
;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,20=
4,204);padding-left:1ex">On Sun, 11 Oct 2020, Tobias Boege wrote:<br>
&gt; On Sat, 10 Oct 2020, William Michels via perl6-users wrote:<br>
&gt; &gt; then proceed to process the function call. As it is my understand=
ing that<br>
&gt; &gt; Raku incorporates a lot of different programming paradigms (imper=
ative,<br>
&gt; &gt; object-oriented, functional, etc.), I&#39;m not sure where this b=
ehavior falls<br>
&gt; &gt; on the &#39;paradigm ladder&#39;.<br>
&gt; &gt; <br>
&gt; <br>
&gt; If you want to view it as a matter of paradigm, I guess it would be th=
e<br>
&gt; &quot;operator-centric paradigm&quot;, except that it is a method and =
not an operator.<br>
&gt; <br>
&gt; The Array class inherits methods from Cool and when you call a method =
from<br>
&gt; Cool on the Array, the Cool part of the array will answer the call. Th=
e<br>
&gt; Array is Cool to advertise that it can be evaluated in numeric and str=
ing<br>
&gt; &quot;context&quot;. In string context, the array becomes joined using=
 spaces as<br>
&gt; delimiters. Put more bluntly: when you treat an array like a string<br=
>
&gt; (by calling a string-related method of Cool on it), then Raku treats i=
t<br>
&gt; as a string, even if it must convert it to one before. [ This may soun=
d<br>
&gt; magical, but in reality Array just obtains the method .split from Cool=
<br>
&gt; and its implementation explicitly converts the invocant, whatever it<b=
r>
&gt; may be, to a Stringy on which a sensible split is defined. ]<br>
&gt; <br>
<br>
Oh, it seems like I was far too slow. From all the other answers, I think<b=
r>
Brad put best what I tried to express using many redundant words. And he<br=
>
avoided the historically charged and probably inaccurate term &quot;context=
&quot;.<br>
<br>
Best,<br>
Tobias<br></blockquote><div><br></div><div>=C2=A0</div><div>Thank you, Tobi=
as!<br></div><div><br></div><div>user@mbook~$ raku =C2=A0#test numeric func=
tion calls on array<br></div><div>user@mbook~$ raku =C2=A0#enter REPL<br>To=
 exit type &#39;exit&#39; or &#39;^D&#39;<br>&gt; my @nums =3D 0, =CF=80/2,=
 3 * =CF=80/2;<br>[0 1.5707963267948966 4.71238898038469]<br>&gt; say @nums=
..elems<br>3<br>&gt; say @nums.sin.elems<br>1</div><div>&gt; say @nums.sin</=
div><div>0.1411200080598672</div><div>&gt; say @nums.elems.sin<br>0.1411200=
080598672</div><div>&gt; say sin(3)<br>0.1411200080598672</div><div>&gt; $*=
VM<br>moar (2020.06)<br>&gt;</div><div><br></div><div>At first perusal one =
might conclude that calling .sin on an array &quot;auto-joins&quot; the arr=
ays elements, but in fact, calling .sin on an array returns the sin() of th=
e number of array elements. The two calls &quot;@nums.sin&quot; and &quot;@=
nums.elems.sin&quot; give exactly the same result. <br></div><div><br></div=
><div>I&#39;m ignorant of the &#39;historically charged&#39; use of the ter=
m &#39;context&#39;, although I interpret your comment to suggest that the =
term &#39;context&#39; now may be a disfavored concept. If so, then all the=
 more reason to obviate the need to explain this concept to new Raku progra=
mmers. <br></div><div><br></div><div>--Best, Bill. <br></div></div></div>
</blockquote></div>

--0000000000008b6a8205b1858367--
0
not
10/13/2020 4:04:28 AM
On Mon, Oct 12, 2020 at 10:02 AM Larry Wall <larry@wall.org> wrote:
>
> On Mon, Oct 12, 2020 at 01:14:09PM -0300, Aureliano Guedes wrote:
> : > This seems pretty convenient and intuitive.  At least, it is possible
> : > to mimic that behavior in Raku:
> : >
> : >         List.^find_method('split').wrap: { $^a.map: *.split($^b) }
> : >         List.^find_method('sin').wrap: *.map: *.sin;
> : >
> : This is like overwrite the function?
> : Might be better just implement a new function, I mean, a new verb as is
> : called in R.
>
> In Raku these functions already have names, if you count metaoperators as=
 a fancy
> way to name anonymous functions:
>
>     say <a,b c,d>=C2=BB.split(',');
>     say (0, (=CF=80/2, 3 * =CF=80/2))=C2=BB.sin;
>
>     ((a b) (c d))
>     (0 (1 -1))
>
> As shown by the =C2=BB.sin example, unary hypers will distribute over
> multi-dimensional structures for you, just as an APL or R programmer
> would expect.  But that behavior is not intuitively obvious to everyone,
> so the vector-processing paradigm is not the default.  (But we make it
> really easy to get to when you want it, as you can see.  And arguably
> the explicit presence of =C2=BB or >> makes your intent clearer to the na=
=C3=AFve
> reader, who at least has something to look up or ask about if they don't
> understand it.)
>
> Larry

Hi Larry!

First of all, let me thank you for designing the Raku (n=C3=A9e Perl6)
programming language in the first place. I've really enjoyed learning
a different set of programming paradigms than I was previously
accustomed to.

With regards to the present topic, what initially 'disunited' me was
calling split() on an a array and ending up with joined elements. It
becomes most apparent when one tries to split() on a character that
isn't present in the array in the first place--in that case, all array
elements are joined into a single string. It has been explained to me
that arrays coercible to strings and called with a string-function
*are* auto-joined with a single space as separator, but it would be
nice to control this behavior somewhat, e.g. for generating a CSV line
(join on commas instead of spaces).

However. I guess the real question in my mind is how to predict which
function "verbs" will work on array "nouns" in plural form (I'm daring
here to discuss linguistics with a linguist). Certainly we know nouns
that remain invariant from singular to plural (sheep, fish, deer,
salmon, aircraft and other -craft, etc.). These nouns exist and don't
seem to be going away anytime soon. I can say "Eels fill my
hovercraft," and that one statement applies to both singular and
plural hovercraft. But swapping the statement around to the more
familiar, we clearly see the verb lets us know whether hovercraft is
used in the sigular or plural: "My hovercraft is/are full of eels."

Thinking of Raku arrays as invariant nouns, I might wonder which
"verb" functions denote acting on a 'singular' array (acting on the
array as a whole) versus acting on a 'plural' array (i.e. acting
element-by-element). Without consulting the Docs, in regards to
functions acting wholly or primarily on strings, I might guess that
the 'grep()' verb acts on a 'singular' array. From my previous posts
you can gather I guessed that split() acts element-by-element on a
'plural' array (along with many other string functions). Without
consulting the Docs, in regards to numeric-functions I might guess
that the sum() verb and any 'mean()' verb would act on a 'singular'
array, and I'd guess that most other numeric functions like log() and
sin() would act element-by-element on a 'plural' array. This could be
completely off-base, and a consequence of sum() or mean() being
'many-to-one' functions, while log() and sin() etc. have a 1-to-1
input/output correspondence.

Now maybe this is a road that has been trodden before, with Perl. Or
maybe it's my own linguistic preconceptions getting in the way. But I
really do hope to understand why the Raku language is designed the way
it is designed.

Thanks, Bill.

> #REPL code below:
Nil
> my @monsters =3D << blob 'king kong' mothera fingfangfoom >>;
[blob king kong mothera fingfangfoom]
> dd @monsters
Array @monsters =3D ["blob", "king kong", "mothera", "fingfangfoom"]
Nil
> @monsters.grep(/" "/);
(king kong)
> @monsters>>.grep(/" "/);
(() (king kong) () ())
> dd @monsters.split(" ");
("blob", "king", "kong", "mothera", "fingfangfoom").Seq
Nil
> dd @monsters>>.split(" ");
Array element =3D [("blob",).Seq, ("king", "kong").Seq,
("mothera",).Seq, ("fingfangfoom",).Seq]
Nil
> my @nums =3D 0,1,2,3,4,5,6,7,8,9;
[0 1 2 3 4 5 6 7 8 9]
> dd @nums
Array @nums =3D [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Nil
> dd @nums.sum
45
Nil
> dd @nums>>.sum
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
Nil
> dd @nums.log
2.302585092994046e0
Nil
> dd @nums>>.log
Array element =3D [-Inf, 0e0, 0.6931471805599453e0,
1.0986122886681098e0, 1.3862943611198906e0, 1.6094379124341003e0,
1.791759469228055e0, 1.9459101490553132e0, 2.0794415416798357e0,
2.1972245773362196e0]
Nil
>

https://dictionary.cambridge.org/us/grammar/british-grammar/nouns-form?q=3D=
Forming+the+plural+of+nouns
https://www.lexico.com/grammar/matching-verbs-to-collective-nouns
https://dictionary.cambridge.org/us/grammar/british-grammar/nouns-singular-=
and-plural?q=3DCollective+nouns+%28group+words%29
https://www.lexico.com/grammar/plural-nouns-treated-as-singular
https://omniglot.com/language/phrases/hovercraft.htm
https://www.theguardian.com/notesandqueries/query/0,,-197456,00.html
0
perl6
10/14/2020 6:26:56 AM
--00000000000051a45405b1a0528e
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

I'd like to help with my 2 cents.

Given your comparison with R, sum, and mean are expected to play with a
vector rather than log and sin are expected to play with single numbers.
Then, the expected behavior for numerics types in Raku still the same as in
R. The difference is only that the functions in Raku are designed to one
and only one single function.

#RAKU
> my @nums =3D 0,1,2,3,4,5,6,7,8,9;
[0 1 2 3 4 5 6 7 8 9]
> @nums.sum
45
> sum(@nums)
45

#R
> library(tidyverse) #import pipe %>%
> nums <- 0:9
> nums
 [1] 0 1 2 3 4 5 6 7 8 9
> sum(nums)
[1] 45
> nums %>% sum()
[1] 45
> nums %>% log
 [1]      -Inf 0.0000000 0.6931472 1.0986123 1.3862944 1.6094379 1.7917595
 [8] 1.9459101 2.0794415 2.1972246
> log(nums)
 [1]      -Inf 0.0000000 0.6931472 1.0986123 1.3862944 1.6094379 1.7917595
 [8] 1.9459101 2.0794415 2.1972246


In this point, the unique weirdness I'd like to understand is why in Raku
`@nums.log =3D=3D 2.302585092994046e0`. I don't understand where this value
comes from.

In the case of strings, pay attention to the size of the array. The infix
`>>` act as expected keeping the vector with the same size, which is the
default behavior of R, since it is functional and vectorization is arguably
its philosophy which handles very well data analysis which is its purpose.

> @monsters>>.split(" ").elems
5
> @monsters.split(" ").elems
7
> my @monsters =3D << blob 'king kong' mothera fingfangfoom 'foo bar'>>;
[blob king kong mothera fingfangfoom foo bar]
> @monsters.elems
5
> @monsters.split(" ")
(blob king kong mothera fingfangfoom foo bar)
> @monsters.split(" ").elems
7
> @monsters>>.split(" ")
[(blob) (king kong) (mothera) (fingfangfoom) (foo bar)]
> @monsters>>.split(" ").elems
5

The point is, I don't know why Raku is designed the way it is. But is
easier to implement in Raku the use of functional and vectorized paradigms
than in Python which requires an external lib (e.g. Pandas or numpy).

Of course, it might be better if Raku has docs explain the paradigms and
philosophy behind the scenes and very didactic and well-explained docs as
Perl5. Also, coping R, might be too inviting to learners and seniors if we
had online handbooks, wiki-style docs, and cheat sheets as we have in R.

best

On Wed, Oct 14, 2020 at 3:28 AM William Michels via perl6-users <
perl6-users@perl.org> wrote:

> On Mon, Oct 12, 2020 at 10:02 AM Larry Wall <larry@wall.org> wrote:
> >
> > On Mon, Oct 12, 2020 at 01:14:09PM -0300, Aureliano Guedes wrote:
> > : > This seems pretty convenient and intuitive.  At least, it is possib=
le
> > : > to mimic that behavior in Raku:
> > : >
> > : >         List.^find_method('split').wrap: { $^a.map: *.split($^b) }
> > : >         List.^find_method('sin').wrap: *.map: *.sin;
> > : >
> > : This is like overwrite the function?
> > : Might be better just implement a new function, I mean, a new verb as =
is
> > : called in R.
> >
> > In Raku these functions already have names, if you count metaoperators
> as a fancy
> > way to name anonymous functions:
> >
> >     say <a,b c,d>=C2=BB.split(',');
> >     say (0, (=CF=80/2, 3 * =CF=80/2))=C2=BB.sin;
> >
> >     ((a b) (c d))
> >     (0 (1 -1))
> >
> > As shown by the =C2=BB.sin example, unary hypers will distribute over
> > multi-dimensional structures for you, just as an APL or R programmer
> > would expect.  But that behavior is not intuitively obvious to everyone=
,
> > so the vector-processing paradigm is not the default.  (But we make it
> > really easy to get to when you want it, as you can see.  And arguably
> > the explicit presence of =C2=BB or >> makes your intent clearer to the =
na=C3=AFve
> > reader, who at least has something to look up or ask about if they don'=
t
> > understand it.)
> >
> > Larry
>
> Hi Larry!
>
> First of all, let me thank you for designing the Raku (n=C3=A9e Perl6)
> programming language in the first place. I've really enjoyed learning
> a different set of programming paradigms than I was previously
> accustomed to.
>
> With regards to the present topic, what initially 'disunited' me was
> calling split() on an a array and ending up with joined elements. It
> becomes most apparent when one tries to split() on a character that
> isn't present in the array in the first place--in that case, all array
> elements are joined into a single string. It has been explained to me
> that arrays coercible to strings and called with a string-function
> *are* auto-joined with a single space as separator, but it would be
> nice to control this behavior somewhat, e.g. for generating a CSV line
> (join on commas instead of spaces).
>
> However. I guess the real question in my mind is how to predict which
> function "verbs" will work on array "nouns" in plural form (I'm daring
> here to discuss linguistics with a linguist). Certainly we know nouns
> that remain invariant from singular to plural (sheep, fish, deer,
> salmon, aircraft and other -craft, etc.). These nouns exist and don't
> seem to be going away anytime soon. I can say "Eels fill my
> hovercraft," and that one statement applies to both singular and
> plural hovercraft. But swapping the statement around to the more
> familiar, we clearly see the verb lets us know whether hovercraft is
> used in the sigular or plural: "My hovercraft is/are full of eels."
>
> Thinking of Raku arrays as invariant nouns, I might wonder which
> "verb" functions denote acting on a 'singular' array (acting on the
> array as a whole) versus acting on a 'plural' array (i.e. acting
> element-by-element). Without consulting the Docs, in regards to
> functions acting wholly or primarily on strings, I might guess that
> the 'grep()' verb acts on a 'singular' array. From my previous posts
> you can gather I guessed that split() acts element-by-element on a
> 'plural' array (along with many other string functions). Without
> consulting the Docs, in regards to numeric-functions I might guess
> that the sum() verb and any 'mean()' verb would act on a 'singular'
> array, and I'd guess that most other numeric functions like log() and
> sin() would act element-by-element on a 'plural' array. This could be
> completely off-base, and a consequence of sum() or mean() being
> 'many-to-one' functions, while log() and sin() etc. have a 1-to-1
> input/output correspondence.
>
> Now maybe this is a road that has been trodden before, with Perl. Or
> maybe it's my own linguistic preconceptions getting in the way. But I
> really do hope to understand why the Raku language is designed the way
> it is designed.
>
> Thanks, Bill.
>
> > #REPL code below:
> Nil
> > my @monsters =3D << blob 'king kong' mothera fingfangfoom >>;
> [blob king kong mothera fingfangfoom]
> > dd @monsters
> Array @monsters =3D ["blob", "king kong", "mothera", "fingfangfoom"]
> Nil
> > @monsters.grep(/" "/);
> (king kong)
> > @monsters>>.grep(/" "/);
> (() (king kong) () ())
> > dd @monsters.split(" ");
> ("blob", "king", "kong", "mothera", "fingfangfoom").Seq
> Nil
> > dd @monsters>>.split(" ");
> Array element =3D [("blob",).Seq, ("king", "kong").Seq,
> ("mothera",).Seq, ("fingfangfoom",).Seq]
> Nil
> > my @nums =3D 0,1,2,3,4,5,6,7,8,9;
> [0 1 2 3 4 5 6 7 8 9]
> > dd @nums
> Array @nums =3D [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
> Nil
> > dd @nums.sum
> 45
> Nil
> > dd @nums>>.sum
> (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
> Nil
> > dd @nums.log
> 2.302585092994046e0
> Nil
> > dd @nums>>.log
> Array element =3D [-Inf, 0e0, 0.6931471805599453e0,
> 1.0986122886681098e0, 1.3862943611198906e0, 1.6094379124341003e0,
> 1.791759469228055e0, 1.9459101490553132e0, 2.0794415416798357e0,
> 2.1972245773362196e0]
> Nil
> >
>
>
> https://dictionary.cambridge.org/us/grammar/british-grammar/nouns-form?q=
=3DForming+the+plural+of+nouns
> https://www.lexico.com/grammar/matching-verbs-to-collective-nouns
>
> https://dictionary.cambridge.org/us/grammar/british-grammar/nouns-singula=
r-and-plural?q=3DCollective+nouns+%28group+words%29
> https://www.lexico.com/grammar/plural-nouns-treated-as-singular
> https://omniglot.com/language/phrases/hovercraft.htm
> https://www.theguardian.com/notesandqueries/query/0,,-197456,00.html
>


--=20
Aureliano Guedes
skype: aureliano.guedes
contato:  (11) 94292-6110
whatsapp +5511942926110

--00000000000051a45405b1a0528e
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I&#39;d like to help with my 2 cents.<div><br></div><div>G=
iven your comparison with R, sum, and mean are expected to play with a vect=
or rather than log and sin are expected to play with single numbers. Then, =
the expected behavior for numerics types in Raku still the same as in R. Th=
e difference is only that the functions in Raku are designed to one and onl=
y one single function.</div><div><br></div><div>#RAKU</div><div>&gt; my @nu=
ms =3D 0,1,2,3,4,5,6,7,8,9;<br>[0 1 2 3 4 5 6 7 8 9]<br>&gt; @nums.sum<br>4=
5<br>&gt; sum(@nums)<br>45<br></div><div><br></div><div>#R</div><div>&gt; l=
ibrary(tidyverse) #import pipe %&gt;%</div><div>&gt; nums &lt;- 0:9<br></di=
v><div>&gt; nums<br>=C2=A0[1] 0 1 2 3 4 5 6 7 8 9<br>&gt; sum(nums)<br>[1] =
45<br></div><div>&gt; nums %&gt;% sum()<br>[1] 45<br>&gt; nums %&gt;% log<b=
r>=C2=A0[1] =C2=A0 =C2=A0 =C2=A0-Inf 0.0000000 0.6931472 1.0986123 1.386294=
4 1.6094379 1.7917595<br>=C2=A0[8] 1.9459101 2.0794415 2.1972246<br>&gt; lo=
g(nums)<br>=C2=A0[1] =C2=A0 =C2=A0 =C2=A0-Inf 0.0000000 0.6931472 1.0986123=
 1.3862944 1.6094379 1.7917595<br>=C2=A0[8] 1.9459101 2.0794415 2.1972246<b=
r></div><div><br></div><div><br></div><div>In this point, the unique weirdn=
ess=C2=A0I&#39;d like to understand is why in Raku `@nums.log =3D=3D 2.3025=
85092994046e0`. I don&#39;t understand where this value comes from.</div><d=
iv><br></div><div>In the case of strings, pay attention to the size of the =
array. The infix `&gt;&gt;` act as expected keeping the vector with the sam=
e size, which is the default behavior of R, since it is functional and vect=
orization is arguably its philosophy which handles very well data analysis =
which is its purpose.=C2=A0</div><div><br></div><div>&gt; @monsters&gt;&gt;=
..split(&quot; &quot;).elems<br>5<br>&gt; @monsters.split(&quot; &quot;).ele=
ms<br>7<br>&gt; my @monsters =3D &lt;&lt; blob &#39;king kong&#39; mothera =
fingfangfoom &#39;foo bar&#39;&gt;&gt;;<br>[blob king kong mothera fingfang=
foom foo bar]<br>&gt; @monsters.elems<br>5<br>&gt; @monsters.split(&quot; &=
quot;)<br>(blob king kong mothera fingfangfoom foo bar)<br>&gt; @monsters.s=
plit(&quot; &quot;).elems<br>7<br>&gt; @monsters&gt;&gt;.split(&quot; &quot=
;)<br>[(blob) (king kong) (mothera) (fingfangfoom) (foo bar)]<br>&gt; @mons=
ters&gt;&gt;.split(&quot; &quot;).elems<br>5<br></div><div><br></div><div>T=
he point is, I don&#39;t know why Raku is designed the way it is. But is ea=
sier to implement in Raku the use of functional and vectorized paradigms th=
an in Python which requires an external lib (e.g. Pandas or numpy).</div><d=
iv><br></div><div>Of course, it might be better if Raku has docs explain th=
e paradigms and philosophy behind the scenes and very didactic and well-exp=
lained docs as Perl5. Also, coping R, might be too inviting to learners and=
 seniors if we had online handbooks, wiki-style docs, and cheat sheets as w=
e have in R.</div><div><br></div><div>best</div></div><br><div class=3D"gma=
il_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Wed, Oct 14, 2020 at 3:2=
8 AM William Michels via perl6-users &lt;<a href=3D"mailto:perl6-users@perl=
..org">perl6-users@perl.org</a>&gt; wrote:<br></div><blockquote class=3D"gma=
il_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,2=
04,204);padding-left:1ex">On Mon, Oct 12, 2020 at 10:02 AM Larry Wall &lt;<=
a href=3D"mailto:larry@wall.org" target=3D"_blank">larry@wall.org</a>&gt; w=
rote:<br>
&gt;<br>
&gt; On Mon, Oct 12, 2020 at 01:14:09PM -0300, Aureliano Guedes wrote:<br>
&gt; : &gt; This seems pretty convenient and intuitive.=C2=A0 At least, it =
is possible<br>
&gt; : &gt; to mimic that behavior in Raku:<br>
&gt; : &gt;<br>
&gt; : &gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0List.^find_method(&#39;split&#=
39;).wrap: { $^a.map: *.split($^b) }<br>
&gt; : &gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0List.^find_method(&#39;sin&#39=
;).wrap: *.map: *.sin;<br>
&gt; : &gt;<br>
&gt; : This is like overwrite the function?<br>
&gt; : Might be better just implement a new function, I mean, a new verb as=
 is<br>
&gt; : called in R.<br>
&gt;<br>
&gt; In Raku these functions already have names, if you count metaoperators=
 as a fancy<br>
&gt; way to name anonymous functions:<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0say &lt;a,b c,d&gt;=C2=BB.split(&#39;,&#39;);<br>
&gt;=C2=A0 =C2=A0 =C2=A0say (0, (=CF=80/2, 3 * =CF=80/2))=C2=BB.sin;<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0((a b) (c d))<br>
&gt;=C2=A0 =C2=A0 =C2=A0(0 (1 -1))<br>
&gt;<br>
&gt; As shown by the =C2=BB.sin example, unary hypers will distribute over<=
br>
&gt; multi-dimensional structures for you, just as an APL or R programmer<b=
r>
&gt; would expect.=C2=A0 But that behavior is not intuitively obvious to ev=
eryone,<br>
&gt; so the vector-processing paradigm is not the default.=C2=A0 (But we ma=
ke it<br>
&gt; really easy to get to when you want it, as you can see.=C2=A0 And argu=
ably<br>
&gt; the explicit presence of =C2=BB or &gt;&gt; makes your intent clearer =
to the na=C3=AFve<br>
&gt; reader, who at least has something to look up or ask about if they don=
&#39;t<br>
&gt; understand it.)<br>
&gt;<br>
&gt; Larry<br>
<br>
Hi Larry!<br>
<br>
First of all, let me thank you for designing the Raku (n=C3=A9e Perl6)<br>
programming language in the first place. I&#39;ve really enjoyed learning<b=
r>
a different set of programming paradigms than I was previously<br>
accustomed to.<br>
<br>
With regards to the present topic, what initially &#39;disunited&#39; me wa=
s<br>
calling split() on an a array and ending up with joined elements. It<br>
becomes most apparent when one tries to split() on a character that<br>
isn&#39;t present in the array in the first place--in that case, all array<=
br>
elements are joined into a single string. It has been explained to me<br>
that arrays coercible to strings and called with a string-function<br>
*are* auto-joined with a single space as separator, but it would be<br>
nice to control this behavior somewhat, e.g. for generating a CSV line<br>
(join on commas instead of spaces).<br>
<br>
However. I guess the real question in my mind is how to predict which<br>
function &quot;verbs&quot; will work on array &quot;nouns&quot; in plural f=
orm (I&#39;m daring<br>
here to discuss linguistics with a linguist). Certainly we know nouns<br>
that remain invariant from singular to plural (sheep, fish, deer,<br>
salmon, aircraft and other -craft, etc.). These nouns exist and don&#39;t<b=
r>
seem to be going away anytime soon. I can say &quot;Eels fill my<br>
hovercraft,&quot; and that one statement applies to both singular and<br>
plural hovercraft. But swapping the statement around to the more<br>
familiar, we clearly see the verb lets us know whether hovercraft is<br>
used in the sigular or plural: &quot;My hovercraft is/are full of eels.&quo=
t;<br>
<br>
Thinking of Raku arrays as invariant nouns, I might wonder which<br>
&quot;verb&quot; functions denote acting on a &#39;singular&#39; array (act=
ing on the<br>
array as a whole) versus acting on a &#39;plural&#39; array (i.e. acting<br=
>
element-by-element). Without consulting the Docs, in regards to<br>
functions acting wholly or primarily on strings, I might guess that<br>
the &#39;grep()&#39; verb acts on a &#39;singular&#39; array. From my previ=
ous posts<br>
you can gather I guessed that split() acts element-by-element on a<br>
&#39;plural&#39; array (along with many other string functions). Without<br=
>
consulting the Docs, in regards to numeric-functions I might guess<br>
that the sum() verb and any &#39;mean()&#39; verb would act on a &#39;singu=
lar&#39;<br>
array, and I&#39;d guess that most other numeric functions like log() and<b=
r>
sin() would act element-by-element on a &#39;plural&#39; array. This could =
be<br>
completely off-base, and a consequence of sum() or mean() being<br>
&#39;many-to-one&#39; functions, while log() and sin() etc. have a 1-to-1<b=
r>
input/output correspondence.<br>
<br>
Now maybe this is a road that has been trodden before, with Perl. Or<br>
maybe it&#39;s my own linguistic preconceptions getting in the way. But I<b=
r>
really do hope to understand why the Raku language is designed the way<br>
it is designed.<br>
<br>
Thanks, Bill.<br>
<br>
&gt; #REPL code below:<br>
Nil<br>
&gt; my @monsters =3D &lt;&lt; blob &#39;king kong&#39; mothera fingfangfoo=
m &gt;&gt;;<br>
[blob king kong mothera fingfangfoom]<br>
&gt; dd @monsters<br>
Array @monsters =3D [&quot;blob&quot;, &quot;king kong&quot;, &quot;mothera=
&quot;, &quot;fingfangfoom&quot;]<br>
Nil<br>
&gt; @monsters.grep(/&quot; &quot;/);<br>
(king kong)<br>
&gt; @monsters&gt;&gt;.grep(/&quot; &quot;/);<br>
(() (king kong) () ())<br>
&gt; dd @monsters.split(&quot; &quot;);<br>
(&quot;blob&quot;, &quot;king&quot;, &quot;kong&quot;, &quot;mothera&quot;,=
 &quot;fingfangfoom&quot;).Seq<br>
Nil<br>
&gt; dd @monsters&gt;&gt;.split(&quot; &quot;);<br>
Array element =3D [(&quot;blob&quot;,).Seq, (&quot;king&quot;, &quot;kong&q=
uot;).Seq,<br>
(&quot;mothera&quot;,).Seq, (&quot;fingfangfoom&quot;,).Seq]<br>
Nil<br>
&gt; my @nums =3D 0,1,2,3,4,5,6,7,8,9;<br>
[0 1 2 3 4 5 6 7 8 9]<br>
&gt; dd @nums<br>
Array @nums =3D [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]<br>
Nil<br>
&gt; dd @nums.sum<br>
45<br>
Nil<br>
&gt; dd @nums&gt;&gt;.sum<br>
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)<br>
Nil<br>
&gt; dd @nums.log<br>
2.302585092994046e0<br>
Nil<br>
&gt; dd @nums&gt;&gt;.log<br>
Array element =3D [-Inf, 0e0, 0.6931471805599453e0,<br>
1.0986122886681098e0, 1.3862943611198906e0, 1.6094379124341003e0,<br>
1.791759469228055e0, 1.9459101490553132e0, 2.0794415416798357e0,<br>
2.1972245773362196e0]<br>
Nil<br>
&gt;<br>
<br>
<a href=3D"https://dictionary.cambridge.org/us/grammar/british-grammar/noun=
s-form?q=3DForming+the+plural+of+nouns" rel=3D"noreferrer" target=3D"_blank=
">https://dictionary.cambridge.org/us/grammar/british-grammar/nouns-form?q=
=3DForming+the+plural+of+nouns</a><br>
<a href=3D"https://www.lexico.com/grammar/matching-verbs-to-collective-noun=
s" rel=3D"noreferrer" target=3D"_blank">https://www.lexico.com/grammar/matc=
hing-verbs-to-collective-nouns</a><br>
<a href=3D"https://dictionary.cambridge.org/us/grammar/british-grammar/noun=
s-singular-and-plural?q=3DCollective+nouns+%28group+words%29" rel=3D"norefe=
rrer" target=3D"_blank">https://dictionary.cambridge.org/us/grammar/british=
-grammar/nouns-singular-and-plural?q=3DCollective+nouns+%28group+words%29</=
a><br>
<a href=3D"https://www.lexico.com/grammar/plural-nouns-treated-as-singular"=
 rel=3D"noreferrer" target=3D"_blank">https://www.lexico.com/grammar/plural=
-nouns-treated-as-singular</a><br>
<a href=3D"https://omniglot.com/language/phrases/hovercraft.htm" rel=3D"nor=
eferrer" target=3D"_blank">https://omniglot.com/language/phrases/hovercraft=
..htm</a><br>
<a href=3D"https://www.theguardian.com/notesandqueries/query/0,,-197456,00.=
html" rel=3D"noreferrer" target=3D"_blank">https://www.theguardian.com/note=
sandqueries/query/0,,-197456,00.html</a><br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"gmail_signature"><div dir=3D"ltr"><div><div dir=3D"ltr"><div><div=
 dir=3D"ltr"><div><div dir=3D"ltr"><div style=3D"text-align:center">Aurelia=
no Guedes</div><div style=3D"text-align:center"></div><div style=3D"text-al=
ign:center">skype: aureliano.guedes</div><div style=3D"text-align:center">c=
ontato: =C2=A0(11) 94292-6110</div><div style=3D"text-align:center">whatsap=
p +5511942926110</div></div></div></div></div></div></div></div></div>

--00000000000051a45405b1a0528e--
0
guedes
10/14/2020 12:03:25 PM
On Wednesday, October 14, Aureliano Guedes wrote: 
> In this point, the unique weirdness I'd like to understand is why in Raku
> `@nums.log == 2.302585092994046e0`. I don't understand where this value
> comes from.

This comes from the length of the array; the array is coerced into a numeric
value:

  > my @nums = 1..10
  [1 2 3 4 5 6 7 8 9 10]
  > @nums.log
  2.302585092994046
  > @nums.Numeric.log
  2.302585092994046
  > 10.log
  2.302585092994046

Brian
0
bduggan
10/14/2020 3:01:11 PM
--000000000000df028c05b1a52ece
Content-Type: text/plain; charset="UTF-8"

Oh, thanks, now it makes sense.

On Wed, Oct 14, 2020 at 12:01 PM Brian Duggan <bduggan@matatu.org> wrote:

> On Wednesday, October 14, Aureliano Guedes wrote:
> > In this point, the unique weirdness I'd like to understand is why in Raku
> > `@nums.log == 2.302585092994046e0`. I don't understand where this value
> > comes from.
>
> This comes from the length of the array; the array is coerced into a
> numeric
> value:
>
>   > my @nums = 1..10
>   [1 2 3 4 5 6 7 8 9 10]
>   > @nums.log
>   2.302585092994046
>   > @nums.Numeric.log
>   2.302585092994046
>   > 10.log
>   2.302585092994046
>
> Brian
>


-- 
Aureliano Guedes
skype: aureliano.guedes
contato:  (11) 94292-6110
whatsapp +5511942926110

--000000000000df028c05b1a52ece
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Oh, thanks, now it makes sense.<br></div><br><div class=3D=
"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Wed, Oct 14, 2020 at=
 12:01 PM Brian Duggan &lt;<a href=3D"mailto:bduggan@matatu.org">bduggan@ma=
tatu.org</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D=
"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-le=
ft:1ex">On Wednesday, October 14, Aureliano Guedes wrote: <br>
&gt; In this point, the unique weirdness I&#39;d like to understand is why =
in Raku<br>
&gt; `@nums.log =3D=3D 2.302585092994046e0`. I don&#39;t understand where t=
his value<br>
&gt; comes from.<br>
<br>
This comes from the length of the array; the array is coerced into a numeri=
c<br>
value:<br>
<br>
=C2=A0 &gt; my @nums =3D 1..10<br>
=C2=A0 [1 2 3 4 5 6 7 8 9 10]<br>
=C2=A0 &gt; @nums.log<br>
=C2=A0 2.302585092994046<br>
=C2=A0 &gt; @nums.Numeric.log<br>
=C2=A0 2.302585092994046<br>
=C2=A0 &gt; 10.log<br>
=C2=A0 2.302585092994046<br>
<br>
Brian<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"gmail_signature"><div dir=3D"ltr"><div><div dir=3D"ltr"><div><div=
 dir=3D"ltr"><div><div dir=3D"ltr"><div style=3D"text-align:center">Aurelia=
no Guedes</div><div style=3D"text-align:center"></div><div style=3D"text-al=
ign:center">skype: aureliano.guedes</div><div style=3D"text-align:center">c=
ontato: =C2=A0(11) 94292-6110</div><div style=3D"text-align:center">whatsap=
p +5511942926110</div></div></div></div></div></div></div></div></div>

--000000000000df028c05b1a52ece--
0
guedes
10/14/2020 5:51:26 PM
Dear Brad,
Thank you so much for taking the time to reply!
I wrote a few notes inline, below:

On Sat, Oct 10, 2020 at 4:07 PM Brad Gilbert <b2gills@gmail.com> wrote:
>
> Functions in Raku tend to have one job and one job only.
>
> `split` splits a string.
>
> So if you call `split` on something that is not a string it gets turned into one if it can.
>
> This happens for most functions.
>
> Having `split` be the only function that auto-vectorizes against an array would be very confusing.

I think the question I have is why string "auto-joining" is
proverbially so 'high-up on the food chain'. I've understood that Perl
(and by extension, Raku) has historically been a 'list-processing"
language--that the language is centered on lists. So I expected that
if you call a function on a single-element scalar, the function acts
on that one element. I expected that if you call a function on a
multi-element list, the function acts on every single element
individually. (Obviously I'm glossing over the differences between
Raku's multi-element $-sigilled scalars and @-sigilled arrays).

> If it isn't the only function, then you have to come up with some list of functions which do vectorize.
>
> Then every single person has to memorize that list in its entirety. Which can be difficult even for experts.
>
> Perl has a similar list of functions which automatically work on `$_`, and almost no one has that list memorized.
> Raku very specifically did not copy that idea.
>
> ---
>
> Raku instead has high level concepts that it uses consistently.
>
> One of those concepts is that functions have one job and one job only.
>
> So if you call `chars` on anything it gets turned into a string first.
>

This is where my previous question on "language-paradigm priority"
comes into play. Here I'm applying what I know from the (functional)
R-programming language, where you choose a data structure based upon
your input data. Have an ordered/unordered mixed sequence of
letters/numbers? Use a vector. Have many vectors of varying length
that are somehow all related to one another? Use a list. Have related
vectors of the same length (rectangular data, i.e. database row)? Use
a matrix or dataframe. Below, R-code (in the R-REPL) working on the
built-in "letters" vector:

> letters
 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p"
"q" "r" "s" "t" "u" "v" "w" "x" "y" "z"
> cat(letters)
a b c d e f g h i j k l m n o p q r s t u v w x y z
> length(letters)
[1] 26
> is.vector(letters)
[1] TRUE
> mode(letters)
[1] "character"
> nchar(letters)
 [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> nchar(paste0(letters, collapse=""))
[1] 26
>

Above, I call nchar() on a vector and I get back the number characters
for each element of the list by default. We can think about the
R-vector (analogous to a Raku array) driving the interchange when
acted upon by R-functions.

I think R's behavior makes sense when you try to call a mathematical
function. The data structure dictates the return, and the bare
math-function call gives the desired/expected return whether the
function (e.g. cos) is called on a single-element or a vector of
elements:

> cos(2*pi)
[1] 1
> cos(0:6 * pi)
[1]  1 -1  1 -1  1 -1  1

Thanks, Bill.

PS.  If Raku's split() is string-only, what splits on bytes in Raku?
What splits a file into multiple equal-sized files in Raku? Thx.

https://www.theunixschool.com/2012/10/10-examples-of-split-command-in-unix.html





> On Sat, Oct 10, 2020 at 4:23 PM William Michels via perl6-users <perl6-users@perl.org> wrote:
>> On Tue, Oct 6, 2020 at 1:59 PM Tobias Boege <tobs@taboege.de> wrote:
0
perl6
10/17/2020 2:28:28 AM
Reply: