🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). Log available at irclogs.raku.org/raku/live.html . If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 6 September 2022.
guifa whoa 00:33
TIL
my @a = 1,2,3; push(@a: 4); say @a 00:34
evalable6 [1 2 3 4]
guifa I always thought it HAD to be parentheses-less
tonyo what is the push(@a: 4) compiling to, i'd've figured a comma there 01:49
my @a = 1,2,3; push(@a, 4); dd @a; 01:50
evalable6 Array @a = [1, 2, 3, 4]
tonyo guifa: isn't the `@a.push: ...` syntax just sugar for `push(@a, ...)` like in perl's `$a = T->new; $a->xxx` is just sugar for `$a = T::new(T); T::xxx($a);` 01:52
or whatever it is, i haven't had a perl job for six years now
guifa There's a sub push(@,$) but then Array defines a method push($) 01:54
push(@a,4) calls the sub
push(@a: 4) calls the method
IIRC the sub just ends up calling the method anyways, but that doesn't have to be the case (even if it normally is) 01:55
tonyo interesting 01:56
guifa the idea is if I make a class
class Foo { method parrot($x) { say $x } }; my $f = Foo.new; $f.parrot('oo'); parrot $f: 'proc' 01:57
evalable6 oo
proc
guifa I don't need to write the sub version manually
tonyo wonder where that came from 02:07
looks fp-ish
in spite of the source obviously being oo
guifa I always figured it was designed to make stuff very procedural 02:08
guifa but I guess both functional and procedurals tend to be more verb first, and OO more object first 02:10
fwiw this is in reference to github.com/Raku/problem-solving/issues/384 02:11
tonyo interesting, i'd echo codesection's comment 02:27
tonyo my Promise $p .=new; keep $p: 42; await $p; say $p.result 02:56
evalable6 42
xinming when we do .split, Is there a way to split on the first occurence of the space for the regex? 13:07
lizmat m: say "foo:bar:baz".split(":",2) ? 13:09
camelia ===SORRY!=== Error while compiling <tmp>
Confused
at <tmp>:1
------> say "foo:bar:baz".split(":",2)⏏ ?
expecting any of:
infix
infix stopper
postfix
statement end
statement m…
lizmat m: say "foo:bar:baz".split(":",2)
camelia (foo bar:baz)
xinming lizmat: SO the 2 here means $limit, right? 13:11
lizmat_ yes, it indicates the maximum number of parts you want
xinming I do checked the doc, I used .split(/<space>/, :limit(1)) Doesn't work, I thought it is used to specify times to match. 13:12
got it, thanks.
lizmat_ hmmm.. maybe limit *should* become a named argument 13:14
lizmat_ and actually: limit is a bad name in that context, just like "length" is 13:15
lizmat clickbaits rakudoweekly.blog/2023/09/11/2023-37-issuing/ 13:22
nemokosch in what regard is it a bad name? 13:30
lizmat because it is not clear whether you're specifying the number of splits, or the number of produced parts 13:31
nemokosch fair enough 13:44
fun times. I reorganized the "atom highlighter" so that one can maintain it without all the Coffeescript legacy. We have asked a move for VS Code from some ages old plist-format highlighter in a Perl package that nobody ever touches anymore 13:49
and after months of idling over it, dude just grabs two screenshots with the supposed highlighters with VSC on some snippet from wikipedia, says that there are some problems with the "Atom" version and rejects it 13:50
ironically enough, the supposed "Atom highlighting" was highly different from the highlighting on Github 13:51
tonyo 'a:b:c'.split(':', :into(2)) would be nice 15:20
ugexe :into is already used to mean something else for 'classify' 15:26
lizmat I was more thinking :parts(2) 15:42
dakkar m: dd('a:b:c'.split(':',2)) 15:44
camelia ("a", "b:c").Seq
ugexe i don't like parts either, because it really means 'max-parts'. in that sense limit makes more sense 15:53
lizmat :max-parts(2) would work for me 15:54
ugexe in node, typescript, java, and julia its called limit, in c# its called count, in python its called max-split 15:58
lizmat max-split has the same semantics, as in number of max number of parts produced? 15:59
antononcube Does :max-parts(2) mean the first two elements of a split? If yes, is it a good idea to have :first(2) and :tail(3) ?
ugexe er, maxsplit rather
then again in python i guess thats just a positional parameter named maxsplit
i have ignored positional implementations 16:00
nemokosch What's wrong about it being a positional?
lizmat because it's an optional argument, and the other optionals are named arguments 16:01
antononcube @nemokosch I was going to suggest it, but that is what Mathematica does. (So, I restrained myself.) 16:02
ugexe max-splits reads better than max-split
nemokosch Depending of the scope of "the other optionals", that is, there are clearly optional positional parameters in the core 16:03
lizmat so max-splits => 1 would give you 2 parts ?
antononcube But since people bring Python examples (Python!!?), here is the Mathematica page for StringSplit : reference.wolfram.com/language/ref...Split.html
ugexe it would give you 1 or 2 parts 16:04
lizmat looks like Mathematica takes the current positional approach
maybe we just need to clarify the documentation, as the internal name of the argument shouldn't matter 16:05
antononcube @lizmat Yeah, that is why I am not suggesting it. 🙂
In Python positional arguments have names; in Mathematica they do not. 16:06
MasterDuke i'd vote for max-parts over max-split(s) if it's a user-visible name
antononcube I thinking options like ":first", ":tail", or ":upto" are better.
Actually, ":upto" is shorter and as descriptive as ":max-splits". 16:07
lizmat disagree 16:08
antononcube Ok, or ":up-to". 🙂
@lizmat I do not feel strongly about my suggestions. I am way too biased from/by Mathematica. 16:09
lizmat upto could be considered some kine of marker upto splits should be done
tonyo max-parts is nice 16:10
antononcube @lizmat Cool! 16:13
And a good example of my bias: reference.wolfram.com/language/ref/UpTo.html 16:14
tonyo upto sounds like it might truncate results, eg 'ab:c:d'.split(':', :upto(2)) -> 'ab', 'c' 16:15
ugexe max-elems is kind of nice in that it implies $splitted.elems <= $max-elems 16:16
although it would have the same problem as sounding like it might truncate results 16:17
tonyo max-splits seems to be the only one without the implication 16:19
nemokosch however, that one does change the current semantics, not just the name 19:58