bancorn howdy! setup rakubrew, raku, and zef. tried a simple thing, installing HTTP::Tiny. wondered if this says anything obv to y'all: 00:01
[~/src/blockchain/tezos/raku]$ rm -rf /Users/jared/.zef/store/d31ded9e8b0651bd8babec0fcc39ff0a24625d51.tar.gz/
[~/src/blockchain/tezos/raku]$ zef install HTTP::Tiny
===> Searching for: HTTP::Tiny
===> Testing: HTTP::Tiny:ver<0.1.8>:auth<zef:jjatria>
[HTTP::Tiny] The spawned command 'touch' exited unsuccessfully (exit code: 1, signal: 0)
[HTTP::Tiny] in method mirror at /Users/jared/.zef/store/store/d31ded9e8b0651bd8babec0fcc39ff0a24625d51.tar.gz/lib/HTTP/Tiny.rakumod (HTTP::Tiny) line 185
[HTTP::Tiny] in block <unit> at t/mirror.t line 55
===> Testing [FAIL]: HTTP::Tiny:ver<0.1.8>:auth<zef:jjatria>
Aborting due to test failure: HTTP::Tiny:ver<0.1.8>:auth<zef:jjatria> (use --force-test to override)
[~/src/blockchain/tezos/raku]$ zef --version
I got it.. aborted due to a test failure. But doing a `--force-test` override let it install, and use a method 00:06
04:06 [Coke] left, [Coke] joined
avuserow Looks like the failure is in the `mirror` method. I would expect that to fail for you. (Or maybe the test was trying to mirror something where it didn't have permissions) 07:43
07:46 dakkar joined
gfldex <@!694526400488669234> Did you try Grammar::Debugger to check if it parses differently? 10:08
Anton Antonov <@!195453211409121280> No, I have not. I will try that. (I just installed `Grammar::Profiler::Simple` for more-or-less the same reasons.) 10:09
[Coke] If we want LSP support, should probably open a ticket in the "problem solving" repo 15:07
16:40 dakkar left
Nemokosch It would be nice 🙂 18:14
By the way... I want to do some sed-style substitution. What characters do I need to escape? How much does it differ from sed? 18:15
avuserow in regexes, there's three kinds of characters, roughly: 18:18
* alphanumeric - defaults to literal meaning, escaped has special meaning
* symbols - defaults to special meaning, must be quoted or escaped to match the literal character
* whitespace - defaults to ignored, must be quoted or escaped to match the literal character
alphanumeric includes underscore, so it's probably 1:1 with the `\w` character class 18:19
Nemokosch thank you very much 🙂 it's more logical than sed where ( ) + would go to the first group. I will pay attention to that 18:20
avuserow yeah, raku grammars and regexes are great. much more consistent even if it's difficult to unlearn the old habits of other tools 18:22
Nemokosch also Raku uses $1 $2 $3 over \1 \2 \3 right? like Perl I think
avuserow - might be of interest 18:23
and yes, raku uses the numeric variables, though I think it starts counting from 0.
m: "foobar" ~~ /(o)/; say $0; say $1; 18:24
probably needs a `:g` flag to get the second match, I keep forgetting that
Nemokosch so $0 is not the whole matching string? that's strange
avuserow well, `$0 $1 etc` are equivalent to `$/[0] $/[1] etc`, and that object is the result, so you're indexing into the list of matches 18:26
Nemokosch where is the whole string then? 😄 18:27
lakmatiol matching on a string will return a list of all matching substrings, captures are stored elsewhere 18:28
avuserow [Coke]: definitely a good idea. if we want editor integration then LSP is the way to go these days since you get support for basically every editor with one implementation. 18:30
Nemokosch okay so it was indeed the whole matching string actually 🤔 18:31
avuserow ah, yeah, in my example I was only matching a single character at a time 18:32
Nemokosch that coincided with the capture group
avuserow m: "foobar" ~~ m:g/(o)/; dd $/; # I should've written something more like this
m: "foobar" ~~ m:g/(o); say $0; say $1; 18:33
m: "foobar" ~~ m:g/(o)/; say $0; say $1;
like that. ☝️
Nemokosch I'm quite confused at this point, it's time to try it out xD 18:34
avuserow so $0 $1 etc are Match objects. this makes it easy to get other details beyond just the text, like the character positions and the original string. definitely give it a try 18:35
and if you just want the text, you can do `$0.Str`. I find this a bit less ergonomic than perl and I keep forgetting it, but it's way more powerful. and I wouldn't be surprised if there's some better way to get the match text 18:36
Nemokosch Gotcha 18:39
It makes sense but it's definitely different from what I used to in sed and also in Python 18:40
It makes sense but it's definitely different from what I'm used to in sed and also in Python
lakmatiol this is pretty close to python, just think of it like using findall by default and getting the list as a result in $/ 18:47
Nemokosch when exactly can parentheses be left off? I just realized that $ worked for me while $ 0 didn't 19:21
avuserow assuming you don't need them for precedence purposes, you can leave them off for function calls, and method calls with no arguments. method calls with arguments need them. 19:24
method calls without parens can also be written as: `$ 0` 19:25
Nemokosch wow 👀
also while we are at it - can I call seek like a bare function or am I going too far? seek($fh, 0) or something similar 19:26
avuserow only if `seek` is defined as a function in addition to a method. looking at, I only see it available as `method`, so not that one 19:27
functions like `join`, `split`, `push`, `pop`, are available as both though, so you can write: `(1..10).join(", ")` or `join(", ", 1..10)` 19:28
if you look at, you can see `sub join($separator, *@list)` . maybe best just to `ctrl+f sub` on those pages. 19:29
Nemokosch that's where the question emerged from 😄 19:30
avuserow yeah, no magic here, just code defined as both methods and subroutines. 🙂 19:31
Nemokosch Sorry for the question overload, I'm trying to do a little text processing 19:46
I have the following scenario: there is a C file that contains a certain preprocessor instruction (#if CPX for the matter) and the inside is always Pascal code 19:47
I have certain substitutions for turning the Pascal code into C code
and I can match the inside of this preprocessor instruction 19:48
how can I substitute the matching part for the result of my own substitution set if I don't want to do that all inline?
I suppose I should iterate over the matchings and then make some kind of call on them 19:51
avuserow if you have one match object at a time, then you can use Match.replace-with: 19:53
I suspect if you tried to use it on several match objects, it would get confused on the lengths. you could manage those offsets yourself, or maybe you can do a while loop with your regex 19:54
another idea is to use `split` on the document, and keep the delimiters. then you can operate on each chunk and join it back together 19:55
m: my $s = "a-b-c-d"; my @parts = $s.split("-", :v); for @parts {$_ = "_" if $_ eq "-"}; $s = join "", @parts; say $s; # long-winded way to replace dashes with underscores 19:57
Nemokosch Oh, I think I found something...
s// can apparently handle function calls 👀
avuserow oof, discord ate some of my underscores. `my $s = "a-b-c-d"; my @parts = $s.split("-", :v); for @parts {$_ = "_" if $_ eq "-"}; $s = join "", @parts; say $s;`
oh yeah that's always an option too 🙂 19:58
Nemokosch That's a pretty badass option actually 😄
I like how one can get used to these pleasant surprises with Raku 19:59
and I should use $/.Str as an argument probably 20:13
or well, $/ but eventually I will only act on the matching string I think
How do I pass a parameter as rw? 20:54
hm, or maybe my function declaration should mark this and then it would work? 20:56
seems like that's the right approach 20:57
hm, wait 22:20
subst doesn't set $/
ooh okay... now this wasn't very intuitive... 22:45
the replacement can be a string that can interpolate all random values stuck in $0 or $/ 22:46
that's not the same as using a string _inside a callable_ where those variables DO get updated
not very obvious when all the difference between an interpolated string and a callable is a pair of brackets 22:47
Anyways, I was quite satisfied with the outcome 😄 23:36
I have learned a lot and if I were to do this by hand, it would have taken not less time. The file was several thousands of lines and the relevant parts were all over the place 23:37