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 <b2gi...@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-us...@perl.org> wrote:
>> On Tue, Oct 6, 2020 at 1:59 PM Tobias Boege <t...@taboege.de> wrote:

Reply via email to