On Mon, Oct 12, 2020 at 10:02 AM Larry Wall <la...@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>».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
Hi Larry! First of all, let me thank you for designing the Raku (née 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 = << blob 'king kong' mothera fingfangfoom >>; [blob king kong mothera fingfangfoom] > dd @monsters Array @monsters = ["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 = [("blob",).Seq, ("king", "kong").Seq, ("mothera",).Seq, ("fingfangfoom",).Seq] Nil > my @nums = 0,1,2,3,4,5,6,7,8,9; [0 1 2 3 4 5 6 7 8 9] > dd @nums Array @nums = [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 = [-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=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=Collective+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