🦋 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.
tbrowder tonyo: thank you very much! 00:41
tellable6 2021-09-03T15:45:56Z #raku <tonyo> tbrowder a PR would be great - i like the idea of using env vars to override defaults and leaving the defaults as is
tbrowder .tell tonyo thanks, i'll work on the PR 00:42
tellable6 tbrowder, I'll pass your message to tonyo
melezhik how can I catch exceptions withing cro routers? 01:23
looks like things like CATCH do not work for me
or try {} ... - github.com/melezhik/sparky/blob/cr...#L291-L298 01:24
an error is not cached and propagated to cro itslef 01:25
melezhik for example - gist.github.com/melezhik/73a4bc541...a3b78b6d65 , when broken yaml is rendered - github.com/melezhik/sparky/blob/cr....raku#L291 01:27
ugexe what does your catch example look like? 01:44
raku -MCro::HTTP::Router -MCro::HTTP::Server -MYAMLish -e 'my $application = route { get -> { my %y; my $err; try { %y = load-yaml("asdf"); CATCH { default { $err = $_.Str; say "error:$err"; } } }; content "text/plain", $err } }; my Cro::Service $s = Cro::HTTP::Server.new: :host<localhost>, :port<10000>, :$application; $s.start; react whenever signal(SIGINT) { $s.stop; exit; }' 01:48
it wasnt showing the error to the connecting client until i changed `$err = $_` to `$err = $_.Str` 01:49
might try $!.Str 01:50
well i guess you already do that with "$!" 01:51
raku -MCro::HTTP::Router -MCro::HTTP::Server -MYAMLish -e 'my $application = route { get -> { my %y; try { %y = load-yaml("!") }; content "text/plain", "$!" } }; my Cro::Service $s = Cro::HTTP::Server.new: :host<localhost>, :port<10000>, :$application; $s.start; react whenever signal(SIGINT) { $s.stop; exit; }' 01:56
that works as expected for me
melezhik . 02:51
moon-child .. 02:52
melezhik ugexe thanks, could you try add cro template to your example? 02:53
xinming When I use $obj.raku to dump the object, What is the right way to load the data again? 07:42
trying to find data format which can exchange data which is like json, but also supports Capture in raku, failed, So sticking with the raku itself. :-) 07:43
keutoi I'm not sure of any idomatic way to do it but, EVALFILE gives the result of the last expression in a file, so that might work. 08:42
xinming well, I know the EVAL function, But I wish we can have some better way to handle it 08:47
keutoi I think EVAL might be the only option. Most docs for the `raku` method just state: Returns an implementation-specific string that produces an equivalent object when given to EVAL. 09:06
holyghost PHP has a vardump function 09:11
which is non-meta info 09:12
so vardump($v) in PHP ---> '2' 09:13
in your browser to debug 09:14
so mbe have a $obj.dump, #obj.dump-meta
sorry let me rephrase that : $obj.dump, $obj.dump-meta
meta info can be used as in a C++ exception (or other such languages) 09:15
just given as an example 09:16
exceptions are stack based, so can be th meta info. I don't know about raku exceptions though 09:18
print, dump, eval 09:20
or say
intelligent stack-based meta info 09:23
so your compiler fetches more information from its runtime 09:24
It's just a C++ thing 09:27
and maybe scheme/LISP for the eval functionality 09:29
keutoi Is rakudocs.github.io still being used? 10:10
raydiak PHP doesn't have the concept of a Capture, so serializing it is a non-issue for them. that said, I'm personally not aware of any serialization formats which support Captures. though rolling your own might not be so bad, just an array and a hash would be a good start. several serialization formats in the ecosystem support arrays and hashes ofc. if you're looking for something in core, then yes you're left with 10:21
only EVAL. .raku and .EVAL are meant to round-trip with each other
though personally if I found myself tring to serialize Captures, in most cases I'd first stop and ask myself if my design ought to be rethought 10:22
holyghost np, just feeding the features 10:23
tbrowder .tell tonyo i'm confused. it looks like you have already implemented the env var, thank you very much! 10:24
tellable6 tbrowder, I'll pass your message to tonyo
tbrowder ok, i see, you called my issue a feature request and completed it. thanks again! 10:27
raydiak though it does bring up the idea of raku-centric serialization. a format which can round-trip all/most raku data structures without EVAL would be a pretty cool thing 10:28
raydiak though apparently "though" is my word of the day though :) 10:30
lizmat raydiak: a Raku version of Sereal maybe :-) 11:10
xinming raydiak: Because it's cool to serialize Capture. :-) 11:33
jsonrpc has some forms of args passing, but it's not as powerful as Capture
If we can serialize capture, We can be more "specific" about what we want for the RPC. 11:34
raydiak lizmat: I haven't used Sereal, only have a vague recollection of some work with Storable close to 20 years ago...but from what I'm reading about Sereal, yes, some approximation of that 14:45
xinming: I'm certainly not against such a thing existing and don't want to dissuade you, but imo an external API should usually be simple and language-agnostic...seems like this wouldn't be either of those things if I understand correctly? 14:47
if Capture is specifically what you want, perhaps you could rip some relevant parts of the grammar straight out of the rakudo parser... 14:51
spacekookie I'd be curious if people here have favourite programs written in Raku I could try first to see if my packaging tools work :) 16:36
It's gonna be more challenging (and useful) than my tiny scripts
Anton Antonov I want like to write a Raku package that provides a grammar / parser for Mathematica aka Wolfram Language (WL). I am considering several package names: 1) `Grammar::Mathematica` 2) `Mathematica::Grammar` 3) `WL::Grammar` 4) `Grammar::WolframLanguage` 5) `FoxyGoat`. Which one do you think it is bests? 17:03
Looking at modules.raku.org/search/?q=Grammar I see both `Grammar::<name>` and `<name>::Grammar` to be equally represented. 17:04
raydiak spacekookie: Not sure about "favorite" but you could try App::Pray. Still works last time I checked. Not popular or useful or anything, but it's fairly extensive and also has a few dependencies, so might be a decent test of packaging tools 17:05
I haven't done serious work on it in years, so there's some anachronisms especially in the META6.json, but you're going to see that all over the ecosystem anyway. main thing off the top of my head that it wouldn't test is %?RESOURCES (they didn't exist when I wrote it) 17:07
spacekookie Thanks! I'll have a look at it 17:10
I'm not very experienced with raku anyway, so it'll be a good thing to learn these things too. I'm currently mostly trying to improve the tooling in NixOS so I have a nicer time playing with the language down the road ;P 17:11
raydiak that's a cool way to go about it, not just learning by doing but also paving the way at the same time 17:13
Anton: my vote would be for Grammar:: instead of ::Grammar, unless you plan to develop a collection of related things which would be grouped together under Mathematica:: 17:16
Anton Antonov @raydiak Thanks! And good point -- I have to decide do I want to implement "other things" under `Mathematica::`. I am undertaking this because I want to convert a bunch of unit tests from Mathematica to Raku. Hence, I might have additional `Mathematica::*` packages / modules. 17:20
neither hi, if I want to alias a method of a class, should I write another method and directly call the other one? e.g., `$obj.very-long-name` and `$obj.vln` where `method vln() { self.very-long-name}`? Or is this better done another way? 17:27
moritz_ there are other methods, like installing it with a new name through the metaclass. Is that "better"? depends on what you optimize for 17:28
m: class A { method x { say 42 } }; A.^add_method("y", A.^find_method("x")); A.y
camelia 42
moritz_ ah, you should also throw in A.^compose(); after you are done introducing new methods (it works without it in this specifici case, but it's more robust to include it) 17:29
raydiak Anton: sounds like a fun project. and you're welcome, of course 17:39
neither Thank you moritz_, by better I meant conventional|idiomatic because I'm new to the language 17:44
sorry for not being clear in the first place 17:45
moritz_ neither: nothing easier to read than a method that calls another method 17:54
tellable6 moritz_, I'll pass your message to neither
raydiak imma paste this because your connection flaked out for a minute and you missed it: 18:00
17:54:15 moritz_ | neither: nothing easier to read than a method that calls another method
neither Thanks 18:25
tellable6 2021-09-04T17:54:16Z #raku <moritz_> neither: nothing easier to read than a method that calls another method
MasterDuke neither: there's also raku.land/cpan:ELIZABETH/Method::Also 18:36
neither thank you MasterDuke, that's very readable 19:19
klebs hi folks! am wondering about whether there is a way to (within a grammar rule) match a token and some suffix, without having the suffix appear when expanding the rule itself 20:20
specifically, I have some rule for "numeric" values
actually, it is a token 20:21
```raku
token numeric-value {
[ '+' | '-' | '~' ]? <[ 0..9 ]>+ [ '.' <[ 0..9 ]>+ ]? [ 'e' <.numeric> ]?
}
token numeric-suffix {
perryprog pfft 20:22
klebs but then, as can be seen in "array-dimension" and "expression", my grammar currently uses <.numeric> to gobble numerics without regard for what is inside them 20:22
moon-child @klebs, part of your message got cut off here, but I expect you want lookahead
klebs thanks @moon-child -- i think I *almost* want lookahead, but I want the parsing to gobble the lookahead somehow so it goes away later in the parsing 20:23
moon-child oh. In that case, just nest the token in another, and only look at the inner token 20:24
klebs in other words, i want numerics, when they are used as <.numeric> to always just return their <numeric-value> with *no* suffix 20:25
Xliff \o 20:25
Xliff just purchased the parts for a new rig.
Threadripper arrives in 10 days! :q
moon-child threadrippers are nice! 20:25
Xliff moon-child: Have one? 20:26
Will be my first AMD build...
klebs the trouble is, I have a quite large codebase which unfortunately assumes everywhere that it can directly use numerics naked as they are
moon-child Xliff: yea. Work-provided, so I didn't have to foot the bill, too
Xliff www.newegg.com/amd-ryzen-9-5950x/p...6819113663 20:27
klebs so doing that nesting would be a breaking change in perhaps many locations
im looking for some way of hooking it somewhere so i can specify in one single place what i want to happen
which is for something like "18.05f" to parse successfully as "numeric", but come back as "18.05" when we ask for <.numeric> within another rule 20:28
is that possible?
Xliff moon-child: Hah! Nice. Unfortunately, I have to take matters into my own hands.
klebs perhaps i could edit the match object somehow? unfamiliar with the nuances of this 20:29
what about something like this? ```raku 20:34
#!/usr/bin/env raku
use v6;
grammar Numerics {
rule TOP {
<.ws> <array-dimension>
}
token numeric-value {
[ '+' | '-' | '~' ]? <[ 0..9 ]>+ [ '.' <[ 0..9 ]>+ ]? [ 'e' <.numeric> ]?
}
token numeric-suffix {
| 'f'
moritz_ please use a pastebin for code 20:34
klebs pastebin.com/raw/PZKtLesP 20:36
oh, moritz!! I bought and read your book! thank you so much! I will remember to write you an amazon review 🙂 20:38
it was great!
Xliff m: my token numeric { <numeric-value> <numeric-suffix>? { $/ = $/<numeric-value>; say "edited: $/" }; }
camelia 5===SORRY!5=== Error while compiling <tmp>
Unrecognized regex metacharacter ; (must be quoted to match literally)
at <tmp>:1
------> 3 = $/<numeric-value>; say "edited: $/" }7⏏5; }
expecting any of:
horizontal whitespac…
klebs super helpful to me
Xliff m: my token numeric { <numeric-value> <numeric-suffix>? { $/ = $/<numeric-value>; say "edited: $/" } }
camelia ( no output )
Xliff m: my token numeric { <numeric-value> <numeric-suffix>? { $/ = $/<numeric-value>; say "edited: $/" } }; say "18.04" ~~ &numeric
camelia No such method 'numeric-value' for invocant of type 'Match'
in regex numeric at <tmp> line 1
in block <unit> at <tmp> line 1
moritz_ assigning to $/ doesn't make much sense; using make() is better for extracting values and storing them in match objects 20:39
Xliff moritz: Would that code block be better served as <{ ... }> 20:39
Or does it matter?
moritz_ <{ ... }> is when you want to change the regex behaviour; { ... } is for pure side effects 20:40
Xliff Ah, thanks!
moritz_ to be precise, the regex engine interprets the result of <{ ... }> as a regex, and matches that 20:41
Xliff Why am I getting "Messages Failed to Load" on Discord every time I try to use it?
klebs i basically want to insert some sort of shim, because I unfortunately use <.numeric> all over the place in the grammar (which is quite large by now)
i want to gobble any numeric-suffix without ever passing it upstream
moritz_ maybe try to use )> then to limit the match object?
m: say 'abc' ~~ /a )> ../ 20:42
camelia 「a」
moritz_ it matches the whole string, but only includes the a in the match object
klebs oh, that does seem to be what i am looking for -- however it doesn't seem to be working when I try it within the grammar 20:44
in that same pastebin, when i insert it in between numeric-value and numeric-suffix 20:45
token numeric { <numeric-value> )> <numeric-suffix>? }
moritz_ then I really recommend going with { make +$<numeric-value> } and using $/<numeric>.made
shouldn't be too hard to find the usages with your editor's search function 20:46
Xliff Can I get an invite for the raku discord, please?
klebs <@742445366489645080> it is here: www.raku.org/community/ 20:48
@moritz_ I am wondering why )> works for the example you gave but not within the grammar I have
ie, pastebin.com/raw/2Ni0f5qR 20:49
moritz_ probably because the rest of the regex engine also thinks that the regex has only consumed the numeric part, not the letter after it 20:50
klebs i see 20:51
is that a bug? that seems the same as lookahead, no? 20:52
moritz_ I don't know if it's a bug or a feature. Could go either way. 20:57
klebs fair enough 🙂 20:58
that is a useful trick i didn't know though (at least for individual matches)
thanks!
moritz_ you're welcome
klebs your book was great 🙂
moritz_ thanks :D 20:59
always happy about ratings on amazon... (hint, hint) :-)
klebs i will write you a glowing review for sure!
moritz_ thanks :D 21:00
klebs what i liked about it the most was that it was basically 100% useful information, with an extraordinarily high ratio of information which was not obvious and unlocked higher usages of the skill itself 21:01
in fact, i i might use that sentence in my review 🙂 21:03
is there a way to edit the global match tree from within a { } block inside a token? 21:09
Xliff m: %h = ( a => 1, b => 2, c => 3 ); my $a = 'a'; %h{$a}:exists.say 21:24
camelia 5===SORRY!5=== Error while compiling <tmp>
Variable '%h' is not declared
at <tmp>:1
------> 3<BOL>7⏏5%h = ( a => 1, b => 2, c => 3 ); my $a =
Xliff m: my %h = ( a => 1, b => 2, c => 3 ); my $a = 'a'; %h{$a}:exists.say
camelia True