This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html
Set by lizmat on 8 June 2022.
01:16 razetime joined 03:56 razetime left 05:41 siavash joined 08:15 teatwo left, tea3po joined 08:16 tea3po left, tea3po joined 08:17 tea3po left 08:48 razetime joined 09:13 teatime joined 10:15 NemokoschKiwi joined 10:23 NemokoschKiwi left 10:36 siavash left 13:33 razetime left 14:33 NemokoschKiwi joined 14:36 Tirifto_ left 14:39 Tirifto joined 14:40 Tirifto left 14:41 Tirifto joined
jgaz In Raku, how do I match N of some repeating character? I tried ~~ /\d{3}/ but that appears to be wrong. 16:48
nemokosch using the ** operator 16:49
\d ** 3
jgaz thanks... why the change in syntax from {n}?
Also, will that break something like /^^\d ** 3 1/ where I'm looking for any 3 digits at the start of a string followed by a one? 16:51
nemokosch I wouldn't know by heart if {} has a special meaning inside regexes but I don't particularly fancy that syntax either 16:54
Raku regexes were designed to be pleasant and readable, not compatible with one of the dozen of ad-hoc regex dialects 16:55
I think that's perfectly fine for "any 3 digits followed by a 1, right after the beginning of the line" 16:56
I think ^^ is for lines
jgaz It certainly helps ditch the line-noise comparison. Thanks for the help. 16:58
antononcube It does -- it specifies a code to be executed together with parsing by the regex. For example, it is a way to include make statements in a grammar. (I.e. not to have a separate class for the actions.) 17:30
nemokosch I just clicked on this issue github.com/Raku/doc/issues/4112
antononcube Hmm... I think I read that in the book "Parsing with Perl 6 Regexes and Grammars: A Recursive Descent into Parsing" by Moritz Lenz. 17:31
Yeah, see page end of Chapter 4 fo that book. (Page 46.) 17:33
| Syntax | Description | |---|---| | `{ CODE }` | runs perl 6 code; no effect on regex match. | | `<?{ CODE }>` | Code needs to return a true value for the match to succeed. | | `<!{ CODE }>` | Code needs to return a false value for the match to succeed. | | `<{ CODE }>` | result of code is interpreted as a regex. | | `<$STRING>` | Interprets $STRING as regex source code. | 17:38
I made the Markdown table above looking at book's table 4-3. 17:39
nemokosch manually or using some magical tool you created? ^^ 17:40
17:40 NemokoschKiwi left
antononcube You are so sharp!! Yes, using the "magical tool" I created. 🙂 17:43
Here is a proof screenshot. But in all fairness this could have been done over the Web interfaces of OpenAI and Bard/PaLM. 17:46
cdn.discordapp.com/attachments/768...egexes.png
nemokosch where is the input, though? 17:50
antononcube Hmmm... I think the input is obvious; the green text. 17:51
nemokosch what is $^a $^b then?
oh okay nevermind 17:52
the wall of text in the middle
but the interesting part would be getting that wall of text 😛
antononcube Here is the code I used: use LLM::Functions; ‌‌my &fmdt = llm-function({"Convert to a Markdown table with columns $^a the text: $^b."}, llm-evaluator=>'PaLM'); ‌‌&fmdt('"Syntax" and "Description"', 'Syntax { CODE } <?{ CODE }> <!{ CODE }> <{ CODE }> <$STRING> Description runs perl 6 code; no effect on regex match. Code needs to return a true value for the match to succeed. Code needs to return a
false value for the match to succeed.
Yes, I looked up the table from the book. (To get the text.) 17:53
The "magic" was to use an LLM to "transpose" the text into two column Markdown table. 17:54
Here is a similar result using Bard's interface directly: 17:57
cdn.discordapp.com/attachments/768...egexes.png
19:31 ab5tract joined 20:06 ab5tract left
librasteve {} in regexes was repurposed to call a function (similar to {} in strings) 20:11
20:14 teatwo joined 20:17 teatime left 20:24 teatwo left, teatwo joined 20:47 ab5tract joined 21:17 ab5tract left 21:32 wafflus joined
wafflus how do i defeine a new operator ? i tried this and it didn't work: pastebin.com/YyudX7uN 21:33
nemokosch The REPL is not clever enough to remember operators from previous reads 21:34
wafflus it works if i say type x but not for unicode symbols 21:35
nemokosch Other than that, i think you're doing it right
wafflus k
lizmat the problem is that the infix sub *is* defined and accessible, but the grammar tweak isn't
in the REPL 21:36
nemokosch x exists as a built-in, probably that's why it worked
It didn't have to be grammar-tweaked
wafflus ok i will test
lizmat if it is non-existing, the grammar needs to be tweaked :-)
wafflus ok it works ty 21:38
does anyone know if i can view all the methods and paramters on an object? atm i'm having to look up using an internet search and it doesn't feel too nice 21:40
nemokosch If you don't mind digging into the metamodel, sure 21:49
There is $obj.^attributes, for example
Similarly, there is $obj.^methods 21:50
wafflus yeah just accidently discoverd that one just now
thowe What's the best way to sort by two things? I want to sort by a name alphabetically, and then sort by a numeric value under the name. Kind of like two order by fields in a SQL query... These fields are hash values in an array of hashes. 22:00
oh, wait... is that built in? 22:01
22:03 wafflus left
thowe bloody hell, that was easy. I love Raku. 22:06
antononcube @thowe 🤔 Can you give an example? 22:11
thowe my @newlist = @service_list.sort: {.<customer>, .<service_name>, .<service>};
isn't there a shortcut for making the sorted list @service_list instead of making a new array "@newlist" ? 22:12
nemokosch .=sort 22:13
thowe of course...
nemokosch Watch out, you can't chain on the left handside, it has precedence as high as a usual method call
Right handside 22:14
Casually mixing up left and right just like that
thowe so is this wrong? : @service_list.=sort: {.<customer>, .<service_name>, .<service>};
nemokosch This will DWYM 22:15
thowe yeah, I already tested it, just didn't want to fall into a trap
nemokosch If you use the colon syntax for arguments, you probably won't have a lot of temptation to chain on the right 😛 22:16
thowe Cool. Now I used Raku to help me finish my audit before billing instead of Perl... \o/ I did a thing! I'm so easily entertained. 22:20
22:32 ab5tract joined 22:43 ab5tract left