🦋 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.
Xliff guifa: Actually, the trait would apply a role which would contain bot an $!ast attribute and an .AST method. If detected, any callable will preserve it's AST in $!ast to be retrieved at runtime by .AST() 00:00
s/any callable/any properly marked Callable/
guifa yeah, what I mean is that I believe it's still undecided if a trait's sub will receive the callable itself or the AST of the trait
obviously, a LOT can be done with the latter 00:01
but as it's done now, all code assumes a compiled sub
if the decision is made to enable some way for a trait to get the AST
then it would be very easy, as the trait could mix in the role with that attribute
Xliff My point exactly.
guifa (obviously, I'm missing back story, I just saw your message to lizmat) 00:02
Xliff That's part of a plan I have to take Raku code and output JS for web-based use cases.
Take RakuAST and then transform the nodes to JavascriptAST for eventual .DEPARSE
role ASTPreserved { has $!ast; method .AST { $!ast }; method Str { $!ast.DEPARSE } }; 00:26
Now.... where to put it..... Actions.nqp? But I want it exposed to Raku.
guifa wonders if what should be done is for trait_mod subs to themselves have traits to be either run at { or at }. Right now it's always } 00:43
tonyo is that already started? the rakuast -> js ast? 00:49
Guest94 librasteve it does not change anything for me. When I use Timestamp grammar/parser I trust it to know what it is. I don’t know to worry about dedicating it some specific chunk. 01:01
Timestamp already knows how to parse it.
*I don’t want to worry about... 01:02
What if it was parsing data like `2024-01-02T12:34+01:00GMT` 01:03
Then `\w+` won’t work anymore.
01:28 kylese left 01:32 kylese joined 01:36 Some-body_ joined 01:39 DarthGandalf left, Some-body_ is now known as DarthGandalf
guifa Guest94: I believe both me and codesections had a discussion on this aobut a year or two ago 01:42
There's several different ways for integrating one grammar into another
Guest94 You mean apart from `is`? 01:44
I would even say `is` is not integrating one grammar into another, it just inherits a bunch of tokens omitting the most important high-level one — TOP 01:45
But nothing really works for my artificial simple example, and we’ve been discussing this quite a bit already here 01:47
So I wonder if there is even one way that works
guifa www.reddit.com/r/rakulang/comments...oughts_on/ Take a look at some of the comments 01:48
tio.run/##jVC9TsMwEN7zFKc2UhMTpYKB...QKkIodx/AE
You can tweak that to make it more elegant for specific-case scenarios rather than the general case that it was designed for 01:49
Guest94 www.codesections.com/blog/grammatical-actions/ this page is 404 01:52
guifa Note I said comments
Guest94 I noted
But there might be some good context there too, right?
There seems to be a web-archive snapshot from year 2022 01:53
guifa eh potentially. I don't know why that one 404s. We were going back and forth a bit so he might have taken it down in favor of a newer article
tonyo Guest94: what doesnt work in any of the given solutions 01:55
Guest94 tonyo It does not parse. Because <timestamp> is in the middle of the Filename TOP, not at the beginning. And there is also something after it. 01:56
tonyo what do you mean not at the beginning? 01:57
guifa tio.run/##jZDNTsMwEITveYqRiNSmrQKE...jdbuCsrn8A
tonyo also, how have you changed it and how is it failing?
guifa wonders why this isn't exactly what Guest94 wants
tonyo i'm getting the sense that this is just crowd source guessing an acceptable solution 01:58
guifa grammar Foo assumes no knowledge of the timestamp grammar, other than the identity of the actions class associated with it. It integrates perfectly, with a controllable top level name
Guest94 tonyo you suggested this:
grammar A { rule TOP { ^ "a"+ $ } }; grammar B { rule TOP { ^ <call-a-grammar> $ }; token b { "b"+ }; }; B.^add_method("call-a-grammar", -> *@_, *%_ { A.parse(@_[*-1].orig) }); dd B.parse("aaaa")
Where <call-a-grammar> is at the beginning of the B::TOP
tonyo yea, that was the least good as i stated then
Guest94 Based on that I tried to apply it to my artificial example: pastebin.com/8M25pvWm
Where <call-a-grammar> is a <timestamp> in my case 01:59
But it won’t work because @_[*-1].orig return the whole input string while the TOP rule looks like rule TOP { <name>'-'<timestamp>'.'<extension> }
You can see there is `<name>'-'` in front of it and `'.'<extension>` after. 02:00
02:00 DarthGandalf left
Guest94 Timestamp grammar won’t parse because it’s getting also `foo-` and `.bar` apart from it needs. 02:01
02:01 evalable6 left
Guest94 I made it to parse by cutting off the beginning by reading the `.pos` of already parsed chunk and replacing parse to subparse so that it can consume partially: 02:02
Timestamp.subparse(@_[*-1].orig.substr(@_[*-1].pos))
But the fact this *method* consumed something does not seem to propagate properpy up to Filename grammar so it fails to parse when trying to parse `'-'<extension>` as far as I can see 02:03
guifa that example could be what I’m looking for, I need to test first 02:04
guifa Guest94: why are you using parse? You should be using subparse
parse will tell TOP to assume ^ and $
Guest94 I took tonyo’s suggestion, and I actually did change it to subparse
guifa ah ok, in the most recent pastebin it had parse, hence the question 02:05
Guest94 That’s just the only pastebin I dropped here. I only added in the chat here that I tried to do this: Timestamp.subparse(@_[*-1].orig.substr(@_[*-1].pos)) instead
Which actually parses Timestamp, but it does not integrate properly with the higher-level Filename grammar 02:06
02:39 kylese left 02:40 kylese joined 02:49 jpn joined
tonyo dang, forgot about subparse 02:50
you'll need to combine librasteve's thing in there
err, something like it 02:51
02:53 bartolin left, bartolin joined 02:54 jpn left 03:15 kylese left 03:17 kylese joined 03:56 opus left
Guest94 Woah, this really works: pastebin.com/5k294nfZ this looks exactly how I was imagining. Thanks guifa 04:39
Though the only big problem I see here is when the parsing fails. There are a lot of errors written to the log and the failure is actually masked. 04:40
It does not fail the program, it only misbehaves later. 04:41
It looks like this if I just add a space at the beginning of the string I try to parse: pastebin.com/4Xks0MEm 04:42
Adding *defined* type helps to prevent the error masking Match:D 04:52
What is the best way to handle parsing failures? 04:55
Is checking for .defined good enough? Do grammars provide any extra info when parsing fails? 04:58
tonyo that seems like a problem left up to the reader : ). you could use a try
try { .subparse ... } // Nil 04:59
or whatever they're supposed to return
maybe it's Failure
Guest94 I actually don’t know if the problem is in that new method. Do the grammars throw exceptions on parsing by default? 05:03
It doesn’t seem so. If the parsing fails it’s just Nil 05:04
If if there are no nesting of other grammars, only tokens
I’m fine with that, just wondering if maybe there is some relatively useful data obtainable for an error message 05:05
Some Match object with partially consumed/parsed chunk could be useful for debugging for instance 05:08
05:09 epony left
Guest94 Is there some way to validate an expression against some type without creating a variable? 05:21
Can I somehow filter keys of a hash? Like apply a predicate that decides where to keep the key or omit it? 05:35
05:53 Xliff_ joined
Xliff_ \o 05:53
antoncube: You around?
06:12 Xliff_ left 06:13 Xliff_ left
Guest94 I assume I can use dummy variable for inline type-checking? Like this: my SomeType:D $ = someExpr 06:32
What method or whatever would you suggest as .reduce but with an accumulator? 06:36
I want to write an expression that would populate some value (e.g. an array or a hash) 06:37
From what I can see unlike in other languages .reduce (aka fold) in Raku is not designed to take accumulator. 06:38
It only applies some operation producing the same type?
06:47 Aedil left 06:50 Aedil joined 07:06 notable6 left 07:18 jpn joined 07:22 jpn left 08:29 abraxxa joined 08:31 abraxxa1 joined 08:35 abraxxa left 08:41 DarthGandalf joined 08:44 sena_kun joined 08:55 maylay left 08:58 maylay joined 09:33 Sgeo left 09:35 jpn joined 09:41 jpn left
nemokosch The "producing the same type" part is more just a semantic expectation than anything enforced 09:48
09:50 jpn joined
And you are right, there is no dedicated accumulator, neither a dedicated direction. The operator decides. You'd have to add the initial value at the right position 09:51
Re filtering keys: grep works, it will take Pairs and produce a sequence of Pairs that you can convert back 09:54
m: my @lottery = (1..100).pick(10); dd @lottery; my %groups = @lottery.classify(* % 5); dd %groups; dd %groups.grep(.key > 2); %groups.=grep(.key > 2); dd %groups 09:58
Raku eval Array @lottery = [23, 83, 7, 56, 26, 18, 60, 19, 39, 86] Hash %groups = {"0" => $[60], "1" => $[56, 26, 86], "2" => $[7], "3" => $[23, 83, 18], "4" => $[19, 39]} ("3" => $[23, 83, 18], "4" => $[19, 39]).Seq Hash %groups = {"3" => $[23, 83, 18], "4" => $[19, 39]}
nemokosch Casually ate up a few asterisks 09:59
Of course it was *.key > 2
10:07 jpn left 10:17 jpn joined 10:18 abraxxa1 left 10:23 jpn left 10:28 jpn joined 10:34 mark22k left, mark22k joined 10:36 Xliff_ joined 10:37 jpn left 10:38 Some-body_ joined 10:41 DarthGandalf left 10:42 Some-body_ is now known as DarthGandalf
guifa re grammars, no, they don't throw exceptions on fail. There are ways to do it, for instance, in your Filename, if you want it to throw if the timestamp is invalid... 11:09
<name> '-' [ <timestamp> || <.bomb> ] '.' <extension> 11:10
and then have a method called <.bomb> which could throw an error and potentially output the current match tree
err
method bomb { die "There was a problem at " ~ self.to } 11:11
nemokosch in an eager and "voluntaristic" parser like this, the concept of parse error isn't very much established 11:12
at the end of the day, the only objective statement is that the parsing failed - why it failed requires certain assumptions about what was surely good 11:13
guifa right. At best we could do is have a bomb for each of the five components -- but that only tells us which component was bad, not what was bad about it 11:16
And given the idea that we can't introspect the timestamp since it's coming from someone else's module, that's pretty much as good as we can get
11:30 Guest94 left 11:48 jpn joined 11:54 jpn left 12:33 jpn joined 12:38 jpn left 12:42 abraxxa joined 12:49 sjn left 12:55 sjn joined
nemokosch makes sense 12:58
13:07 TieUpYourCamel left
lizmat discord people: what would be a good URL to use to point to you people on Discord ? 13:20
13:22 merp left
lizmat nemokosch librasteve antononcube ^^ 13:24
13:26 timo left 13:27 merp joined 13:28 timo joined 13:34 jpn joined 13:39 jpn left
antononcube @lizmat Hmm… do you mean individually? 14:01
lizmat no, to the Raku community on Discord 14:02
where people would go if they want to join
antononcube Right — I used the link on raku.org .
discord.gg/VzYpdQ6 14:03
lizmat ah, good point thanks both!
and yet another Rakudo Weekly News hits the Net: rakudoweekly.blog/2024/01/02/2024-...-map³-sum/ 14:21
nemokosch lizmat: the happier syntax sugar in python is not Konstantin Narkhov I think 14:33
lizmat Indeed.. oops.
Fixed, thanks for the headsup! 14:34
14:35 jpn joined 14:40 jpn left 14:42 melezhik joined
melezhik o/ 14:42
Happy new year
lizmat melezhik: insgelijks! (that's Dutch for "the same to you!" 14:43
melezhik Just published a small article on new Sparky feature - dev.to/melezhik/sparky-self-hosted...le-ui-4m0n if someone is interested
lizmat: thanks 😊
lizmat you just missed the weekly: it will be in the next :-) 14:44
melezhik Have some free time on holidays , it's cold in here , so decided to write some stuff
No worries Liz
lizmat posted on Reddit and programming.dev 14:45
14:50 melezhik left
antononcube What is the proper way to refer to articles in the advent blog? The full name with the "Day XX" prefix, or just the rest of the name? 14:52
14:52 melezhik joined
melezhik Thanks a lot, Liz! 14:53
lizmat antononcube depends a bit on context, either would be fine, I'd say 14:54
librasteve .oO .subparse & method-as-token, eh? nice one tonyo! tbh I was frustrated since it's easy to combine tokens (via is / does / maybe MOP method surgery) but quite a struggle to combine Grammars ... until you know the recipe
pity this Q&A is not on StackOverflow as will be hard to find later when I need it 14:55
Guest94: a good challenge - thans for your patience!!
14:57 melezhik left
Geth ¦ problem-solving: lizmat unassigned from codesections Issue TAP refers to Perl 6 github.com/Raku/problem-solving/issues/416 15:12
15:28 jpn joined 15:36 jpn left, jpn joined
tonyo hah, librasteve it was definitely a group effort 15:42
15:42 jpn left 15:56 abraxxa left 16:20 jpn joined 16:25 jpn left
[Coke] If you include the "day" you should include the year, probably, otherwise it won't age well 16:31
16:38 jpn joined 16:42 jpn left 16:47 jpn joined 17:16 Guest94 joined
[Coke] just opened raku REPL on my mac and getting tons of complains about Cannot locate native library '/var/folders/8n/rypl9_990b9578zd5435pgr40000gn/T/.zef/1702343732.20256/1702343741.20256.5645.427279618365/resources/5342239100523A11F35C47F949A6974841869956.dylib' 18:07
Haven't run the REPL in a week, but haven't touched rakubrew recently either.
El_Che did you update the OS or homebrew? 18:10
18:34 Guest94 left
[Coke] Nope 18:38
El_Che mm 18:39
[Coke] had Terminal::LineEditor installed. Just did a download (not a build) of 2023.12 via rakubrew, will reinstall T::LE and see if it works. 18:40
yup. 18:41
weird. the folder it's complaining about seems like a zef temp folder, no? 18:42
is there a zef command to clean out any builds/downloads? 18:43
ok. with the new setup that works, if I delete $TMPDIR/.zef, it breaks again 18:45
... I'm guessing the previous failure was due to a reboot and tmp cleanup, then 18:47
ugexe: ^^
once it generates this error, not sure how to get it back. Forcing a re-install doesn't fix it 18:58
uninstall/reinstall doesn't work.. 18:59
ah, might be a bug in LineEditor itself: github.com/ugexe/zef/issues/546 19:04
(Though why it would persist over a re-install of the module, not sure) 19:05
japhb: ^^ Anyone else report this issue? 19:07
ah, it's Term::termios 19:12
Don't see the RESOURCES .Str issue in particular there.
19:15 abraxxa-home joined 19:16 abraxxa-home left 19:18 abraxxa-home joined
[Coke] github.com/krunen/term-termios/issues/22 19:32
.seen krunen
tellable6 [Coke], I saw krunen 2016-01-09T16:24:27Z in #perl6: <krunen> [Coke]: (re moving Rakudo release tags) I thought I only said it was talked about at some point, but confused discussion happened. Sorry.
19:36 jpn left
[Coke] github.com/retupmoca/P6-LibraryMak...akumod#L89 - is calling .absolute also going to cache the value? 19:40
(like .Str does in the zef issue above)
ugexe uninstalling it and/or reinstalling it should fix it yeah. although if its a dependency causing it i'm not sure if you'd have to also reinstall any reverse dependencies 19:46
[Coke] Does that .absolute call look sus? 19:47
jdv is sus a word now?
ugexe That .absolute call (or anything that stringifies %?RESOURCES) is arguably wrong. but what you linked is documentation, not actually using it 19:48
19:59 jpn joined
ugexe I suppose we should also deprecate Distribution::Resource .absolute and .relative 20:00
20:06 jpn left
ugexe [Coke]: I wonder if you have an older version of Term::termios installed? github.com/krunen/term-termios/com...894849e07d 20:08
ah right, the depends of Terminal::LineEditor pin to Term::termios:ver<0.2> but the commit above is v0.2.7 20:11
Apparently it pins to v0.2 because of bugs in the later 0.2, so just installing a newer Term::termios manually might not fix it 20:13
20:27 jpn joined 20:31 jpn left
[Coke] jdv - it is here, for sure. 21:33
21:36 Guest94 joined
Guest94 Is there some universal namespace wrapping in Raku? Like if I want to define multiple subroutines but put everything under a namespace. 21:43
Something like: my \ns = namespace { sub foo {} sub bar {} }; ns.foo; ns.bar?
[Coke] docs.raku.org/language/packages 21:45
guifa package Foo { sub a { ... }; sub b { ... } }; Foo::a, Foo::b. Just be aware that while subs are by default our-scoped, variables will not be. If you want to my-scope a routine within a package (make it invisible to the outside world), just do `my sub c { ... }` to adjust the scope 21:47
jdv ha 22:06
librasteve m: package Foo { our sub a { 1 } our sub b { 2 } } say Foo::a, Foo::b; 22:18
Raku eval Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Bogus statement at /home/glot/main.raku:1 ------> package Foo { our sub a { 1 } o⏏ur sub b { 2 } } say Foo::a, Foo::b; expecting any of: whitespace
librasteve m: package Foo { our sub a { 1 }; our sub b { 2 } }; say Foo::a, Foo::b; 22:19
Raku eval 12
librasteve m: package Foo { sub a { 1 }; sub b { 2 } }; say Foo::a, Foo::b;
Raku eval Exit code: 1 Could not find symbol '&a' in 'Foo' in block <unit> at main.raku line 1
librasteve sub is my-scoped by default 22:20
Guest94 m: package Foo { sub a { 1 }; sub b { 2 } }; say a, b;
camelia ===SORRY!=== Error while compiling <tmp>
Undeclared routines:
a used at line 1
b used at line 1
librasteve stackoverflow.com/questions/337887...-rakuperl6 22:23
Subroutines default to lexical (my) scope Methods default to has scope (only visible through a method dispatch) Type (class, role, grammar, subset) and module declarations default to package (our) scope Constants and enumerations default to package (our) scope
also some good advice from jnthn when to do what (eg. use my scope with is export)
m: package Foo {sub a is export {1}; sub b is export {2}}; import Foo; say a,b; 22:43
Raku eval 12
librasteve stackoverflow.com/questions/346886...he-program
docs.raku.org/language/module-pack...th_modules 22:46
and docs.raku.org/language/modules#UNIT::EXPORT::* if you want to get fancy 22:49
nemokosch well, this is not great... rakubrew fails with the error Steve already opened an issue for, and rakudo-pkg installs some horribly obsolete version 23:09
for the new VPS, Debian 12
eventually I just wget'd the deb file and installed it with dpkg 23:10
23:11 Guest94 left 23:19 sena_kun left 23:22 Woodi left 23:44 Sgeo joined 23:58 abraxxa-home left