🦋 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.
lizmat [Coke] Thanks, fixed! 07:02
Guest59 Hi 09:58
Kernspin Good noon. It is exactly 12 AM o'clock. 10:01
Nemokosch same 10:02
okay 1 minute off 😄
Geth planet.raku.org: f10772d266 | (Elizabeth Mattijsen)++ (committed using GitHub Web editor) | perlanetrc
Add lizmat's dev.to feed
10:48
planet.raku.org: 88a4ca7cc8 | (Elizabeth Mattijsen)++ (committed using GitHub Web editor) | perlanetrc
Adapt title, didn't realize that's shown on the raku.org homepage
11:08
tbrowder .tell tony the code seems to be fully working now. all the current tests work with mi6 test. but more tests are needed “of course” 13:39
tellable6 tbrowder, I'll pass your message to Tony_ 13:40
tbrowder .tell tonyo ^^^
tellable6 tbrowder, I'll pass your message to tonyo
tonyo tbrowder: nice, is that going without eval? 13:48
been dealing with production problems the last couple of days and haven't had time for much else
tbrowder no, it’s using EVAL
tbrowder it needs internal code cleanup, but the design works. i would like to avoid the unique class name problem, but that can wait for a PR from the raku pros 13:51
tonyo there is a way to name anonymous classes but i'm failing to recall what it is 16:42
[Coke] .^set_name("FOO"), and then .^compose, maybe? 16:53
(though I cannot do that and make FOO.new work, so I'm missing something
m: my $a = anon class { method hi{say "hi"}}; $a.^set_name("Foo"); $a.^compose; dd $a.new 16:59
camelia Foo.new
[Coke] but Foo.new at that point, or even ::("Foo").new don't work. Missing a step
lizmat when you do Foo.new, the "Foo" needs to live somewhere lexically visible 17:00
that the anonymous class thinks of itself as "Foo" doesn't help in this search 17:01
you would need to bind the anonymous class to "Foo" somewhere
[Coke] ah, fair. I think I thought the compose would do that. 17:02
lizmat m: my \Foo = class { has $.a = 42 }; dd Foo.new.a
camelia 42
lizmat I don't think ^compose does that, or is expected to do that
.^compose is mostly about clearing / re-initalizing any caches 17:03
[Coke] is there a MOP method we could use to add a class in with a name? 17:11
lizmat perhaps this can be an inspiration: 17:14
m: my constant \Foo = package { }; BEGIN Foo::<Bar> := class { has $.a = 42 }; dd Foo::Bar.new.a
camelia 42
lizmat the problem is really that if you do Foo::Bar.new, the Foo::Bar must exist at compile time 17:16
[Coke] lizmat++
lizmat a runtime version:
[Coke] m: m: my constant \Foo = package { }; Foo::<Bar> := class { has $.a = 42 }; ::("Foo:Bar").new.a;
camelia No such symbol 'Foo:Bar'
in block <unit> at <tmp> line 1
lizmat m: my \Foo = package { }; Foo::<Bar> := class { has $.a = 42 }; dd Foo::<Bar>.new.a
camelia 42
lizmat yup, you got the idea :-) 17:17
[Coke] m: m: my constant \Foo = package { }; Foo::<Bar> := class { has $.a = 42 }; ::("Foo::Bar").new.a;
camelia ( no output )
[Coke] so if you can't guarantee it's there at compile time, you can always look it up at runtime.
lizmat indeed 17:22
although, now that we have newdisp, you could argue that the Foo::Bar lookup should be at runtime
I believe the compile timedness of such lookups was mostly a efficiency thing 17:23
[Coke] That change would have to go in over a language bump, probably? 17:24
lizmat well, perhaps 17:33
probably, yes
hythm m: my @a = 1, 2, 3; @a.hyper.map(*.say); 18:58
camelia 1
2
3
tellable6 2022-10-12T09:30:15Z #raku <lizmat> hythm: END try self.some-method()
hythm an array can be hyper iterated like above. but is there a way to ask an array to be hypered anytime it is iterated, without explicitly calling `hyper` before `map`? something like  `@a .= hyper; @a.map(*.say);` 19:01
m: my @a = 1, 2, 3; @a .= hyper(); @a.map(*.say) ## and I be sure that the map call will be hypred? 19:03
camelia 1
2
3
hythm What I'm trying to do is to call hyper based on a condition, and the map block of code is long, so to avoid duplicating the long code block inside map, I 'd like to do something like `@a .= hyper if $condition; @a.map: ...` 19:10
lizmat m: my @a = ^10; my $s := 0 ?? @a.hyper !! @a; my @b = $s.map: { 42 }; dd @b # hythm 20:05
camelia Array @b = [42, 42, 42, 42, 42, 42, 42, 42, 42, 42]
lizmat m: my @a = ^10; my $s := 1 ?? @a.hyper !! @a; my @b = $s.map: { 42 }; dd @b # hythm
camelia Array @b = [42, 42, 42, 42, 42, 42, 42, 42, 42, 42]
lizmat m: 'my @a = ^10; my $s := 1 ?? @a.hyper !! @a.Seq; my @b = $s.map: { 42 }; dd @b @ perhaps clearer 20:06
camelia ===SORRY!=== Error while compiling <tmp>
Unable to parse expression in single quotes; couldn't find final "'" (corresponding starter was at line 1)
at <tmp>:1
------> s.map: { 42 }; dd @b @ perhaps clearer⏏<EOL>
expecting …
lizmat m: my @a = ^10; my $s := 1 ?? @a.hyper !! @a.Seq; my @b = $s.map: { 42 }; dd @b @ perhaps clearer 20:07
camelia ===SORRY!=== Error while compiling <tmp>
Two terms in a row
at <tmp>:1
------> !! @a.Seq; my @b = $s.map: { 42 }; dd @b⏏ @ perhaps clearer
expecting any of:
infix
infix stopper
postfix
ugexe probably not good to mix something that you typically want to work lazily with something you almost never want to work lazily
lizmat m: my @a = ^10; my $s := 1 ?? @a.hyper !! @a.Seq; my @b = $s.map: { 42 }; dd @b # perhaps clearer
camelia Array @b = [42, 42, 42, 42, 42, 42, 42, 42, 42, 42]
ugexe i'd probably just always hyper but with :degree(1),:batch(1) if i wanted map-like behavior
lizmat I guess :degree(1) should be enough, and not do any hypering at all and just return an ordinary Seq 20:08
masukomi is there any builtin function i could use to execute a shell command and stream the output? For example, if i wanted to make a script that let users start "top" running and just stream the ever-changing top output to them. 20:10
Nemokosch Proc::Async? 20:11
docs.raku.org/type/Proc::Async there is an example 20:12
masukomi hmm. yeah maybe. I wonder if there's a way to just wire it's output directly to stdout rather than the "react" mechanism 20:13
Nemokosch I mean... if you don't want to do anything with the output, why don't you just downright call the process? 😄 20:15
ugexe all the proc ops use stdout/stderr as the default handles
m: shell("top") 20:16
camelia The spawned command 'top' exited unsuccessfully (exit code: 1, signal: 0)
in block <unit> at <tmp> line 1
masukomi outside of raku? i can, and i do, but in this context it's "here's info about something... oh hey, there's an asiiinema recording for it. would you like me to play it?" I'd like to actually play it for the person not force them to run a separate command.
ugexe maybe you should just try 20:17
masukomi yeah, am about to. ;)
ugexe my $proc = run("top", :out); $proc.out.Supply.tap: { say $_ }; loop {}; $proc.out.close() 20:19
Nemokosch Are you sure this would work, with the infinite loop? Did nothing for me 20:21
but yeah `shell('top')` just works for running a process to completion
masukomi the top example looks terrible when run. my similar test of running asciinema works but screws up formatting 20:22
ugexe yes that works with the infinite loop
Nemokosch then I don't know what I'm doing wrong 20:23
masukomi the top one seems to be ignoring / loosing escape codes that result in lines being redrawn and is, instead just streaming a constant list
Nemokosch for me, it just freezes the REPL, inline script also
masukomi ah, i didn't run it in a repl. i figured that was pretty much guaranteed to introduce weirdness 20:24
ugexe 🤷 works for me raku -e 'my $proc = run("top", :out); $proc.out.Supply.tap: { say $_ }; loop {}; $proc.out.close()'
Nemokosch didn't work with `raku -e` either, mind you 20:25
I wonder what it would produce
will check on the physical Ubuntu as well
masukomi i took ugexe's line and stuck it in an executable. here's a video of the result share.cleanshot.com/lxEm9s 20:26
Nemokosch Anyway, embedding top into a script doesn't sound like a good idea 20:27
interesting xdd
ugexe if you dont want to process the output then just do the previously mentioned shell("top") or run("top")
my example should probably use print instead of say as well 20:28
Nemokosch is top even meant to produce processable output? 20:29
masukomi uh.... shell("asciinema play path/to/foo.cast") works perfectly. I didn't even try it because i assumed it couldn't possibly be that easy.
shell("top") ALSO works perfectly 20:30
masukomi i'm .... astounded. free beer on me to whoever made that work so flawlessly. 20:31
Nemokosch nope, doesn't work on physical machine, Ubuntu 20.04, Cinnamon's default terminal either 20:32
or xterm for what it's worth 20:33
hythm28 Thanks lizmat & ugexe. Im away from computer at the moment, will try later.  Does `@a.hyper(:1degree).map` has performance penality if used instead of `@a.map` ? 20:34
masukomi do you have it in a simple executable file with just a shebang line and a shell("top") line? That's all i did. I'm on macOS though. 20:35
Nemokosch masukomi: embedding shell execution was easy in Python and even in C, using `system`... however, my special favorite is the qx quoting
which sends the output straight back as a string
no, that works, I meant ugexe's example 20:37
tbh the qx quoting is among the reasons I started Raku 😅
the final push was that I was annoyed by the boilerplate Python required for shell interactions 20:38
these inline shell quotes are excellent when you half know the tools 20:40
you don't have to suddenly get deep into either the APIs for Raku for the CLI of a more sophisticated command-line tool, you can just glue something in two minutes 20:41
and the pleasure and usefulness will fuel the learning
masukomi yeah, i'm SO very impressed at how much better raku is at CLI tools than... literally everything else. So much work has been put into supporting that kind of tool making. 21:00
guifa_ sena_kun: you work on Comma, right? 21:42
sena_kun guifa_, yes 21:43
yes, we lost last month release
guifa_ no not that lol
sena_kun no, we'll do one this month 21:44
guifa_ the billing system is down.
sena_kun oh
that's bad
down as in?
guifa_ insert fry_take_my_money.gif
It's giving an error on using Stripe, saying that the administrator needs to complete some kind of set up
sena_kun thanks a lot for letting me know
guifa_ I'll PM you the exact message
sena_kun we'll sort it out ASAP (well, tomorrow I hope) 21:45
Nemokosch Is it a good idea to put a global config file of a script into the resources folder? 22:10
ugexe thats what zef does 22:45
ugexe i would say its a good idea o put a "default" global config file in resources/, but if you expect users to edit configs then it should look somewhere like ~/.config/whatever/ first 23:00
users shouldnt be editing config files of installed modules afterall
Nemokosch Then I don't know why it wouldn't work... 23:02
Hm, wait... are resources not exposed to files in the bin/ folder? 23:04
ugexe ah right yeah, same with test files 23:05
ugexe i always write my scripts inside of a module e.g. MyModule::CLI and my bin scripts are `use MyModule::CLI;` 23:05
that allows your script to get precompiled as a side effect as well
Nemokosch Makes sense, although I feel I'm getting overkill with a zero dependency script that mostly just calls other CLI tools :D 23:07
ugexe thats pretty much all zef is 23:08
it also allows you to do stuff like
raku -MZef::CLI -e '' install Foo::Bar 23:09
ugexe which, surprisingly, i've had uses for 23:09
like if multiple versions are installed, an easy way to invoke a specific one: `raku -e 'use Zef::CLI:ver<0.1>' install Foo::Bar` 23:11
ugexe it also works as a command to run a script without first pointing PATH at e.g. site/bin 23:18
Nemokosch Anyway, thank you, useful learning 23:23
Time to go to sleep o/ 23:24