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.
10:26 MasterDuke left 12:44 greenfork left, KOTP left, greenfork joined, KOTP joined
lizmat and yet another Rakudo Weekly News hits the Net: rakudoweekly.blog/2024/08/05/2024-32-de-python/ 12:57
16:12 jgaz joined 16:55 lizmat_ joined 17:00 lizmat left
holmdunc If I write a string e.g. "\k" then I get the error message Unrecognized backslash sequence: '\k', but if I write e.g. "\-" or "\|" or "\?" then those are fine. What is it about the latter ones that makes them recognizable/allowed? 17:57
18:28 lizmat_ left, lizmat joined
antononcube @holmdunc Here is what I get asking LLMs your question: 19:27
cdn.discordapp.com/attachments/768...0f256&
holmdunc So the answer is tentatively something like "A backslash followed by a punctuation character, where the punctuation character is not one of these specific ones, has a result as if the backslash wasn't there"? 19:33
I had a look at docs.raku.org/language/syntax#String_literals and docs.raku.org/language/quoting and couldn't find any mention of this. Maybe I missed it though 19:34
librasteve @holmdunc - the Q-language (quoting language) is a sub-language (aka slang) of raku. The relevant docs are here - docs.raku.org/language/quoting#Int...cape_codes 20:07
in general (as with all of raku), the design is intended to ape the expected behaviour for simple cases "like perl double quotes\n" (same as the qq|xxx| ) form. Backslash behaviour may also be fine grained controlled via the :backslash (or :b) adverb, thus :qq (:double) means Interpolate with :s, :a, :h, :f, :c, :b 20:11
to keep it simple to remember, iirc the rule is you can backslash any punctuation character (ie <[punct]>) which is anything that is not an alphanumunder (ie <alnum]>) as defined here ... docs.raku.org/language/regexes#Pre...r_classes, whereas only a select few predefined alnums (like \n) are allowed 20:17
there is a lot of depth and fine grain control here - but remember the defaults are well chosen so that it works "like perl double quotes\n" and in the main you don't have to worry about what's under the hood 20:22
sadly the LLM answer hallucinates because it confuses the Q-language with regex escapes 20:24
why does raku do this (I hear you ask)? imo, it is an awesome set of tools that can be applied to fine tune the interpolation rules to just about any text source - once you can select the right combination of adverbs, raku can just suck up text (eg from other language source files) and do what you mean 20:30
holmdunc Cheers. As a touch point, Perl doesn't quite work for me 'cos IIRC I've never written a single line of it :D. Python seems to complain about all unrecognised backslash escapes, rather than the backslash sometimes melting away 20:37
a12l Re: docs.raku.org/type/Str#routine_uc It uc defined in two places, once in the Str class and one time outside of it? Haven't been able to find the implementation of the function in Rakudo's git repo. 20:49
librasteve yeah - sorry to use perl as an example, I simply mean the regular C-like languages, bash, PHP, etc that handle single and double quotes - Python quoting is a mystery to me 21:11
holmdunc No worries, I got what you're saying and thanks for the info on the wider picture. I guess another facet of e.g. "\-" is that even though the backslash melts away, in the process it can still act as a breaker to end an interpolated variable name, e.g. in "$abc\-def" 21:27
librasteve good point, I hadn't considered that 21:30
@a12l sorry I do not know the raku source - but, from the docs, we have this docs.raku.org/type/Str#routine_uc and this docs.raku.org/type/Cool#routine_uc - the difference as I perceive it is that the Cool variant coerces it's arg to Str and doesn't promise to return a defined result - so a subtle distinction 21:33
it took me a while to work out why we would want uc on Cool items, but consider this: ```
[0] > [1,2,3].Str 1 2 3 [1] > <a list of words>.WHAT (List) [2] > <a list of words>.Str a list of words 21:34
and this [3] > <a list of words>.uc A LIST OF WORDS
^^ it's just a way to save typing .Str.uc when there are many things that you may wish to print from your program apart from Str's 21:35
as you can see from the typegraph, class Str is Cool {...} so it inherits all the Cool methods anyway - but I think that the docs indicate that Str overloads uc and other methods for the reasons of the return type promise 21:41
21:57 MasterDuke joined