|
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. |
|||
|
02:27
frost joined
04:14
Kaipei joined
04:17
Kaiepi left
05:18
Kaipei left
|
|||
| Nemokosch | Does this really exist? | 05:50 | |
| 1. TIL Raku/user-experience repo | 05:59 | ||
| 2. The single argument rule terminology doesn't make a lot of sense here because that "single argument" is not an iterable anyway... | |||
| 3. Having said that, qw and even qqw is for literals mainly. Why don't you use .words if you don't know how many elements you'll get? | |||
| m: dd 'jajca'.words | 06:06 | ||
| a Seq, as you can see | |||
| it turns into a list if you assign it to a @variable | 06:07 | ||
|
07:06
dakkar joined
07:08
frost left
08:16
Kaipei joined
08:17
discord-raku-bot left,
discord-raku-bot joined
08:53
discord-raku-bot left,
discord-raku-bot joined
|
|||
| Zephyr | is there a way to parse a regex pattern from a string, other than using eval? | 09:13 | |
| Nemokosch | from what I know, no | 09:15 | |
| fingers crossed for RakuAST | |||
| Zephyr | I guess github.com/edumentab/p6-ecma262regex comes close to what I'm looking for | 09:17 | |
| gonna be using that for now | |||
| actually, that won't cut it | 09:46 | ||
| is there a way to use that now? | |||
| Nemokosch | Probably you could compile it at least but I'm absolutely not knowledgeable at this | 09:48 | |
|
11:07
Nemokosch joined
11:10
Nemokosch left
|
|||
| Anton Antonov | You might be able to use one of DrForr packages for parsing Raku programs. | 12:07 | |
| See here: github.com/drforr/perl6-Perl6-Parser | 12:09 | ||
| Zephyr | isn't raku's regex part of the syntax though, not sure if it can be dynamically constructed even from a parsed AST | 12:13 | |
| Anton Antonov | I do not see the problem with that. Ideally, this can be just verified with suitable examples / experiments. | 12:36 | |
| stevied | I'm thinking it might be NQP | 13:25 | |
| Nemokosch | what would it do? | 13:27 | |
| stevied | ok, it's not NQP. See stackoverflow.com/a/72704382/1641112 | 13:29 | |
| and to my surprise, it even handles a list of arrays without a problem: www.reddit.com/r/rakulang/comments...;context=3 | 13:30 | ||
| I think the postcircumfix: bit is a method call | 13:31 | ||
| and the <{; }> bit is the argument. but I'm not sure. | 13:32 | ||
| Nemokosch | this is like the comma-separated dimensional thing | 13:33 | |
| stevied | what I did in 20 lines of code can be done in about 20 characters | ||
| yeah. i haven't played with those separators at all | |||
| Nemokosch | but I didn't know it's like an operator | ||
| stevied | i've only used them playing around with lists | ||
| Nemokosch | like you know, $asd[1][2][3] can be written as $asd[1;2;3] | 13:34 | |
| or $asd[||<1 2 3>], that works already iirc | |||
| stevied | ok, yeah, I didn't know htat | ||
| Nemokosch | what I didn't know is that it works with hashes and it's implemented as an operator | ||
| stevied | I mean I read it once. but haven't used it and forgot about it | ||
| Nemokosch | I really advise the weekly challenges | 13:36 | |
| they are usually pretty small tasks but they almost always require some sort of list manipulation 😄 | |||
| stevied | yeah, I still gotta get some more basics down before I start looking into them | ||
| I'm writing a module that will help me write my own executable tutorials to learn raku. | |||
| In the process of doing that, I get sidetracked learning more raku. 🙂 | 13:38 | ||
| hopefully by the end of the year I will crack into an intermediate level of proficiency | |||
| what's the surefire way for testing the type of an object? | 14:19 | ||
| like if I want to test if an object is `Hash`. I've been using .`^name` and testing it against a string | |||
| but I'm not sure if that's the right way to do it | |||
| should I be using smartmatch instead? | 14:21 | ||
| Nemokosch | that's pretty clean | 14:29 | |
| stevied | what is? .^name or smartmatch? | ||
| Nemokosch | smartmatch | ||
| stevied | so smartmatch is the preferred way? | ||
| Nemokosch | I think smartmatch uses .WHAT | 14:34 | |
| It's legit but it will match for undefined variables of the given type, too | |||
| Morfent | depends | 14:35 | |
| `.WHAT =:= .WHAT` is exact, `~~` against a type object will deal with subtypes | |||
| there's `Metamodel::Primitives.is_type`, but it's rather niche | |||
| it and the type object smartmatch are both `nqp::istype`, just one doesn't have multiple dispatch involved | 14:38 | ||
| stevied | `=:=`? what the hell is that? | ||
| Morfent | think of it like comparing pointers | ||
| only the exact same object can match | |||
| stevied | why isn't `^.name` exact? | ||
| Morfent | `.^name` is just a string in a `.HOW` | 14:40 | |
| you can change it with `.^set_name` | |||
| stevied | ok, so it shouldn't be relied upon then | ||
| ok, so if I wanted to find out an object was exactly a `Hash`, what would I do? | |||
| `$obj.WHAT =:= .WHAT`? | 14:42 | ||
| `$obj.WHAT =:= .HashWHAT`? | |||
| Morfent | `Hash` is a bit weird, you'll need the smartmatch | ||
| stevied | `$obj.WHAT =:= .Hash.WHAT`? | ||
| Morfent | unless you don't want to worry about typed hashes | ||
| stevied | `$obj.WHAT =:= Hash.WHAT`? | ||
| Nemokosch | I think for all intents and purposes, the smartmatch is good | ||
| stevied | ok, so now my next question: | 14:44 | |
| ``` | 14:46 | ||
| sub recurse(%hash) { | |||
| for %hash.sort { | |||
| say .key; | |||
| say .value; | |||
| recurse .value if .value ~~ Hash; | |||
| } | |||
| } | |||
| ``` | |||
| so a simple recursive sub for a hash | |||
| how do I raku-fy this? | |||
| i'm gonna guess there's a more idiomatic way of doing this in raku | |||
| Nemokosch | ~~just flatten it~~ | 14:50 | |
| Morfent | usually when i want to smartmatch on a type like that multiple dispatch can handle it a little more cleanly | 14:54 | |
| stevied | ah, good idea | ||
| Nemokosch | samewith | ||
| stevied | so something along the lines of this: | 14:57 | |
| ``` | |||
| multi sub recurse($not-a-hash) { | |||
| } | |||
| multi sub recurse(Hash:D %hash) { | |||
| for %hash.sort { | |||
| say .key; | |||
| say .value; | |||
| recurse .value; | |||
| } | |||
| } | |||
| ``` | |||
| yeah, that opens up some interesting possibilities while keep the code clean | 14:58 | ||
| Nemokosch | just decide when you want to make your calls on the data | 14:59 | |
| I wonder... | 15:01 | ||
| maybe mutual recursion would be nice? | 15:04 | ||
| stevied | what's that? | ||
| Nemokosch | when two (or more?) functions call each other and that forms the recursion | 15:05 | |
| or idk, maybe it's good this way, I'm not sure what would look good | 15:09 | ||
| stevied | ok, well, not a big deal. i'm probably getting too overboard with it anyway. Keep it simple. | ||
| Nemokosch | Meh, I hoped nextsame or nextwith would be usual functions | 15:21 | |
| but they drop the control | |||
| ```perl | 15:25 | ||
| sub process-hash(%start) { | |||
| .&process-pair for %start.sort; | |||
| } | |||
| multi process-pair($pair) { | |||
| #common code handling the pair | |||
| nextsame; | |||
| } | |||
| multi process-pair($pair where *.value ~~ Hash) { | |||
| .value.&process-hash; | |||
| } | |||
| ``` | |||
|
15:31
avuserow left
15:32
avuserow joined
15:35
dakkar left
|
|||
| ```perl | 15:44 | ||
| sub process-hash(%start) { | |||
| .&process-pair for %start.sort; | |||
| } | |||
| multi process-pair($pair) { | |||
| #common code handling the pair | |||
| nextsame; | |||
| } | |||
| multi process-pair($pair where *.value ~~ Hash) { | |||
| $pair.value.&process-hash; | |||
| } | |||
| ``` | |||
| ```perl | 15:48 | ||
| sub process-hash(%start) { | |||
| .&process-pair for %start.sort; | |||
| } | |||
| multi process-pair($pair) { | |||
| #common code handling the pair | |||
| nextsame; | |||
| } | |||
| multi process-pair($pair where { .value ~~ Hash }) { | |||
| $pair.value.&process-hash; | |||
| } | |||
| ``` | |||
| okay, fixed it | 15:53 | ||
| ```perl | |||
| sub process-hash(%start) { | |||
| .&process-pair for %start.sort; | |||
| } | |||
| multi process-pair($pair where { True }) { | |||
| #common code handling the pair | |||
| nextsame; | |||
| } | |||
| multi process-pair($pair where { .value ~~ Hash }) { | |||
| $pair.value.&process-hash; | |||
| } | |||
| ``` | |||
| I had no better idea to force priority than to add a dummy clause... | 15:54 | ||
| this did work, though, so it's good for learning from it at the very least 😄 | 15:56 | ||
| stevied | ooh, just found out I can turn off ads for Raku pottery on google | 19:19 | |
| life changer | |||
| i think the problem with doing fancy stuff like nextsame is that there's a good chance the next Raku developer who comes along and tries to read it is out of luck | 19:21 | ||
| how do you do that little trick where if you pass a named paramter to a sub it defaults to true? | 19:23 | ||
| can't figure it out | |||
| lizmat | :foo = True | 19:54 | |
| ? | |||
| :$foo = True rather :-) | |||
| sub bar(:$foo = True) { } | |||
| afk& | 19:55 | ||
| locria | Is there a way to access identifier by name? | 19:56 | |
| I was using `Inline::Perl` | 19:58 | ||
| stevied | thanks. thought I tried that, though. | ||
| maybe I was doing something else wrong | |||
| locria | I want to get `&GLFW_XXXXXXX` with `XXXXX` as parameter | ||
| I want to get `&GLFW_XXXXXXX` with `XXXXX` as parameter in local scope | |||
| Don't want to use EVAL | |||
| stevied | I think that's coming with AST | 20:00 | |
| locria | ``` | ||
| use OpenGL::GLFW:from<Perl5> qw<:all>; | |||
| class ConstCaller { | |||
| has $.prefix; | |||
| method postcircumfix:«< >» (Str:D $name) { | |||
| # FIXME | |||
| # term:<$!prefix ~ '_' ~ $name> | |||
| ... | |||
| } | |||
| } | |||
| ``` | |||
| Morfent | something like `&::{"GLFW_$id"}`? | ||
| stevied | oh, yeah, that'll work | ||
| Morfent | may need the sigil on the rhs | 20:02 | |
| oh `&::( )` is what i was thinking of | 20:03 | ||
| stevied | yeah, was gonna say but wasn't 100% sure | 20:04 | |
| locria | Thanks it works | ||
| Is there a way to look up from caller's scope? | 20:06 | ||
| Is there a way to look up variable from caller's scope? | |||
| Morfent | `CALLER::` | 20:10 | |
| stevied | * twigil | ||
| docs.raku.org/language/variables#T...declarator | 20:11 | ||
| To make new-location() print nowhere, make $location a dynamic variable using the * twigil. This twigil makes the compiler look up the symbol in the calling scope instead of the outer scope after trying the local scope. | |||
| Morfent | dynamics are the more natural way to go about it | 20:12 | |
| locria | by I don't control the variables (they're from perl5) | 20:14 | |
| ``` | 20:17 | ||
| use OpenGL::GLFW:from<Perl5> qw<:all>; | |||
| use lib "."; | |||
| use ConstCaller; | |||
| constant GLFW = ConstCaller.new :package(OpenGL::GLFW) :prefix<GLFW>; | |||
| say GLFW<CONTEXT_VERSION_MAJOR>; | |||
| ``` | |||
| How do I look up `OpenGL::GLFW::GLFW_PRESS` programatically? | |||
| How do I bind a "type object" like `OpenGL::GLFW` to a variable? | 20:19 | ||
| I can do the same with Raku module | 20:21 | ||
| `module B {}; my $b = B;` | |||
| SmokeMachine | lizmat: hi! A question about rak: should `class \s+ <([\w+]+ % “::”)> \s* “{“` highlight the whole line or only the class’ name? (I would expect only the class’ name) | 20:24 | |
| locria | I know why. It's a bug(?) in Inline::Perl. | 20:25 | |
| SmokeMachine | I mean: `rak ‘/class \s+ <([\w+]+ % “::”)> \s* “{“/` | ||
| locria | what's rak | 20:27 | |
| SmokeMachine | raku.land/zef:lizmat/App::Rak | 20:35 | |
| locria: 👆 | 20:36 | ||
| lizmat | SmokeMachine: I guess it's an issue with the underlying .contains logic | 21:45 | |
| hmmm... or maybe with the highlighter module | 21:47 | ||
| I'll look at it tomorrow... too tired now | |||
| thanks for trial running rak :-) | |||
| fwiw, I found this to be the easiest way to do this on the command line: | |||
| rak '/ class \s+ <( [\w+]+ % "::" )> \s* "\{" / | 21:48 | ||
| also note that the "\{" willl probably cause any class statements that have a curly open on the next line, to be missed | 21:49 | ||
| or any class like: | 21:50 | ||
| class Foo is Bar { | |||
| afk for sleep& | 21:51 | ||
| stevied | where should I put xt tests that I don't want to run when the module is installed? | 22:01 | |
| i've got an xt folder and when I do mi6 test it still runs those tests | 22:02 | ||
| Anton Antonov | I am not sure would like this alternative -- you use `skip` and `skip-test` | 22:06 | |
| docs.raku.org/type/Test#sub_skip | 22:07 | ||
| stevied | so there's no way to tell the distribution which tests to run? | 22:08 | |
| Anton Antonov | I am sorry, I am not familiar with testing ... 🙂 | ||
| stevied | np | 22:15 | |
|
22:29
discord-raku-bot left
22:30
discord-raku-bot joined
|
|||
| ok, did this: | 22:32 | ||
| ``` | |||
| if %*ENV<AUTHOR_TESTING> { | |||
| lives-ok { recurse %simple }, 'can recurse menu without dying'; | |||
| } else { | |||
| skip 'Skipping author test'; | |||
| exit; | |||
| } | |||
| ``` | |||
|
23:08
discord-raku-bot left,
gfldex left
23:36
discord-raku-bot joined
23:40
gfldex joined
|
|||