wayland76 Hi all! 09:14
librasteve good morning 09:35
wayland76 I'm trying to implement a bunch of operators that will allow us to walk trees like XPath. I've seen the .tree function (not well documented). I think I'm going to have to make some custom iterators for them. At the moment, I'm just trying to get .tree() to output each element separately instead of as an array. 09:39
m: <c b a>.tree(*.self.say) 09:40
camelia (c b a)
wayland76 What am I doing wrong?
m: <c b a>.tree(*.say) 09:41
camelia (c b a)
wayland76 Actually, I've figure I was getting over-fancy. But I'm still going to want something that walks a tree and just selects the nodes that match a function (like grep, but walks a tree). Any tips? 09:47
antononcube Look at Cases of Wolfram Language: reference.wolfram.com/language/ref/Cases.html 10:10
I strongly suspect that RakuAST is the best way to do this. Also, there are recent discussions here about similar functionalities. 10:18
See / search discussions around “tree-sitter”. 10:21
wayland76 antoncube: Interesting! The Wolfram one I'm assuming was for inspiration. The RakuAST stuff looks interesting, but I'm trying to a) make something that'll work at least somewhat on any nested data structure (which I'm not sure the RakuAST stuff does), and b) will call a "parent" method if available, to allow walking up the tree, or sideways, or whatever. 10:32
Anyway, I've got my operators for child, descendent, and self working, so I'll stop for the night (9:33pm here). I think the next step will be to have it match against a LibXML document. 10:34
I'm hoping to have operators that do most of the tree walking that XPath axes can do (parent, ancestor, following-sibling, etc). 10:35
lizmat tbrowder: re Data::Dump::Tree github.com/nkh/P6-Data-Dump-Tree/i...2668321046 11:14
tbrowder lizmat: thnx 11:39
m: say "\x[120]"; say "\c[100]" 11:40
camelia Ġ
d
tbrowder m: say "\o[200]" 11:41
camelia
tbrowder is there any way to use an octal number in the string to get a char? 11:42
i know you can in a pod string
postscript uses \nnn inside the string as a char refererenc, but i don't think that would work 11:44
m: say "\O[200]" 11:45
camelia ===SORRY!=== Error while compiling <tmp>
Unrecognized backslash sequence: '\O'
at <tmp>:1
------> say "\<HERE>O[200]"
expecting any of:
argument list
double quotes
term
lizmat m: say "\o[101]"
camelia A 11:46
lizmat m: say "\o101"
camelia A
lizmat looks to me \o does what you want ?
m: say 0o101 11:47
camelia 65
lizmat m: say 0o101.chr
camelia A
tbrowder yes, i'm no sure that's in the docs. the two hex and dec forms are together
lizmat if it's not in the docs, it should be :)
tbrowder yes, for sure 11:48
thank you! it makes my old redbook very useful again 11:49
m: say "0d10" 11:51
camelia 0d10
tbrowder m: say 0d10 11:52
camelia 10
tbrowder m: say 0o101
camelia 65
melezhik . 13:31
weekly: sparrowdo.wordpress.com/2025/02/19...sparrowdo/
notable6 melezhik, Noted! (weekly)
tbrowder i just submitted a docs PR 14:35
librasteve wayland76: sorry went out for a bit, how about 16:38
m: say [[1,2,3],[[4,5],6,7]].deepmap({$_ %% 2 ?? $_ !! Empty});
evalable6 [[2] [[4] 6]]
Raku eval [[2] [[4] 6]]
librasteve (or duckmap) 16:39
?
timo is there something convenient that's like "zef look" but instead of extracting a release it "git clone"s a distro's source repo to a folder on my disk? 17:15
melezhik. timo: I am recalling I did some automation , but not exactly what you are asking , if you just need a source code from tarball you may use this - sparrowhub.io/plugin/zef-fetch/0.001000 17:24
Maybe I can adjust it a bit and return scm repo via state as well, as long as it is valid in META6.json file 17:26
You can try out passing identity as a git repo and see what it does , I am not however sure that git scm is a valid zef identity 17:27
timo yeah i only want to clone the repo, only the latest - or specified - version that was released does not help me at all for what i want to do 17:29
melezhik. I just checked zef docs , so identity could be an scm repo , so you could do this “my $state = task-run ‘fetch thing’, ‘zef-fetch’, %( identity => ‘module git repo’); say $state<directory>;” 17:32
Does what you need to do 17:33
But you need to know scm repo
Or actually just - git clone repo , I dunno 🤷)) 17:34
timo yeah if i already have the scm url i don't need to do anything with zef. except the whole point is i don't want to find or type out the repo url, i want to have only the short-name of the distro and get a clone in a predictable place 17:37
i want to "hack-on Zef" and it would do something like `mkdir -p ~/raku/ecosystem/ugexe/github/zef/`, git clone zef in there, and optionally cd me into it 17:38
ugexe i usually do `zef look Foo::bar` although that isn't quite what you asked for since it will download tar.gz files and not put it in a predicable place (it goes in some temp dir i think) 17:44
you can do e.g. `zef browse zef source --/open` but that only works if they link the repo url in the support.source field of the metadata
(`zef browse zef source --/open` would output the repo to fetch to be clear - you'd still need to pipe it to git to actually fetch) 17:45
also sorry i didnt look back far enough to see you already mentioned zef look
timo right 17:46
ugexe i think `zef browse zef source --/open` fits the job, but most people probably dont fill out that field
you can get rid of `--/open` and it'll open a browser window to the repo 17:47
timo in the case of JSON::Fast, zef browse JSON::Fast source --/open will give 'browse' urls supported by JSON::Fast: source because the url is a git:// and therefore the check for http or https fails and zef considers it "not what you want"
is Zef::Client meant to be easy to use in a custom script or one-liner? what I ended up with now looks like `use Zef::Client; use Zef::Config; my $confpath = Zef::Config::guess-path; my $conf = Zef::Config::parse-file($confpath); my $c = Zef::Client.new(config => $conf); $c.search(...)` which is a little bit wordy and maybe the guess-path + parse-file case could get a shortcut somehow 17:48
ugexe i guess github.com/ugexe/zef/blob/080304e1...#L900-L903 should also not fire if --/open is specified 17:50
timo i could imagine a `zef script` with optional `--repl` that pre-initialises a Zef::Client with all the bells and whistles from the commandline arguments that zef has
or alternatively a `use Zef::Client::DWIM;`
but i have no idea if anyone else has needs to script with zef, so it could be a waste of time, too
ugexe there needs to be a real Zef::Configuration class that contains the configuration and works with Zef::CLI and MAIN param config options and ENV options 17:55
but yeah ideally Zef::Client would require less verbosity to use without providing a DWIM class that isnt otherwise used by any of the other code in Zef 17:56
timo right, if it's not used by Zef itself, it is likely to bit-rot without anybody noticing. test cases can only do so much if nobody shows up to write down all the implicit assumptions 18:07
wayland76 librasteve: Interesting! deepmap looks useful, but I'm really looking for a deepgrep. 20:33
timo you can use gather/take for that if you like 20:57
m: my @in = [[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]]; dd deepmap-with-if => @in.deepmap({ $_ if .is-prime }), deepmap-with-gather-take => (do gather @in.deepmap({ take $_ if .is-prime })).list; 20:59
camelia :deepmap-with-gather-take((2, 3, 5, 7, 11))
:deepmap-with-if([[[2, 3], [5]], [[7], [11]]])
timo depends on what you want, gather/take will give you a flat result, deepmap with if will keep the structure
ah i see librasteve already showed how Empty can do that 21:00
wayland76 Nice! I'm after the flat structure. Thanks! 21:01
timo i've never actually used ** aka HyperWhatever before, but i did not expect this: 21:03
m: dd [[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]][**]
camelia (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12).Seq
librasteve .oO
timo but what i did expect, after seeing that, was for postcircumfix:<[]> with ** would also allow :kv and :p and friends
librasteve m: [[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]].flat(:hammer).say 21:05
evalable6 (1 2 3 4 5 6 7 8 9 10 11 12)
Raku eval ([[1 2 3] [4 5 6]] [[7 8 9] [10 11 12]])
timo right, :hammer is also relatively new AFAIK 21:06
librasteve yep - but I wonder if it plays nice with :kv | :p 21:07
timo not sure flat is actually a place i'd expect those adverbs to apply 21:09
librasteve not sure I understand what you meant with HyperWhatever playing nice with kv | p 21:10
guess I need an example
timo well, for the tree-ified numbers between 1 and 12 i was hoping for something like `(0,0,0) => 1, (0,0,1) => 2, (0,0,2) => 3, (0,1,0) => 4, ...` 21:11
librasteve well - can't help on that - but tx for introducing me to HyperWhatever ;-) 21:16
wayland76 I have a question. I'm using the XML module by lizmat, and it says "Unless you are doing something that requires direct access of the @.nodes property, it's probably easier (and less noisy) to use the array access syntax.". However, at some point (when passing to a function), I get the error "Type check failed in binding to parameter '@inputs'; expected Positional but got XML::Element ((my \XML::Element_44...)"
timo it really feels like we should have an ecosystem module with an implementation of what i just described 21:18
wayland76: that sounds like passing a single element to a constructor's argument that would want an array (or similar)
timo what module is that exactly? i don't see one by liz in the ecosystems? 21:21
wayland76 Sorry, it's a community module and GitHub has her name on it.
raku.land/zef:raku-community-modules/XML
github.com/raku-community-modules/...nt.rakumod 21:22
timo ah right, that's the last commit that changed the file
i think what that message (comment?) you pasted is refering to is that you would use $my-element[3] for getting a node's fourth child node 21:24
wayland76 timo: agreed. However, I have some code that's testing for that, and I've been using $item ~~ Positional, but now I'm going to have to start testing for .can('AT-POS') or whatever. I'm of the opinion that XML::Element should also be marked "does Positional does Associative". 21:26
timo oh, yes it makes sense that if it has these methods it should also do that role 21:31
librasteve since a community module, maybe a PR would help? 21:35
wayland76 librasteve: Agreed; I hope to get to it, but for now, I've made an issue instead. 21:36
librasteve ++ 21:38
also a lot of raku is kinda stubs for more work ... I would love to see clean and simple primitives for tree walking in a module that could ultimately become part of the core 21:40
antononcube I would love to see gcd on Rat’s. 🙂 21:47
Doing that later today… 21:48
librasteve diy
dont forget the gaussian complex no's
wayland76 Regarding a tree module, likewise. 21:49
If I get this done, it might be a step in the right direction; an inspiration/basis for the core tree-walking modules. It seems achievable at the moment, if I don't run into too many more bugs. 22:00
Anyway, off to work. Good $time-of-day to you all :)
antononcube @librasteve I implemented the GCD for Gaussian integers already. It is needed to factorize Gaussian integers, (also implemented, now.) 22:16
timo randomly responded to two of the XML github issues 22:19
antononcube It turns out that Perl has a comprehensive Number theory package. And -- surprise, surprise -- that Perl package follows and mentions Mathematica a lot and often. 22:29
I referring to "Math::Prime::Util::GMP". 22:30
timo here's a question / concern / bike shedding oportunity about a page in the docs: github.com/Raku/doc/pull/4555#issu...2669915588 would be happy for some input 22:36