🦋 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 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 8 June 2022.
tonyo hi ingy 02:20
Nemokosch reinventing the wheel be like 08:53
> git log | raku -pe 'last if /^^ "commit " / && $++ >= 10'
in other words: git log -10
lizmat SmokeMachine: if you want to use rak as a sub, would you need all of its features, or a subset ? 09:19
if subset, what subset ? :)
SmokeMachine lizmat: I’m thinking… but I assume at least most of them… let me think… 09:28
Nemokosch How can I catch all the arguments of a function (so that I can propagate them to another function)? 10:12
Perhaps I will rather use a decorator-ish pattern but still worth asking imo
SmokeMachine m: sub bla(|c) { say |c }; bla “test”, 42 10:14
camelia test42
Nemokosch does it pick up named arguments as well? 10:16
lizmat it does 10:25
if you're interested in *only* the named arguments, you should use a slurpy hash 10:26
Nemokosch thankies 10:28
does `last` set the return value of a block? 10:32
lizmat not in 6.c 10:33
lizmat in 6.e you can "last 42" 10:33
m: use v6.e.PREVIEW; say (^10).map: { $_ == 5 ?? (last 42) !! $_ } 10:34
camelia (0 1 2 3 4 42)
lizmat m: say (^10).map: { $_ == 5 ?? (last 42) !! $_ }
camelia ===SORRY!=== Error while compiling <tmp>
Calling last(Int) will never work with any of these multi signatures:
( --> Nil)
(Label:D $x --> Nil)
at <tmp>:1
------> say (^10).map: { $_ == 5 ?? (⏏last 42) !! $_ }
Nemokosch wow 10:35
while this is good to know, actually this wasn't the essential question I should have asked
say I have a piece of code &actions
and I want to do `return actions`, or could be `last actions` in this other example
what happens if actions throws?
lizmat if it doesn't get caught in a CATCH, your ptogram will die 10:42
Nemokosch I'm gonna show an example code that I don't fully understand 10:44
I'm trying to emulate error and retrial 10:45
If Pidgin starts...
Nemokosch m: sub demo2 { loop { CATCH { say "OKAY WTF." }; return { die 'Now!' unless (1 .. 10).pick == 1; 12 }(); } } 10:47
camelia ( no output )
Nemokosch oops, maybe it should be called as well...
m: sub demo2 { loop { CATCH { say "OKAY WTF." }; return { die 'Now!' unless (1 .. 10).pick == 1; 12 }(); } }; demo2 10:48
camelia OKAY WTF.
Now!
in block at <tmp> line 1
in sub demo2 at <tmp> line 1
in block <unit> at <tmp> line 1
Nemokosch This is what I always get. Caught at first, dies after.
Or caught and yet dies? I don't know how this works.
lizmat you didn't handle the exception in the CATCH block, so it is being rethrown by a CATCH block higher up 10:49
m: CATCH { say "CATCH"; .resume }; say "before"; die; say "after"
camelia before
CATCH
after
Nemokosch well, what does "handling" mean? I'm used to the block itself doing the distinguishing, a la C++ and derived languages 10:50
"distinguishing", almost... extinguishing xd 10:51
lizmat then why did you want a CATCH block ? todo something with the exception, no ? 10:55
*to do
Nemokosch Well for now I wanted to see if it's caught 10:56
lizmat m: CATCH { say "CATCH" }; say "before"; die; say "after"
camelia before
Died
in block <unit> at <tmp> line 1

