🦋 Welcome to Raku! raku.org/ | evalbot usage: 'p6: say 3;' or /msg camelia p6: ... | irclog: colabti.org/irclogger/irclogger_log/raku
Set by ChanServ on 14 October 2019.
00:10 pecastro left 00:15 sena_kun joined 00:16 zacts joined, Altai-man_ left 00:18 aborazmeh joined, aborazmeh left, aborazmeh joined 00:20 zacts left 00:28 NewGreyhawke left
guifa2 Xliff: You could make a suffix, I suppose, but IME it's *very* tricky keeping native stuff as natives. Even doing something like $a + ($b - $c) has booted them out of native and into general Ints 00:32
00:43 MilkmanDan left 00:45 MilkmanDan joined, aborazmeh left 00:53 _jrjsmrtn joined 00:55 __jrjsmrtn__ left 01:02 silug left 01:03 silug joined 01:22 NewGreyhawke joined 01:23 silug6 joined, silug left, silug6 is now known as silug, lucasb left 01:59 molaf left
Xliff guifa: Yeah. Everything has to be typed! 02:02
Using binds also helps.
The moment it conts, you lose the native, I think.
02:03 Noisytoot left 02:06 ManifestO left, ManifestO joined 02:07 Noisytoot joined 02:11 molaf joined 02:13 Altai-man_ joined 02:16 sena_kun left 02:21 Noisytoot left 02:24 Noisytoot joined 02:30 Noisytoot left 02:35 oodani_ left, oodani joined 02:37 kst left
Geth doc: coke self-assigned xt/examples-compilation.t github.com/Raku/doc/issues/3391
889c6aa040 | (Tom Browder)++ (committed using GitHub Web editor) | doc/Language/intro.pod6
03:22 kst joined 03:25 guifa2_ joined, guifa2 left, guifa2_ is now known as guifa2 03:34 gordonfish joined 03:48 cpan-raku left 03:50 RaycatWhoDat joined, zacts joined, cpan-raku joined, cpan-raku left, cpan-raku joined, RaycatWhoDat left 04:09 leont joined 04:14 sena_kun joined 04:15 sivoais_ left, sivoais joined 04:16 Altai-man_ left 05:05 reach_satori left, reach_satori joined 05:07 skids joined 05:18 wamba joined 05:45 rindolf joined 06:13 Altai-man_ joined 06:16 sena_kun left 06:17 NewGreyhawke left
cpan-raku New module released to CPAN! Chart::Gnuplot (0.0.18) by 03TITSUKI 06:19
06:30 skids left 06:44 xinming left
cpan-raku New module released to CPAN! Chart::Gnuplot (0.0.19) by 03TITSUKI 06:51
07:15 wamba left 07:32 xinming joined 07:47 xinming left 07:49 xinming joined
linkable6 Link: docs.raku.org/language/intro
DOC#3252 [closed]: github.com/Raku/doc/pull/3252 proposed table of Raku vs. Perl 6 deprecations
07:59 Zero_Dogg left 08:08 Noisytoot joined 08:14 sena_kun joined 08:16 Altai-man_ left
Geth doc: e707196480 | (JJ Merelo)++ | doc/Type/Supply.pod6
Changes former definition to table
doc: f818b95bce | (JJ Merelo)++ | doc/Type/Supply.pod6
Adds new definitions to Supply.throttle.

Also rewrites a part. Closes #175
linkable6 Link: docs.raku.org/type/Supply
DOC#175 [closed]: github.com/Raku/doc/issues/175 [docs] Document Supply.throttle(:$vent-at)
08:36 Zero_Dogg joined
Geth doc: d9fa24d5bc | (JJ Merelo)++ | doc/Type/Supply.pod6
Reformatting working on #1875
doc: b4ac61ded0 | (JJ Merelo)++ | doc/Type/Supply.pod6
Moves Supply.reduce, closes #1875

