This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html
Set by lizmat on 8 June 2022.
nhail Alright, followup to last question. Here's my current testing code for this program: sub sendMpvCommand(*@args) { my $sentCommand = shell "echo '\{\"command\":[\"{@args.join('", "')}\"]}' | socat - /tmp/mpvsocket", :out; return 'got: '~ $sentCommand.out.slurp: :close; } my $mpvproc = Proc::Async.new(<mpv --idle --input-ipc-server=/tmp/mpvsocket>); $mpvproc.start; sleep 1; say 00:59
sendMpvCommand('quit') This technically works, but there are some major issues. First off, the sleep 1. The code doesn't work without it, and it also doesn't work when that is replaced with await $mpvproc.ready, so there must be some additional delay between "ready" and the socket actually recieving data. Second, I'm getting output in my stdout from the mpv proc. My terminal looks like this after running the code:
> ./async_testing.raku Exiting... (Quit) got: {"data":null,"request_id":0,"error":"success"} I can tell that Exiting... (Quit) is not supposed to be there, because it's not prefixed with got:, like I would expect if it was coming from the sendMpvCommand function
(Sorry for the text wall btw, hopefully someone can help) 01:00
nemokosch I suppose that's where you'd want a react block or something alike 01:52
nhail I hate to say "write my code for me", but would you be able to provide an example of a react block here? Try as I might, I haven't really been able to figure it out from the documentation 02:00
I understand tap because I'm used to javascript's addEventListener 02:01
but react still doesn't quite make sense to me 02:02
Well, I found a working system with tap 02:14
but I still get the $mpvProc's stdout getting sent to my terminal 02:15
Fixed by adding nohup 02:30
04:35 razetime joined 04:41 teatwo joined, razetime left 04:44 tea3po left 05:08 razetime joined 05:22 siavash joined 07:30 siavash left 07:35 siavash joined 11:22 siavash left 11:29 razetime left
nemokosch I think I've used react like once but even that code got left behind at my previous workplace 12:23
antononcube Hm… I think I have used react a few times because of Cro and trying to make some semi-interactive applications. 13:25
_elcaro_ I'm no expert either, but perhaps you can try Github code search for uses of react block in Raku github.com/search?scopeName=All+re...;type=code I skimmed the first page, and there's at least one example using a Proc::Async (in ‎lib/Fez/Util/Proc.rakumod), but I don't know if it suits your use case specificially. 14:48
16:42 teatwo left, teatwo joined 16:47 teatwo left
librasteve there is a difference between react the JS framework and raku react 18:46
sub send-mpv-command(*@args) { my $sent-command = start { run "echo '\{\"command\":[\"{@args.join('", "')}\"]}' | socat - /tmp/mpvsocket", :out; } await $sent-command; return 'got: '~ $sent-command.out.slurp: :close; } my $mpv-proc = Proc::Async.new(<mpv --idle --input-ipc-server=/tmp/mpvsocket>); $mpv-proc.start; sleep 1; react { whenever signal(SIGINT) { say
send-mpv-command('quit'); exit; } }
^^^ here's what my friend ChatGPT suggestes
docs.raku.org/language/concurrency#react 18:47
although both do reactive programming 18:48
antononcube What is the shortest elegant way to produces a list of results of repeated function: [$a, f($a), f(f($a)), f(f(f($a))) ...] ? I have a solution using produce is not that elegant: produce( -> $x, $y {f($x)}, $a, | (0...3)) . 19:17
nemokosch does the sequence operator not work for this? 19:19
$a, &f ... * 19:20
antononcube @nemokosch Seems to work! 😲 19:27
librasteve ^^ nice 19:45
or maybe function composition 19:46
Function composition lets us take advantage of the idea that f(g(x)) will always return the same value for a given value of x. And as such we can create a new function h where h(x) == f(g(x)). The composition operator (∘ or o) lets use define h without having to formally wrap the functions :
my &h = &f ∘ &g; # or my &h = &f o &g;
docs.raku.org/routine/o%2C%20infix%20∘ 19:49
say 'Hello World!'; sub f($p){ say 'f'; $p / 2 } my &c1 = &f ∘ &f; say c1 2; my &c2 = ∘; say c2 2; 19:59
^^ sorry little o is hard to read on discord
lakmatiol raku > sub f($x) {$x + 1} &f > [\o] (&f xx 10) andthen $_>>.(1) (2 3 4 5 6 7 8 9 10 11) this does work, but it is less efficient than the ... solution 20:17
antononcube @librasteve Thanks! I had similar idea, but I want to get a list of the values not just the final result. So, I was looking for a solution that of @lakmatiol . (And, yes, @nemokosch gives the best solution. I am surprised I did not "know it"...) 21:19
I know that if I have the functions A and B then I can use both A(B(x, y)) and (&A o &B).(x, y) . My question where is the definition and usage description of "the dot" . before (x,y) ? 22:36
Also, how it is called? I assumed it is described in, say, Signature , or it has to something with .meth , etc. 22:37
23:21 kjp left 23:24 kjp joined