🦋 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.
SmokeMachine Voldenet, lizmat: Do you think it's better like this? github.com/FCO/RakuAST-Matcher/com...c97143910c 00:10
Voldenet SmokeMachine: definitely a lot easier to maintain, btw you don't need {} in `gather { $needle.visit-children: *.take }` ┐(´~`;)┌ 04:32
Voldenet but `my @needle = gather { $needle.visit-children: *.take };` would probably allocate large array without iterating anyway 04:34
`my $needles = gather $needle.visit-children: *.take; my $asts = gather $ast.visit-children: *.take; [&&] ($needles.Seq Z $asts.Seq).map(…)` would iterate 04:38
SmokeMachine Voldenet: I've forgotten to add `lazy` before the gather that was my intention 07:29
SmokeMachine Voldenet: Thank you 07:30
Voldenet i'm not a fan of lazy, because it'll still allocate arrays 07:32
which is not needed if it's simply fed to [&&]
SmokeMachine Voldenet: but I don't think those arrays would ever be very big, how many local children (not descendants) a node usually have? 07:38
m: say gather "1 + 2 + 3 + 4 + 5".AST.visit-children: *.take
camelia (RakuAST::Statement::Expression.new(
expression => RakuAST::ApplyInfix.new(
left => RakuAST::ApplyInfix.new(
left => RakuAST::ApplyInfix.new(
left => RakuAST::ApplyInfix.new(
left => RakuAST::IntLiteral.new(…
SmokeMachine m: say (gather "1 + 2 + 3 + 4 + 5".AST.visit-children: *.take).elems 07:39
camelia 1
SmokeMachine Voldenet: but yes, that makes sense 07:40
Voldenet btw, visit-children is not recursive
SmokeMachine yes, that was my thinking... 07:41
Voldenet in the worst case the matching tree can grow beyond the stack
m: say elems gather "1 + 2 + 3 + 4 + 5".AST.visit: *.take 07:42
camelia 15
SmokeMachine yes, with visit that could be a problem
Voldenet m: say elems gather '[&&] (@needle Z @ast).map({ match(|$_) })'.AST.visit: *.take
camelia ===SORRY!=== Error while compiling
Variable '@needle' is not declared. Perhaps you forgot a 'sub' if this
was intended to be part of a signature?
------> [&&] (⏏@needle Z @ast).map({ match(|$_) })
Voldenet m: say elems gather 'sub match(|c) { }; my @needle; my @ast; [&&] (@needle Z @ast).map({ match(|$_) })'.AST.visit: *.take 07:43
camelia ===SORRY!=== Error while compiling
Confused
------> &&] (@needle Z @ast).map({ match(|$_) })⏏<EOL>
Voldenet m: say elems gather 'sub match(|c) { }; my @needle; my @ast; [&&] (@needle Z @ast).map({ match($_) });'.AST.visit: *.take 07:44
camelia ===SORRY!=== Error while compiling
Confused
------> [&&] (@needle Z @ast).map({ match($_) })⏏;
SmokeMachine I can't do that, I would be comparing many things more times than needed...
Voldenet either way, visit does iterate and uses queue 07:44
instead of being recursive 07:45
I'm not sure how costly it is in terms of stack usage, but things could get ugly if you use it on large files 07:50
even if locally match used tiny arrays, the arrays may accumulate and get too fragmented to stay in caches in continuous form 07:56
either way, even that gigantic chunk would simply contain pointer, so it doesn't improve data locality anyhow 07:58
I'd still attempt to use visit instead, I'm betting it will handle worst cases better 08:05
tbrowder__ howdy, all. i have a module "unit class SomeLongName" A" and i would like to refer to the class as, say, S. then do this: my $s = S.new; 16:55
i've tried variants of "our \S is export = SomeLongName" but no luck so far. aliasing subs and other things seems pretty straightforward. 16:57
[Coke] you're trying to create the alias i mthe class def and export it too? 17:02
*in the*
I would expect you'd have have a module with the class and the alias exported, not a top level class in the file 17:03
lucs tbrowder__: Could ⌊class S is SomeLongName {}⌉ be enough? 17:09
tbrowder__ [Coke]: that was just a simple sample 'cause i'm used to the general syntax. 17:25
lucs: great, didn't think of that. i'll give it a try right now. thnx 17:26
[Coke] I would recommend not exporting an alias by default in code you expect others to use. 17:28
lizmat sub EXPORT { Map.new: ( 'SomeLongName' => SomeLongName, 'S' => SomeLongName ) } 17:35
note, I would let the consumer do the aliasing in general
use SomeLongName; my constant S = SomeLongName; 17:36
tbrowder__ luc's method works for me so far. 18:25
i put both defs in one module with nothing else. defined the Long class first. then: "class S is Long is export {}" and all is well 18:26
any downside? 18:27
lizmat m: class A { }; class B is A { }; dd B.^name 18:32
camelia "B"
lizmat m: class A { }; my constant B = A; dd B.^name
camelia "A"
lizmat not sure whether that is an upside or a downside
tbrowder__ hm, i like your way better, seems like a real alias to me 18:39
testing again now....
works great, exports fine, thanks 18:43
tbrowder__ opinion on a class name, please: "Array1'indexed" <= the apostrophe in a valid name, a very cool Raku feature 19:11
tbrowder__ m: class A'B { say "cool"}; my $b = A'B.new; say $b 19:12
camelia cool
A'B.new
leont I'm still not sure that was a good idea, but I'm extremely happy that - is legal (they follow the same rules, e.g. an identifier can't begin or end with either) 19:17
avuserow tbrowder__: I would generally not use it. Maybe in math-y code, or generated code to help with namespacing, or for a more inventive domain-specific languages?
though I do agree that kebab-cased variables are excellent 19:18
lucs tbrowder__: Yeah, I prefer lizmat's way too :) 19:44
tbrowder__ avuserow: yeah, agree. i think i've settled on "ArrayOneBased" for real name 20:00
lucs: i agree, but yr suggestion led to the solution! 20:01
lucs I kind of knew my answer was a bit off, but I know that Cunningham's law always has a good chance of manifesting itself :) 20:04
tbrowder__ i just released Algorithn 23:37
duh, AlgorithmsIT
Anton Antonov @tbrowder Reading it now. More importantly, that package name convinced me that the name I have chosen for my next-to-publish package is correct. 23:57