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. |
|||
jaguart | oh maybe I'm confused because .WHO.gist shows more meaningful than .WHO.raku | 00:04 | |
ok - so use MyModule; MyModule.WHO returns the Modules Stash aka MyModule:: which looks like its { :MyClassOne<MyModule::MyClassOne>, ... } ie pairs of local name -> fullname | 00:19 | ||
Nemokosch | stash = symbol table hash | 00:20 | |
jaguart | MyClass.WHO returns the class stash - but can't see how I can get to the Module from the Class | ||
I also don't understand the diff between package and module :( | 00:22 | ||
Do you put your classes in packages and your subs in Modules? | 00:23 | ||
Nemokosch | www.youtube.com/watch?v=NYBc3tQEIh4 all I know, I know from this mega class | 00:24 | |
I watched it within the last week | 00:25 | ||
I'm trying to look up that part but the point was that packages are basically a lower-level construct in Raku, they back up modules as well | 00:26 | ||
it also answered one of my former questions (how to call an inherited method) on the way | 00:28 | ||
jaguart | ok, so maybe its as simple as: package is a namespace, module is a namespace with ver and auth, class has ver and auth but is not a namespace -> so put it in a package or a module | 00:29 | |
Nemokosch | Stash examples start around 2:06:.. by the way | 00:30 | |
jaguart | thanks | ||
Nemokosch | 2:16:48 "Raku actually has two similar concepts, it has packages and it has modules..." | 00:40 | |
"package just declares the namespace (...) module inherits from the package, it does a little bit more" | |||
00:41
razetime joined
|
|||
jaguart | TIL Foo:: ===> great video, added to favs | 00:45 | |
00:58
RTB47 joined
00:59
RTB47 left
|
|||
deoac | Given the Str "MyClass<2446066483976>", is it possible to retrieve the actual class object? | 01:05 | |
01:15
discord-raku-bot left
01:20
discord-raku-bot joined
01:22
human-blip joined
02:00
discord-raku-bot left,
discord-raku-bot joined
02:05
discord-raku-bot left,
discord-raku-bot joined
|
|||
jaguart | Do you mean kind of like get the object at a memory location? | 02:10 | |
You might be able to walk through all the things in your namespace and see if any of their .WHICH matches your ObjAt.Str? | 02:11 | ||
m: say ::.keys | 02:13 | ||
camelia | ($_ $! $=pod GLOBALish $=finish ::?PACKAGE EXPORT !UNIT_MARKER $?PACKAGE $/ $¢) | ||
jaguart | m: my $a='a'; my $b=Hash.new; say ::.pairs.grep({ .key ~~ /^^ \$ / and .value.DEFINITE }).map({ .key ~ ' -> ' ~.value.WHICH }); | 02:41 | |
camelia | ($/ -> Match|6104765595648 $=pod -> Array|6104780987304 $a -> Str|a $b -> Hash|6104898989504) | ||
02:43
discord-raku-bot left,
discord-raku-bot joined
02:46
gfldex left,
gfldex joined
02:48
discord-raku-bot left
02:49
discord-raku-bot joined
|
|||
jaguart | Is there a way to instantiate a class named withing a string without EVAL? | 03:13 | |
m: use MONKEY-SEE-NO-EVAL;class C {}; my $cl = 'C'; my $c = EVAL "$cl.new"; say $c.WHAT | |||
camelia | (C) | ||
jaguart | but without the EVAL? | ||
deoac | Hmmm. I think I'll refactor than tinker with that magic. Thank you. | 03:38 | |
`cat foo.txt | ./my-prog.raku` | 03:43 | ||
How do I write the Signature of MAIN to capture the text of foo.txt? | |||
gfldex | m: class C {}; my $cl = 'C'; my $c = ::{$cl}.new(); say $c.WHAT; | 04:15 | |
camelia | (C) | ||
gfldex | jaguart: ^^^ | ||
deoac: see: docs.raku.org/type/IO::ArgFiles#$*ARGFILES | 04:17 | ||
05:08
Heptite left
05:25
deoac left
|
|||
Nemokosch | How are these beginner questions, by the way? 😄 | 10:40 | |
13:31
NemokoschKiwi joined
|
|||
chicken | ```pl | 14:12 | |
grammar Bruh { | |||
rule TOP { | |||
^^ <expression>* $$ | |||
} | |||
rule expression { | |||
[<number> | <string>] | |||
} | |||
token number { | |||
\d+ | |||
} | |||
token string { | |||
\S+ | |||
} | |||
} | |||
say Bruh.parse("3 f") | |||
``` how can i make this not return the expression but only the children <number> / <string> | |||
Nemokosch | almost sure the answer will be action class and/or just decomposing the match object by hand | 14:13 | |
but what do you want to be returned, exactly? | |||
chicken | like this ```pl | 14:14 | |
「3 f」 | |||
number => 「3」 | |||
string => 「f」 | |||
``` currently it's like this ```pl | |||
「3 f」 | |||
expression => 「3 」 | |||
number => 「3」 | |||
expression => 「f」 | |||
string => 「f」 | |||
``` | |||
Nemokosch | hmmm | 14:25 | |
aha! | 14:31 | ||
parse returns Match objects | |||
Bruh.parse("3 f")<expression> returns an Array of all matches captured inside <expression> named captures | 14:42 | ||
If you want to do something significantly more complex, consider using Action objects: docs.raku.org/language/grammars#in...ry-Actions | 14:44 | ||
15:37
Heptite joined
|
|||
falsifian | Can I have an @-sigiled variable that's both immutable and has a type? "my Int @x := (1, 2, 3);" fails because List isn't a subclass of Positional[Int]. | 16:11 | |
m: my Int @x := (1, 2, 3); | |||
camelia | Type check failed in binding; expected Positional[Int] but got List ((1, 2, 3)) in block <unit> at <tmp> line 1 |
||
falsifian | I guess I could make my own subclass of Positional[Int], but I'm wondering if I'm missing something built-in. | 16:12 | |
Nemokosch | long story short: typed @-sigilled variables are a constant headache | ||
probably a where clause is easier to get working | 16:13 | ||
where *.all ~~ Int, or something | |||
falsifian | I'm trying to use where with my @... but it looks like the where clause is applied to the elements. | 16:17 | |
m: my @x where * ~~ Int = 1, 2, 3; | |||
camelia | ( no output ) | ||
falsifian | m: my @x where * ~~ Int := 1, 2, 3; | ||
camelia | Type check failed in binding; expected Positional[<anon>] but got List ((1, 2, 3)) in block <unit> at <tmp> line 1 |
||
Nemokosch | the code examples don't support the statement? | ||
anyway, you do need to allow conversion from List to something else | 16:19 | ||
since List doesn't know element types | 16:20 | ||
falsifian | What code examples do you mean? | ||
m: my $x where { $_.all ~~ Int } := (1, 2, 3); | 16:21 | ||
camelia | ( no output ) | ||
falsifian | That seems to work, at least. | ||
Nemokosch | for me it doesn't but I'm not going to complain on someone else's behalf 😄 | 16:37 | |
falsifian | In practice I'll probably just drop the type in favour of the immutability, unless the type check is especially helpful. my @x := .... I'm still figuring out when I want to use what features. | 16:43 | |
Nemokosch | oh I misread it, you wrote my $x, not my @x | 16:46 | |
17:15
razetime left
18:36
NemokoschKiwi left
|
|||
chicken | im trying to call a grammar.parse from inside a class method but im getting `Cannot assign to a readonly variable or a value | 19:35 | |
` | |||
lizmat | that could be anything... | 19:43 | |
can you golf the issue and provide a full --ll-exception backtrace ? | |||
in a gist? | |||
chicken | ok here is the gist gist.github.com/scpchicken/c96a035...cc44a1dcd2 | 19:52 | |
19:55
deoac joined
|
|||
pastebin.com/cj7yBZmB here is the --ll-exception | 19:56 | ||
lizmat | yeah, ok, thanks | 19:57 | |
ok, not seeing a quick fix | 19:59 | ||
and I'm going to be in a meeting in a minute | |||
will check again when done | |||
deoac | ~% cat deleteme.raku | ./deleteme.raku | 20:04 | |
Usage: | |||
./deleteme.raku <some-text> | |||
How can I get that to work? deleteme.raku expects a string, not a filename. | 20:05 | ||
chicken | ./delete `cat bruh` | ||
./delete $(cat bruh) | 20:06 | ||
do edits show up? | |||
Nemokosch | I think they are resent | 20:10 | |
chicken | ./delete "$(cat bruh)" | 20:35 | |
lizmat | chicken: you need to make $/ writable in method TOP: | 20:59 | |
method TOP($/ is copy) { | |||
afk& | |||
chicken | huh ok | 22:02 | |
xkevio | what kind of parser do raku grammars use when calling `parse`? is it LL? | 22:05 | |
what kind of parser does raku grammars use when calling `parse`? is it LL? | |||
what kind of parser does a raku grammar use when calling `parse`? is it LL? | |||
Nemokosch | PEG, from what I know | ||
xkevio | ah i see | 22:06 | |
ok follow up question, i tried translating a simple context free grammar as a raku grammar and when trying to parse a word that has a symbol in it that is not at all contained in the grammar, raku enters an endless loop but not when that symbol is at the end of the word | 22:07 | ||
this grammar | |||
i translated like that | 22:08 | ||
now ofc "c" isnt part of that but i dont get `Nil`, ive traced through it with `Grammar::Debugger` and i do understand why it recurses but is this just an example of PEGs being limited context free grammars? | |||
guifa | Do you have a copy of either the original grammar or your raku grammar and a test parse string you're using? | 22:13 | |
Nemokosch | already posted, except IRC is being IRC | 22:15 | |
media.discordapp.net/attachments/7.../image.png | |||
media.discordapp.net/attachments/7.../image.png | |||
xkevio | oh sorry, idk how the irc bridge handles discord image uploads | 22:16 | |
guifa | So the reason that it hangs is that you are allowing for zero-width progression | 22:24 | |
Regardless whether it tries to match <A><B> or <B><C>, it will end up in the same place: <A> will try to match 'a' fail and then <B> anyways. Thn it tries to match 'b' and that's a no go so it goes to <C>, tries to match 'a', no go, and then tries to go with <A> again. | 22:28 | ||
xkevio | yes i understand that. so how do i not allow zero-width progression? something like negative lookaround? i am sorry, im not too knowledgable on those specific terms | 22:34 | |
guifa | Wikipedia has a small discussion on it. en.wikipedia.org/wiki/Left_recursi..._recursion | 22:45 | |
In your case, I'd just check that everything is <[ab]> | |||
eg | |||
token valid { ^ [a | b]+ $ }; token TOP { <valid> && [ <A><B> | <B><C> ] } | 22:47 | ||
xkevio | i see thank you! i will read up on that, knew it had something to do with but didnt know how to express that | 22:51 | |
23:04
deoac left
23:22
jaguart left
|