Also, some clarification.
linkable6 Link: docs.raku.org/type/Supply
DOC#1875 [closed]: github.com/Raku/doc/issues/1875 [bug][docs] Supply.reduce waits for the Supply to finish
09:13 oddp joined, MasterDuke joined 09:26 Sgeo left 09:31 cpan-raku left, cpan-raku_ joined, cpan-raku_ left, cpan-raku_ joined 09:42 HarmtH_ joined 09:43 markong joined, HarmtH left 09:49 wamba joined 09:51 Black_Ribbon left 09:54 markong left 09:55 markong joined
Geth doc: bb4543d9ac | (JJ Merelo)++ | doc/Type/Supply.pod6
Adds definitionf of Supply.tail #3527
linkable6 Link: docs.raku.org/type/Supply
DOC#3527 [open]: github.com/Raku/doc/issues/3527 [RFE][docs][help wanted][versions] Checklist for 2020.07
10:13 Altai-man_ joined 10:16 sena_kun left 10:22 pecastro joined
holyghost I am going to start Tuesday on racul, a scheme language extension compiler/interpreter which extends raku applications, probably not the compiler itself 10:26
It's on Xliff's server and at github.com/theholyghost2/racul
I chose the name from dracul (dragon knight) and guile (gnu extensions system from the scheme language) 10:27
So basically it's scheme language specifically for raku, instead of using guile, I start from scratch 10:28
It'll be revised scheme report 3 at the minimum
So no continuations for example, to start with 10:29
(I've written unterpaganperl)
It's probably be written in plain ANSI C 10:31
I cannot give pf and pm a new language though, but if racul is somewhere, anyone can extend the scheme language 10:32
It'll be a modularized system 10:33
10:55 NewGreyhawke joined 10:58 erdic left 10:59 telex left 11:01 erdic joined 11:02 telex joined 11:19 xinming left 11:20 xinming joined, aborazmeh joined, aborazmeh left, aborazmeh joined 11:24 xinming left 11:25 xinming joined 11:29 kensanata joined 11:41 kensanata left 11:44 wamba left 11:55 NewGreyhawke left 12:14 sena_kun joined 12:17 Altai-man_ left 12:34 aborazmeh left
Xliff gist.github.com/Xliff/600d1c8ba52c...f43fb24ccc <- Solves my enum problem 12:48
12:48 Ven`` joined 12:55 Zero_Dogg left 12:59 sena_kun1 joined 13:03 kensanata joined 13:09 Zero_Dogg joined
[ptc] silly question time: theoretically, the regex `m:i:g/ 'bb' || <-[ b ]> ** 2 /` should match either two 'b's or not a 'b' twice 13:25
my question is: is it possible to write that more elegantly? 13:26
codesections Hmmm, interesting question. My first thought (combining into `[ 'bb' || <-[ b ]> ] ** 2` doesn't work. 13:32
[ptc] maybe `[ 'b' || <-[ b ]> ] ** 2` ? 13:34
codesections er, right, that's what I meant (the 'bb' was a typo on my part). I thought that might work, but it doesn't 13:36
but that matches 'ab'. Which I'm slightly surprised by – I guess the branch is evaluated seperately on each repetition 13:37
[ptc] hrm, true. Weird. 13:40
m: say "abBii" ~~ m:i:g/ 'bb' || <-[ b ]> ** 2 /;
camelia (「bB」 「ii」)
[ptc] say "abBii" ~~ m:i:g/ [ 'b' || <-[ b ]> ] ** 2 /;
evalable6 (「ab」 「Bi」)
lizmat moritz ^^ 13:41
[ptc] my raku is amazingly rusty... still trying to get back up to speed
Voldenet m: "aaabbbac" ~~ m:Perl5:g/bb|[^b]{2}/ 13:42
camelia ( no output )
[ptc] Voldenet: in theory that should work (at least, that was the version on the T-shirt I used to own ;-) ) 13:43
Voldenet oh, i just realized what it means :D 13:44
and it'd work in perl5, so I wonder why doesn't it now 13:45
m: "aaabbbac" ~~ m:Perl5:g/a/
camelia ( no output )
Voldenet m: "aaabbbac" ~~ m:Perl5/a/
camelia ( no output )
codesections I'll be kind of sad if the best Raku regex we can come up with involves the `Perl5` adverb :) 13:46
Voldenet that's weird
codesections m: say "aaabbbac" ~~ m:Perl5:g/bb|[^b]{2}/
camelia (「aa」 「bb」 「ac」)
Voldenet …lol, right
codesections :)
Voldenet I'd argue about "best" - shortest maybe ;) 13:47
[ptc] yeah, I'd like to steer clear of the Perl5 adverb :-) 13:48
Voldenet m: say "aaabbbac" ~~ m:g/bb||<-[b]> ** 2/
camelia (「aa」 「bb」 「ac」)
Voldenet it's almost the same
in fact 13:49
m: say "aaabbbac" ~~ m:g/bb|<-[b]> ** 2/
camelia (「aa」 「bb」 「ac」)
[ptc] true, but it has more of a raku flavour, and that's what I'm interested in
yeah, that's definitely better than my attempt 13:50
Voldenet it's literally the same tho :D
[ptc] but in p5 it's not possible to spread it out with whitespace (not using /x, of course) 13:51
and I think that makes it easier for the brain to parse when reading it
Voldenet i've seen regex hell, nothing scares me anymore 13:52
[ptc] hehe
m: say "aaabbbac" ~~ m:g/ bb || <-[b]> ** 2/
camelia (「aa」 「bb」 「ac」)
[ptc] that feels a bit more "idiomatic raku" to me... Dunno if there's such a thing as idiomatic raku yet though 13:53
Voldenet m: say "aaabbbac" ~~ m:g/ bb || <-[b]><-[b]> / 13:56
camelia (「aa」 「bb」 「ac」)
[ptc] m: my $question = 'aaabbbac'; $question ~~ m:g/ bb || <-[b]> ** 2/; 13:59
camelia ( no output )
[ptc] m: my $question = 'aaabbbac'; say $question ~~ m:g/ bb || <-[b]> ** 2/;
camelia (「aa」 「bb」 「ac」)
13:59 wamba joined
[ptc] I had hoped to be able to use rx//, but the :g adverb doesn't work with rx// 14:00
took me a while to work out why, but once I found the place in the docs, it became clearer :-)
thanks for the tips everyone!
codesections m: say 'aaabbbac' ~~ m:i:g/ 'a' ** {(1, 3)}/ 14:01
camelia (「aa」)
codesections why doesn't that dwim? I would have thought that would be "either 1 or 3 'a's", but it returns 2 14:02
timotimo it numifies the list, the list has two elements, so it's equivalent to `** 2` 14:04
codesections …oh. Right, because it won't take a list, just a Range 14:05
timotimo that's right
14:05 sena_kun1 left
timotimo if you want to have two alternatives, you will need an alteration 14:05
perhaps at some point junctions of integers could be supported? 14:06
codesections and the same is true of something like (1, * + 5 … 6)
Which I *think of* as a Range, but really reduces to a (perhaps lazy) List
timotimo i would not call that a range 14:07
especially since it has a gap :) 14:08
codesections Well, it's a Seq
timotimo yeah, ... is the Sequence operator
Range is more closely related to the mathematical notion of an Interval
codesections I (sloppily) think of as being "like Ranges but fancier" :) 14:09
which I should probably stop doing!
m: 'aa' ~~ /a ** {('str', 'str2')}/ 14:13
camelia ( no output )
codesections m: 'aa' ~~ /a ** {'str2'}/ 14:14
camelia Cannot use non-Numeric or NaN value as quantifier
in block <unit> at <tmp> line 1
14:14 Altai-man_ joined
moritz a sequence operator is closer to a loop 14:14
codesections Do you think it's a bug that the List example coerces to Numeric without throwing the same error that the Str version does?
14:14 rawr is now known as grumble
timotimo could probably warn when it's a literal 14:15
if you're using a variable that has a list in it and it gets numified for you, that's usually a feature; like "match a string with as many 'a's as the array has elements" essentially 14:16
codesections is that just to save typing `.elems`?
14:16 sena_kun left
moritz yes 14:18
also, p5 heritage
14:19 xelxebar_ joined 14:20 xelxebar left
codesections and I guess we do have a warning sign docs.raku.org/language/traps#Lists...ic_context 14:20
14:20 sftp left
codesections :) 14:20
(Just not on the Regex page) 14:21
14:23 sftp joined 14:37 Xliff left
samebchase- In Raku, we use grep when we want to filter elements based on a predicate. How do we return the elements from a sequence that do NOT match a predicate. Other languages have a "remove" function, what's the most idiomatic Raku way of doing this? 14:59
14:59 xinming left
samebchase- "Note that if you want to grep for elements that do not match, you can use a none-Junction:" hmm, found this in the documentation 15:00
15:00 xinming joined
codesections In many cases, you can also just flip the test, right? 15:01
m: (^20).grep({!.is-prime})
camelia ( no output )
codesections m: say (^20).grep({!.is-prime})
camelia (0 1 4 6 8 9 10 12 14 15 16 18)
samebchase- hmm, complementing the predicate seems to be the easiest way 15:03
thanks codesections!
codesections you're welcome :) 15:04
(Something I really like about Raku is how it does a lot more with simple combinations of well-thought out operations (here, smartmatching and junctions) where other languages use a lot more methods) 15:05
timotimo codesections: many tests are not code :) 15:06
m: say <a b c d e f g>.grep(none <a e f>)
camelia (b c d g)
samebchase- The reason I ask is, I was writing some code recently, and to write a filter, I had an "if", of the form (if cond A and cond B, then check cond C or return true otherwise). It seemed clunky to have a true in the else branch, so I changed it to use remove with the if changing to (if cond A and cond B then check inverse of cond C), and I got rid of t
he "true" part if that makes any sense
15:08 pi4 left 15:09 e left
samebchase- , but the language I was using (Clojure) had "when", but Raku's when has the behaviour which bit me recently "When the when block is executed, control is passed to the enclosing block and /following statements are ignored/!" 15:10
codesections That *feels* like a good use case for a Junction, but I'm not quite sure… 15:11
samebchase- so I avoid using when as much as possible
codesections Why's that? To avoid multiple exit points for the fn? 15:12
samebchase- I guess, it seems to me right now, that we can use a combination of flipping the predicate or the none Junction as described in the documentation, depending on the case
codesections, basically someone used to Lisp or Clojure's when/unless should be wary of Raku "when" gotcha, but interestingly enough Raku's "unless" does not have the same gotcha 15:13
codesections Interesting. I hadn't thought about it from a Lisp point of view. There, the distinction between `if` and `when` is that `when` allows multiple forms without `progn` or whatever? (My Lisp is a bit rusty) 15:15
samebchase- If you don't have an else branch, it just seems cleaner to use when/unless (in those languages), but I guess, in Raku we should use if without an else branch in situations where there could be other statements following the if block.
15:16 kensanata left
samebchase- codesections: yeah, the implicit progn/do is a convenience feature 15:16
If anyone can let me know why Raku's "when" does it this way, I am interested to know the reason, purely out of curiosity. 15:17
15:18 NewGreyhawke joined
codesections re "use if without an else branch", especially since `if` can be an expression, with either `do` or parens 15:18
samebchase- I had a major, "is there something wrong with the universe" situation, when the last few statements of my program were just not getting executed, and then I read the documentation
codesections m: say (if True { 'foo' } ~ 'bar'
camelia 5===SORRY!5=== Error while compiling <tmp>
Strange text after block (missing semicolon or comma?)
at <tmp>:1
------> 3say (if True { 'foo' }7⏏5 ~ 'bar'
codesections m: say (if True { 'foo' }) ~ 'bar'
camelia foobar
15:18 MilkmanDan left
codesections I can't speak to the "why" – I'm new and wasn't there – but `when`'s behavior always made sense to me because I thought of it as part of the `given … when` construct, just used without the `given`. Which makes it a bit like the `case` block in switch statements in many langauges (or, the `match` block in Rust, where I was coming from). Not having fall through there made sense to me 15:21
Well, that and I wasn't expecting a `when` to exist, so I first learned it as "if without fallthrough" instead of expecting it to exist 15:22
15:23 MilkmanDan joined
Kaiepi `when` is a bit weird and took me a while to understand how to use it well 15:27
i don't like to think of it like `case` in a `switch` because you can use it anywhere, not just in a `given` 15:28
unlike `if`, it smartmatches $_ against its condition
this makes it useful in stuff like `for` loops as well:
m: for 1..100 { when * %% 15 { say 'FizzBuzz' }; when * %% 3 { say 'Fizz' }; when * %% 5 { say 'Buzz' }; default { say $_ } }
camelia 1
holyghost ok, I started work on racul, I have some lines for a symbol table already, I will continue later on 15:30
15:31 wamba left
samebchase- Kaiepi: nice 15:43
15:43 wamba joined 15:45 Voldenet left 15:51 NickSeagull joined 15:52 NickSeagull left 15:53 NickSeagull joined
codesections m: sub f($i) { (^$i).map({CATCH { default { "PLACEHOLDER" } }; if $_ == 5 {die}; $_ × 2})}; say f 10 15:55
camelia (0 2 4 6 8 Nil 12 14 16 18) 15:56
NickSeagull Hi! Raku newcomer here :) Coming from Haskell, I'm loving the language a lot
codesections why is the 6th item in that list ^^^^ `Nil` and not `PLACEHOLDER`?
NickSeagull: Welcome! I'm also fairly new, and came here from Rust 15:57
15:57 Voldenet joined, Voldenet left, Voldenet joined
NickSeagull I'd like to be a bit more involved in the community. Are there any efforts geared towards having LSP ready for Raku? I'd like to work on that :) 15:58
codesections I miss `Option` and expect you'll miss `Maybe`, but otherwise like it a lot :)
lizmat LSP ?
NickSeagull codesections: Thanks! :D
codesections Language Server Protocol
NickSeagull lizmat: Language Server Protocol: microsoft.github.io/language-server-protocol/ 15:59
lizmat ah... I seem to recall it being mentioned before
but I think it was like "a nice to have"
NickSeagull I thought about starting to work on it as a pet project, while getting more in depth with Raku. But didn't want to split efforts if something was going on already 16:00
Looks like there's nothing on GitHub about it though
codesections I've been toying with the idea of building an Emacs extension that's modeled after a striped down version of the LSP – but just focused on documentation rather than autocompletion 16:01
but using the same basic json transport and client/server model 16:02
NickSeagull codesections: Cool! What I like about LSP itself is that it unifies the core part of the language support and then the users can use their favorite editors :) 16:03
codesections Yeah, that is powerful!
Altai-man_ NickSeagull, there is github.com/azawawi/ide-perl6 and github.com/azawawi/app-perl6langserver but I think they are incomplete and want a maintainer, so if you feel like doing a great thing you can try to contact author / fork and go.
NickSeagull This is super helpful Altai-man_ , thanks! 16:04
codesections have you seen this talk by Jonathan Worthington about building the Comma IDE for Raku? www.youtube.com/watch?v=zDP9uUMYrvs 16:05
NickSeagull codesections, Nope, but will look into it now ty
codesections He talks about writing a different compiler/interpreter for the IDE work to deal with the (very different) challenge of real-time autocompletion/etc with program input that is usually invalid 16:06
I *suspect* that a LSP implementation might also need a different compiler backend 16:07
(The Comma one is not currently open source, though I know Johnathan has mentioned the possibility of releasing it at some point)
16:13 zacts left 16:15 sena_kun joined 16:16 Altai-man_ left 16:18 Sgeo joined
Geth doc: 5850cdf925 | (JJ Merelo)++ | doc/Type/Supply.pod6
New functionalities of Supply.tail #3527
linkable6 Link: docs.raku.org/type/Supply 16:22
DOC#3527 [open]: github.com/Raku/doc/issues/3527 [RFE][docs][help wanted][versions] Checklist for 2020.07
16:22 zacts joined 16:24 zacts left 16:25 zacts joined 16:26 zacts left
NickSeagull I'm confused, why are there two github orgs: Raku and Perl6? 16:31
timotimo the name change ws just recently
NickSeagull timotimo, Yep, but shouldn't it be just a rename of the GH org instead of creating a new one? 16:32
moritz there's a slow migration from Perl6 to Raku
NickSeagull in what way moritz ?
16:34 Zero_Dogg left
moritz repos are being migrated one by one, after careful consideration if we still need it 16:35
NickSeagull Ah cool :) 16:36
Is there a way to typecheck a module using Rakudo? Without running that is 16:39
timotimo very difficult 16:40
BEGIN time stuff, including using modules, and types that are defined with predicates that are code, all make it extra hard
moritz NickSeagull: there are some type errors that are caught at compile time. You can catch those with rakudo -c path/to/file 16:41
but most type errors are run time
timotimo the lack of restrictions on what subclasses are allowed to do with methods also makes things dicey
NickSeagull ah :(
timotimo in C++ for example, you have restrictions what subclasses do with a virtual method's signature, right? 16:42
NickSeagull I see 16:43
Yet for simple functions it'd be nice to have something. E.g.: sub f(Int $x --> Bool){ "hello" }; say f 3.4 16:44
holyghost First write of variable and lambda symbol ADTs are in, in racul
timotimo m: sub f(Int $x){ say "hi" }; f(4.3)
camelia 5===SORRY!5=== Error while compiling <tmp>
Calling f(Rat) will never work with declared signature (Int $x)
at <tmp>:1
------> 3sub f(Int $x){ say "hi" }; 7⏏5f(4.3)
timotimo ^- this is a compile-time error
NickSeagull timotimo, Yep, but if that compilation succeeds, it will get run 16:45
timotimo ah, there's a syntaxcheck flag to rakudo
NickSeagull Would be nice if that rakudo -c checked that
timotimo -c check syntax only (runs BEGIN and CHECK blocks)
NickSeagull With -c I only get "Syntax OK" for that code
timotimo oh, it doesn't 16:46
Geth doc: 1db69d68e1 | (JJ Merelo)++ | doc/Type/Supply.pod6
New functionalities of Supply.head using WhateverCode #3527
linkable6 Link: docs.raku.org/type/Supply
DOC#3527 [open]: github.com/Raku/doc/issues/3527 [RFE][docs][help wanted][versions] Checklist for 2020.07
timotimo in that case, just use --target=optimize instead, lol
because this check currently lives in the optimizer
(among other things it's because subs can be post-declared and thus may not be available for checking at the call site)
Geth doc: acf784f300 | (JJ Merelo)++ | doc/Type/Supply.pod6
New functionalities of Supply.head using WhateverCode #3527
timotimo perhaps RakuAST will allow this to happen earlier 16:47
16:48 Zero_Dogg joined
NickSeagull timotimo, --target=optimize works, thanks! Coming from Haskell, I'm used that mostly everything happens in the compilation phase heh 16:50
timotimo right 16:51
NickSeagull btw timotimo where can I learn more about RakuAST? Is that a library in development?
timotimo raku has some things that you usually get from dependent typing environments, but only checked at run time, and therefore not exhaustive at all like a full agda or coq thing
i'll dig up some links for you 16:52
www.youtube.com/watch?v=91uaaSyrKm0 - this ought t get you started
NickSeagull Thanks will watch it
timotimo, regarding checking types at runtime and ensuring code correctness, how do we work around that? With a TDD approach? 16:53
16:54 NewGreyhawke left
timotimo yeah, perl in general has been big on TDD for a long long time 16:54
NickSeagull But with Raku's type system would it be a thing yet? 16:56
timotimo u.setxkbmap.de/#0-H_jmNFEquodjEBSMW8tQ eeeeexcuse me?
sena_kun timotimo, some of the characters from famous `$character death` are alive though. :P 16:57
NickSeagull timotimo, it looks like its another guy
timotimo impostors trying to ruin our reputation 16:58
NickSeagull heh 16:59
17:07 NewGreyhawke joined
NickSeagull What's the current way of starting a new project? Does one have to write meta6.json by hand and all that jazz? Or am I missing some hidden thing in zef? 17:07
timotimo Comma offers this functionality i think 17:10
can also try App::Assixt, mi6, and similar tools
there is more, i forgot the other names 17:11
NickSeagull timotimo, thanks looking into them 17:12
timotimo i use mi6 for JSON::Fast
"mi6 new Foo::Bar" exists according to its USAGE 17:13
NickSeagull Awesome!
kawaii someone once sent me a one-liner that would identify all of the module namespaces for easy meta population, but I've long since lost it 17:14
codesections NickSeagull: there's also this page of Module dev tools: docs.raku.org/language/modules-extra 17:15
NickSeagull codesections, wow!!! That's what I needed :) 17:16
codesections I can't personally vouch for how up-to-date that page is
I'm still struggling to understand Raku's model for handling exceptions. 17:18
m: sub f { CATCH { default { 42 }}; die}; say f
camelia Nil
codesections why does that return `Nil` instead of `42`?
NickSeagull codesections, perhaps you have to wrap it in try?
17:18 Ven`` left
timotimo blocks return the last thing in them 17:18
NickSeagull m: sub f { try { CATCH { default { 42 }}}; die}; say f
camelia Died
in sub f at <tmp> line 1
in block <unit> at <tmp> line 1
timotimo m: sub f { die; CATCH { default { 42 }}; }; say f 17:19
camelia Nil
timotimo hm, ok
codesections there is a different form, with try as a statement modifier 17:20
sub f { CATCH { default { 42 }}; die}; say f
evalable6 Nil
codesections m: sub f { try { die } // 42 }; say f 17:21
camelia 42
codesections so I know how to get the output I'm looking for, but I'd still like to understand what CATCH is doing
17:36 Ven`` joined
guifa2 CATCH will grab whatever exception was thrown. It's a phaser though, so it's not called in the normal flow 17:42
Most languages require you to use the structure try { … } catch { … }
codesections with you so far 17:43
17:44 markoong joined
guifa2 Just like sometimes it can be cleaner / more readable / etc to use a postfix "if" (esp as a first line in a sub, "DIE If { condition is of secondary importance}" ) 17:44
It can be nice from a readability standpoint to let me know what will happen in the case of a failure in a true
so you can do
17:44 markong left
guifa2 try { CATCH { *this-is-important-to-know* } now we try the stuff } 17:45
phasers will execute at special times, rather than in code order
codesections m: sub f { CATCH { default { say "I caught something. Returning 42"; 42 } }; die }; say f
camelia I caught something. Returning 42
guifa2 CATCH is a phaser, so you can put the catch wherever you want in a block
and it will only execute if there's an exception
codesections That CATCH block is being triggered, but it's *not* returning anything? 17:46
guifa2 If you want to ignore the error you need to tell CATCH things are okay
use .resume if you want to continue the operations from the point of the exception 17:48
codesections Yeah, but I *don't* want to continue from the point of the exception. I want to abort the current function with a default return value 17:49
guifa2 sub f { say "1. "; CATCH { default { say "Caught"; } }; say "2. "; die; say "3. "; "4." }; say f
evalable6 1.
guifa2 ah
then just put in "return foo" :-)
m: sub f { say "1. "; CATCH { default { say "Caught"; .resume } }; say "2. "; die; say "3. "; "4." }; say f
camelia 1.
guifa2 is what I wanted to say but 17:50
m: sub f { say "1. "; CATCH { default { say "Caught"; return "5." } }; say "2. "; die; say "3. "; "4." }; say f
camelia 1.
codesections m: sub f { CATCH { default { say "I caught something. Returning 42"; return 42 } }; die }; say f
camelia I caught something. Returning 42
codesections oh 17:51
I could have sworn I tried that...
guifa2 Ha, that's how it always goes 17:52
codesections m: sub f($i) { (^$i).map({CATCH { default { return 42 } }; when $_ == 5 { fail }; $_ × 2})}; say f 10 17:53
camelia Attempt to return outside of immediately-enclosing Routine (i.e. `return` execution is outside the dynamic scope of the Routine where `return` was used)
in block at <tmp> line 1
in any at <tmp> line 1
in block <unit> at <tmp> line 1
codesections Or, simplified a bit: 17:56
m: sub f { (1).map({CATCH { default { return 42 } }; die })}; say f
camelia Attempt to return outside of immediately-enclosing Routine (i.e. `return` execution is outside the dynamic scope of the Routine where `return` was used)
in block at <tmp> line 1
in any at <tmp> line 1
in block <unit> at <tmp> line 1
codesections how is that different?
17:56 NewGreyhawke left
guifa2 hmmm 17:59
18:03 Xliff joined
Xliff \o 18:04
guifa2 codesections: if you put it in a try block, it all works fine
err no 18:05
codesections This has *something* to do with the difference between Blocks and Routines. «Blocks that aren't of type Routine (which is a subclass of Block) are transparent to return» 18:06
I'm used to thinking of `map`, etc as Higher Order Functions that take fns as their arguments. But in Raku they take Blocks
which (I think?) makes a subtle but key difference 18:07
18:14 Altai-man_ joined 18:16 sena_kun left
codesections actually, maybe 100% of my confusion comes from `map` or other HoF and not from CATCH at all 18:20
guifa2 codesections: here's a way to make it work: tio.run/##K0gtyjH7/7@4NEkhjatagYtT...xEqFtP//AQ
codesections m: sub f { (1).map({return 42}) }; say f
camelia Attempt to return outside of immediately-enclosing Routine (i.e. `return` execution is outside the dynamic scope of the Routine where `return` was used)
in block <unit> at <tmp> line 1
guifa2 I'm sure what's going on is that map is obscuring the ability to return to locate the main sub
But you can pass a sub into map, and violà, return function works (but it will do it once per map operation) 18:21
codesections interesting – thanks! 18:23
that's exactly the behavior I would have expected (without needing the inner sub)
jdv79 which is exactly what the docs point to:) 18:25
codesections jdv79: how do you mean/which docs? 18:27
jdv79 for some reason when i see pointy block i think sub but i guess semantics are different
docs.raku.org/routine/map#(List)_routine_map 18:28
18:28 melezhik joined
timotimo yeah, pointy blocks aren't Routine, which is where returns happen 18:34
18:35 ab5tract joined
ab5tract I've written a new blog post that I thought some folks here might enjoy: 5ab5traction5.bearblog.dev/for-lov...e-underdog 18:36
codesections timotimo: I get that. But what don't get is why `return` from a pointy block inside a `map` inside a `sub` can't seem to find the sub it's in to return from
m: sub f { (1).map({return 47})}; say f
camelia Attempt to return outside of immediately-enclosing Routine (i.e. `return` execution is outside the dynamic scope of the Routine where `return` was used)
in block <unit> at <tmp> line 1
timotimo is execution actually sill inside the sub, or was the lazy list returned from the sub already? 18:37
codesections ..... ohhh
timotimo that seems to be the case here
codesections light bulb moment
ab5tract I only indirectly discuss Raku in this one because this post is about filling in the perspective that leads me to choose Raku as one of my "chosen few" programming languages.
codesections sub f { eager (1).map({return 47})}; say f 18:38
evalable6 47
codesections It all suddenly makes sense!
guifa2 ab5tract++ 18:40
weekly: 5ab5traction5.bearblog.dev/for-lov...e-underdog
notable6 guifa2, Noted! (weekly)
ab5tract thanks guifa2 :) 18:41
codesections guifa2: so, with timotimo's insight, that means the code you posted to Tio could become 18:42
m: sub f { eager (^2).map({ CATCH { default { return 42 } }; die } ) }; say f
camelia 42
timotimo or your code could become 18:43
m: say 42
camelia 42
guifa2 ;-)
timotimo i'm not sure what exactly the code is trying to do :D
guifa2 codesections: I guess the questino is whether you want one single return or multiple
codesections yeah. And there are pretty good options for both :)
jdv79 fun stuff 18:47
timotimo you can also "last" out of a map, can't you? 19:00
codesections I would assume so. Aren't for loops compiled down to maps? 19:05
CIAvash m: say 1,2,3 ≡ 3,2,1 19:07
camelia 12True21
CIAvash is that expected?
19:08 melezhik left
lizmat CIAvash: yes, because ≡ applies .Set semantics 19:09
ah, you mean, why does it output 12...21 ? 19:10
hmmm... maybe the precedence is off
m: say 1,2,3 (==) 3,2,1
camelia 12True21
lizmat m: say 1,2,3 (<=) 3,2,1
camelia 12True21
CIAvash yeah
lizmat well, if it's off, it's off for all set semantics operators 19:11