CATCH
lizmat m: CATCH { say "CATCH" }; note "before"; die; note "after" 10:57
camelia before
CATCH
Died
in block <unit> at <tmp> line 1
lizmat say is on STDOUT, camelia got some syncing issues there, using note makes the sequence more clear
making all output happening on STDERR 10:58
Nemokosch without dying, that is :D anyway, I was looking at this .resume... I'm not sure I want to give the control flow back to where the error happened
I just want to keep the loop running so that there can be a retry 10:59
lizmat m: for ^10 { CATCH { next }; die if $_ == 5; .say } 11:00
camelia 0
1
2
3
4
6
7
8
9
lizmat make sure the CATCH is inside the loop
m: for ^10 { CATCH { say "CATCH"l; next }; die if $_ == 5; .say }
camelia ===SORRY!=== Error while compiling <tmp>
Two terms in a row
at <tmp>:1
------> for ^10 { CATCH { say "CATCH"⏏l; next }; die if $_ == 5; .say }
expecting any of:
infix
infix stopper
postfix
11:01
lizmat m: for ^10 { CATCH { say "CATCH"; next }; die if $_ == 5; .say }
camelia 0
1
2
3
4
CATCH
6
7
8
9
Nemokosch okay, good enough overall. This leads to... 11:03
Nemokosch gist.github.com/2colours/255b578e6...c21cd70bf9 11:04
lizmat you want to return the result of calling &actions, right ?
Nemokosch yes :plad 11:06
🥺
lizmat so what is the problem with that code?
Nemokosch Well, nothing anymore, I hope? 😄
Will see the rest. Thanks for the help!
lizmat well.. it will continue to retry on failure... which may be excessive 11:07
especially if the failure is quick, you're going to burn a lot of CPU there
so I'd put a max on the number of retries, and maybe put in an increasing delay on retries
Nemokosch I doubt the failure is going to be quick. There is a 20 seconds timeout on the requests typically, could be even more 11:08
lizmat ah, ok
glad to have been of help :-) 11:10
Nemokosch I'm trying to not over-engineer it because it's gonna be something that "only has to work" once in a month or so
we host the service that should be accessed so if there is serious trouble, probably it will escalate to other systems and shutting down poor script won't be the biggest deal 😅
lizmat gotcha :-)
well, it's some form of production :-)
Nemokosch I updated the gist with a "usage example" 11:14
lizmat looks ok from here 11:21
Nemokosch Hopefully it will work okay. I kinda like this style 11:22
lizmat :-) 11:23
Nemokosch Lesson to learn: .kv only works for Maps, not Positionals of Pairs - however, for loop with :key and :value destructuring works for both 12:00
lizmat yep, that's because a loop on a Map will produce a list of Pairs 12:01
m: my %h = a => 42, b => 666; for %h { dd $_ }
camelia :b(666)
:a(42)
lizmat m: my %h = a => 42, b => 666; for %h { dd .^name }
camelia "Pair"
"Pair"
ingy hi tonyo 13:17
ingy tonyo: how can I `fez login` from a script (not interactively) 13:46
I could use `expect` but hopefully I can just curl something? 13:47
lizmat ingy: afaik, you only need to do that once a month ? 13:52
ingy lizmat: this is for an ephemeral environment 14:24
lizmat then why upload it to fez ?? On fez it will stay there *forever* !! 14:25
ingy I'm not sure we are talking about the same thing. 14:27
ingy I have a tool that can publish modules in various languages. It runs in docker. It uses a credentials file containing fez creds and others. 14:28
When I do a `pst publish` in a raku module repo it should `fez login` and `fez upload` 14:29
I guess I'll look in the fez code and see what it's doing. I just thought I could get a quicker answer here :) 14:30
lizmat sorry to have disappointed you 14:31
El_Che that sounds a tad dramatic 16:40
lizmat sorry, but the person in question *always* wants it the quick and easy and lazy way, and I'm grumpy today 16:44
[Coke] offers lizmat something from the ice cream truck that just went through Coke's neighborhood. 17:01
... or I would, if they ever drove by my house! They always go around!
leont Given the weather in NL at the moment I'm pretty sure ice cream would be welcome 17:05
lizmat yeah.. will probably go out in 30 mins or so to get some 17:21
[Coke] \o/ 17:31
[Coke] ... which I guess is the chocolate at the bottom of a coronetto? 17:39