🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). This channel is logged for the purpose of keeping a history about its development | evalbot usage: 'm: say 3;' or /msg camelia m: ... | Log inspection is getting closer to beta. If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 25 August 2021.
Xliff m: my ($a, $b, $c, $d) = 0 xx 4; for $a, $b, $c, $d -> $_ is raw { say .VAR.name } 00:44
camelia $a
$b
$c
$d
melezhik .tell lizmat Whateverable build fails on SparkyCI - sparrowhub.io:2222/report/124 01:50
^^ AlexDaniel
HTH
Nick12 What have people tried to make rakudo startup/execution faster? I absolutely love the power of the language but it's a barrier for me to adopt this over perl due to performance. For example: 02:39
raku -e 'print $_ for 1..1000000;' > /dev/null 1.66s user 0.03s system 104% cpu 1.617 total
perl -e 'print $_ for 1..1000000;' > /dev/null 0.25s user 0.00s system 98% cpu 0.254 total
Rakudo v2022.02 installed on macOS 12.2.1 with homebrew
perl v5.34.0 on the same system, also installed with homebrew
japhb Nick12: In that *particular* case you may be running up against Perl doing no output encoding, but Raku using UTF-8 encoding by default. 02:43
But rather than microbenchmarks, I'd say it's more valuable to look at the performance difference for whatever it is you're *actually* trying to do. 02:44
(Having written quite a few microbenchmarks, I can say that it is very easy to wildly change relative performance with minor changes.) 02:45
Oh, also it matters for MacOS if you're on an Intel or ARM processor -- the latter does not yet have JIT support in Rakudo. 02:46
Nick12 Sure. I agree a single test case isn't sufficient to prove it's slower. Most big applications I default to using something like c++ and opt for scripting when I'm just trying to get something specific done really quickly and typically is focused on processing text (perl one liners? ooh 8)  lol). I've perceived a slower response time using rakudo 02:56
which is a bit frustrating, and I know that's vague. It probably takes playing around with it a bit more and perhaps not entirely switching from perl to raku if I'm looking for something really snappy. The potential of saving minutes writing a raku script might dwarf the milliseconds to seconds of extra time spent executing one haha.
FWIW I have an intel processor 02:57
japhb Yeah, generally perl will be faster for pure sed/awk-like tasks, as that is what it was optimized for. Rakudo will be faster for heavy OO and many of the numeric bits that Perl doesn't support out of the box (big integers, rational numbers, and complex numbers, for example). And as you note, rather often Raku has more general whipupitude and developer efficiency. 03:34
Also, very few interpreters beat perl on startup time. It's wicked fast at that. Rakudo does a lot more at startup than perl does, and it costs a few dozen milliseconds to do all of that. 03:36
grondilu on docs.raku.org/language/operators#O...precedence the table seems to list operator precedence levels alphabetically, not from actual precedence levels. 05:54
a quick search points to raku.finanalyst.org/language/operators.html 05:57
where the table makes much more sense.
grondilu unrelated: 06:15
m: say class :: does Numeric { method Int { 13 } }.new div 7; CATCH { default { say "huh?" } }
camelia huh?
grondilu which method do I need to implement the Numeric role? 06:16
m: say class :: does Numeric { method Bridge { 13 } }.new div 7; CATCH { default { say "huh?" } }
camelia huh?
grondilu m: say class :: does Numeric { method Numeric { 13 } }.new div 7; CATCH { default { say "huh?" } }
camelia ===SORRY!=== Error while compiling <tmp>
Cannot have a multi candidate for 'Numeric' when an only method is also in the package '<anon|1>'
at <tmp>:1
grondilu m: say class :: does Numeric { method Real { 13 } }.new div 7; CATCH { default { say "huh?" } } 06:17
camelia huh?
Voldenet that table on operator_precedence seems to be sorted in some weird way 06:25
It is correct in source though github.com/Raku/doc/blob/master/do...s.pod6#L34
grondilu then it's the conversion to html that is wrong. 06:28
Voldenet …the html conversion is also correct :) 06:31
it's some fancy script that sorts the table
Voldenet regarding the "Numeric" role, operators are not part of the role 06:46
m: class X does Numeric is Int { method Int { 13 } }; multi infix:<div>(X:D $a, Int:D $b) { $a.Int div $b }; say X.new div 7 06:47
camelia 1
Voldenet m: say class :: does Numeric is Int { }.new(13) div 7 06:48
camelia 1
grondilu oh ok, so with a straight-up inheritance to Int. 06:49
then I guess I don't even need Numeric
m: say class :: is Int { method Int { 13 } }.new div 7; CATCH { default { say "huh?" } }
camelia 0
grondilu m: say class :: does Numeric is Int { method Int { 13 } }.new div 7; CATCH { default { say "huh?" } } 06:50
camelia 0
grondilu not what I want 06:51
Voldenet m: multi infix:<div>(Numeric:D $a, Int:D $b) { $a.Int div $b }; say class :: does Numeric { method Int { 13 } }.new div 7
camelia 1
grondilu I really don't want to have to redefine the operator myself. 06:52
guifa o/ 07:50
AlexDaniel melezhik18: I haven't tried installing it that way for a long time, so that's kinda expected. Pull requests are welcome 09:20
grondilu isn't there a flag for `prompt` to suppress echo? 10:31
I mean what is the correct way to prompt for a password then? 10:32
Nemokosch hmmm 10:34
gfldex grondilu: see github.com/rakudo/rakudo/blob/mast...s.pm6#L146 10:37
echo is a property of the terminal and Raku doesn't know those exist 10:40
raku.land/github:titsuki/Terminal::Readsecret 10:41
this module does
Voldenet > sub without-echo(&fn) { LEAVE { run("stty", "echo") }; run("stty", "-echo"); fn() }; say without-echo({ prompt("password: ") }) 10:42
grondilu I guess I can also call the shell : 10:43
say "password was {.out.slurp}" given shell q[read -s -p "password?"; echo $REPLY], :out
evalable6 password was ♥🦋 ꒛㎲₊⼦🂴⧿⌟ⓜ≹℻ 😦⦀🌵 🖰㌲⎢➸ 🐍💔 🗭𐅹⮟⿁ ⡍㍷⽐
grondilu lol that's fun
Voldenet but shell implies bash 10:44
sh doesn't do read -s
grondilu I mean look at that beautiful unicode string
gfldex shell implies not-Windows
Voldenet touche
grondilu I don't mind excluding Windows users lol 10:45
Voldenet windows-also solution sounds difficult to maintain on your own
gfldex It would make any coporate password policy very happy indeed.
Voldenet regarding corporate password policies, I've seen things you people wouldn't believe :D
gfldex I got a login for a software that controls SIM cards. 8 chars max for the PW. 10:46
grondilu thinks about the famous Sony playstation hack
gfldex Dont't use SMS for two-factory.
s/y//
Voldenet sadly some services only have sms or nothing, sms is still better than nothing 10:53
grondilu Voldenet: looking at your solution again, it looks fine actually
Voldenet well, stty is relatively portable too 10:54
grondilu quite a smart use of LEAVE too 10:56
grondilu ended up using that solution 10:59
what about checking input by prompting password twice and dying if the inputs differ? How to make sure echo is restored then? Since the LEAVE will not be executed. 11:11
Voldenet hmm? 11:14
grondilu well it's common to ask for a password twice to check for input mistakes. 11:15
then if there is indeed a mistake I would raise an exception, but then the LEAVE will not be executed, would it?
Voldenet it would 11:17
grondilu { CATCH { default { say "oops" }; LEAVE say "done"; die "aaaahh"; } }()
Voldenet m: { CATCH { default { say "oops" } }; LEAVE say "done"; die "aaaahh"; } 11:19
camelia oops
done
grondilu ok great 11:21
Voldenet either way:
sub without-echo(&fn) { LEAVE { run("stty", "echo") }; run("stty", "-echo"); fn() }; sub get-new-pass { without-echo(sub { loop { my $pass = prompt("password: "); return $pass if $pass eq prompt("\nrepeat password: "); say "\npasswords mismatch" } }) }; say get-new-pass;
grondilu I don't need a dedicated `without-echo` function but yeah, that's the idea. 11:23
m: { LEAVE run <echo bye>; say hi; } # testing shorter syntax 11:24
camelia ===SORRY!=== Error while compiling <tmp>
Undeclared routine:
hi used at line 1
grondilu m: { LEAVE run <echo bye>; say "hi"; } # testing shorter syntax
camelia hi
grondilu hum
Voldenet it will work if you test it on real env 11:24
grondilu indeed 11:25
the run command is really powerful, especially now that it handles binary input/output.
Voldenet m: say $*OUT.native-descriptor 11:26
camelia 1
Voldenet that's most puzzling 11:27
m: say $*OUT
camelia IO::Handle<IO::Special.new("<STDOUT>")>(opened)
melezhik . 12:14
[Coke] As someone who uses windows raku for $dayjob, if there's a raku core solution that works (assuming this is going into the ecosystem), I'd prefer you used the core solution. 13:28
Voldenet no dependencies is the best dependency 13:39
[Coke] mm! 14:22
Xliff Still having problems with nested braces. This time trying to parse out methods from a class definition. 14:23
Can someone tell me what I'm missing?
gist.github.com/Xliff/e2a51378257a...13c6369a8a
grondilu [Coke]: do you use WSL? 15:08
El_Che [WSL]: do you use Coke? 15:12
dunno, it's all a waze
[Coke]_ I do not use WSL, no 15:40
grondilu how can I get JSON::RPC::Client to send an actual {} as parameter instead of 'null'? 16:45
grondilu I have an rpc server which accepts {} as params but not null, and I think JSON::RPC::Client sends null. $server.method({}) works the same as $server.method() and fails. 16:46
gfldex grondilu: what happens when you send `Hash.new` ? 17:24
grondilu same result 17:28
apparently the lib relies on add_fallback
m: class { BEGIN { $?PACKAGE.HOW.add_fallback( $?PACKAGE, sub (|) { True }, -> $obj, $name { method (*@params, *%params) { say "$name called with {@params.raku}"; } } ) } }.new.foo({})
camelia foo called with []
grondilu but this mechanism does not accept and empty hash as a positional parameter? 17:29
m: class { BEGIN { $?PACKAGE.HOW.add_fallback( $?PACKAGE, sub (|) { True }, -> $obj, $name { method (*@params, *%params) { say "$name called with {@params.raku}"; } } ) } }.new.foo("hello")
camelia foo called with ["hello"]
grondilu see what I mean?
m: class { BEGIN { $?PACKAGE.HOW.add_fallback( $?PACKAGE, sub (|) { True }, -> $obj, $name { method (*@params, *%params) { say "$name called with {@params.raku}"; } } ) } }.new.foo
camelia foo called with []
grondilu m: class { BEGIN { $?PACKAGE.HOW.add_fallback( $?PACKAGE, sub (|) { True }, -> $obj, $name { method (*@params, *%params) { say "$name called with {@params.raku}"; } } ) } }.new.foo([]) 17:30
camelia foo called with []
grondilu neither an empty array?
m: class { BEGIN { $?PACKAGE.HOW.add_fallback( $?PACKAGE, sub (|) { True }, -> $obj, $name { method (*@params, *%params) { say "$name called with {@params.raku}"; } } ) } }.new.foo(["hey"])
camelia foo called with ["hey"]
grondilu looks like a bug to me
oh wait 17:31
m: sub (*@params) { @params }([]).say 17:32
camelia []
grondilu m: sub (*@params) { @params }().say
camelia []
grondilu ah
grondilu tries to remember how this *@ thing is called. Slurpy parameters? 17:33
m: sub (*@params) { @params }([].item).say 17:34
camelia [[]]
grondilu ah ah
damn I was hoping that would work but the rpc call still fails 17:35
m: class { BEGIN { $?PACKAGE.HOW.add_fallback( $?PACKAGE, sub (|) { True }, -> $obj, $name { method (*@params, *%params) { say "$name called with {@params.raku}"; } } ) } }.new.foo([].iteum) 17:37
camelia No such method 'iteum' for invocant of type 'Array'. Did you mean
'item'?
in block <unit> at <tmp> line 1
grondilu m: class { BEGIN { $?PACKAGE.HOW.add_fallback( $?PACKAGE, sub (|) { True }, -> $obj, $name { method (*@params, *%params) { say "$name called with {@params.raku}"; } } ) } }.new.foo([].item)
camelia foo called with [[],]
saint- Hi, I was wondering what was wrong with trying to use this grammar to parse into just separate lines? www.toptal.com/developers/hastebin...orefon.lua 22:15
Voldenet m: grammar Lit { token TOP { ^ <lines>+ $ }; token lines { .*? '\n' };}; Lit.parse("ab\nc\nde\n").say 23:02
camelia Nil
Voldenet m: grammar Lit { token TOP { ^ <lines>+ $ }; token lines { .*? "\n" };}; Lit.parse("ab\nc\nde\n").say 23:04
camelia 「ab
c
de

lines => 「ab

lines => 「c

lines => 「de
Voldenet the '\n' works, but probably not in the way you want 23:06
m: grammar Lit { token TOP { ^ <lines>+ $ }; token lines { .*? '\n' };}; Lit.parse("ab\\nc\\nde\\n").say
camelia 「ab\nc\nde\n」
lines => 「ab\n」
lines => 「c\n」
lines => 「de\n」