|
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. |
|||
|
00:49
jgaz left
01:31
frost joined
04:53
Kaiepi left
|
|||
| stevied | If anyone is bored and is looking for a distraction, I wrote an answer to my own question on SO for my code that uses a class factory to generate similar classes concisely. If you see a way I can improve or streamline this code further, please post a comment there on SO. Thanks! | 04:55 | |
| oh, and I couldn't figure out how to put the attributes directly into the Dimension class without getting an error so I created them on the fly. Not sure if it's possible to put them into Dimension class directly. | 05:02 | ||
|
05:37
kjp joined
08:12
Kaiepi joined
08:19
lizmat_ is now known as lizmat
08:35
kueppo joined
|
|||
| kueppo | Hi there, just going through the manual, I've no clue of what the ~ twigil is used for, I guess I'm not gonna have to use it in future or ...? '=D | 08:48 | |
| lizmat | kueppo: probably not, indeed | 08:50 | |
| kueppo | Noted | ||
| lizmat | not until RakuAST has landed, I'd say | 08:51 | |
|
09:32
kueppo left
09:52
kueppo joined
10:02
kueppo left
10:35
Kaiepi left
10:40
Kaiepi joined
10:45
kueppo joined
10:50
kueppo left
11:44
Kaiepi left
11:48
Kaiepi joined
12:11
jgaz joined
12:46
kueppo joined
13:32
frost left
15:10
m_athias left
15:12
m_athias joined
16:02
kueppo left
|
|||
| SmokeMachine | stevied: is there a link for that? | 17:03 | |
|
17:04
jgaz left
|
|||
| SmokeMachine | this one? stackoverflow.com/questions/725544...2#72569192 | 17:06 | |
| Nemokosch | ngl you guys are really using Raku in sophisticated and very diverse ways | 17:22 | |
|
17:29
jgaz joined
17:31
jgaz left
|
|||
| stevied | oh, sorry, yeah, forgot the link. yeah, that's it | 17:35 | |
| i have this function sig: | 17:37 | ||
| `sub derived-factory(Hash:D %derived, Str:D $type, Str:D $base, Bool:D $imp = False)` | |||
| I'm passing a hash into it, I think, but I'm getting this error: | |||
| `Type check failed in binding to parameter '%derived'; expected Associative[Hash] but got Hash ({:Gt(${:den(1.0), :n...)` | |||
| why does it say expected Associative[Hash]? | 17:38 | ||
| I don't even know the difference between the two | 17:39 | ||
| ok, if I change it the `%` to the `$` sign it works. I suppose this is one of those container things | 17:43 | ||
| or it gets converted to a list or something, right? I forget. | |||
| Nahita | `%` means the variable is an (or "does") Associative (for which the default type is Hash); if you put some type before it (e.g, Hash you did), it indicates what the type of *key*s of the Associative is restricted to. So it expects an Associative where keys are Hashes; `Associative[Hash]` signals this (i.e., some variable declared as `my Hash %h;` is to be passed). [Similarly you can constrain the type | 17:49 | |
| (at least) two resolutions: as you did `Hash $var`, or `%var` only | |||
| stevied | ah, ok, yeah, that rings a bell | ||
| so it's like a argument checker, not a sigil | 17:50 | ||
| thanks! | |||
| SmokeMachine | Hash:D %derived means exactly a Associative (that's what the % mean) where each value is a Hash:D | 18:05 | |
| sorry, just ready Nahita's answer... | |||
| stevied: I've added a suggestion on your question to create a `dimension` keyword... | 18:07 | ||
|
18:23
jgaz joined
|
|||
| stevied | thanks, i'll check it out | 18:59 | |
| what's the best way to determine if an object has a specific attribute? | 19:35 | ||
| I came up with this: `say $.dimension.^attributes.Str.contains: 'multiplier';` but this seems pretty hacky | 19:39 | ||
| lizmat | m: dd q/$!value/ (elem) 42.^attributes>>.name | 19:40 | |
| camelia | Bool::True | ||
| stevied | ok, so seems like there's not built in way | 19:41 | |
| ok, so seems like there's no built in way | |||
| lizmat | well, that *is* a built-in way as no NQP is involved :-) | 19:42 | |
| well, externally :-) | |||
| stevied | still couldn't tell you waht NGP stands for š | 19:45 | |
| Q | |||
| lizmat | Not Quite Perl | 19:46 | |
| originally | |||
| m: sub has-attribute(\object, Str:D $name) { $name (elem) object.^attributes.map({.name.substr(2)}) }; say 42.&has-attribute("value") | 19:47 | ||
| camelia | True | ||
| stevied | oh yeah | ||
| Nahita | there are `$obj.^can("attr")` and `$obj.?attr` but not sure if these are equivalent to what @lizmat showed above fully | ||
| lizmat | ^can only tells you it can do a *method* | 19:48 | |
| Nahita | `^can` returns an empty list if not found, `.?` returns Nil | ||
| SmokeMachine | those are for methods... | ||
| lizmat | an attribute *can* have an accessor method, but if it's private, it doesn't | ||
| and methods can also be just: methods :-) | |||
| SmokeMachine | m: class Bla { has $.a; has $!b }; say Black.^can("a"); say Black.^can("b") | 19:49 | |
| camelia | ===SORRY!=== Error while compiling <tmp> Undeclared name: Black used at line 1. Did you mean 'Block'? |
||
| Nahita | oh okay thanks | ||
| SmokeMachine | m: class Bla { has $.a; has $!b }; say Black.^can("a"); say Bla.^can("b") | ||
| camelia | ===SORRY!=== Error while compiling <tmp> Undeclared name: Black used at line 1. Did you mean 'Block'? |
||
| SmokeMachine | m: class Bla { has $.a; has $!b }; say Bla.^can("a"); say Bla.^can("b") | ||
| camelia | (a) () |
||
| Nahita | where is Raku on EAFP vs LBYL? is there a strong tendency to either | 19:51 | |
| or TIMTOWTDI and discussion is moot | |||
| jgaz | If I want to split my code off into smaller module files (in the same dir as my main code) how do I do that? | 19:58 | |
| That is, how do I include the external module? | 19:59 | ||
| lizmat | with "use" (and make sure to add the to the META6.json :-) | 20:00 | |
| jgaz | So, even when it's a local file I still have to use META6.jason? | 20:03 | |
| err... META6.json? What's the point/ | |||
| lizmat | no, you don't, but it is a good practice :-) | 20:05 | |
| -I has its disadadvantages | |||
| jgaz | Sorry, I mean what is META6 in the first place? What is the function of the file? | 20:06 | |
| lizmat | it is needed to create an installable distribution of your module | 20:10 | |
| it keeps information on what it provides, what it needs, who the authors are, and the authority etc. | |||
| jgaz | lizmat: okay, gotcha. | 20:17 | |
|
20:45
Kaiepi left
20:54
jgaz left
21:46
Kaiepi joined
21:49
Kaipei joined
21:51
Kaiepi left
23:08
kueppo joined
|
|||
| kueppo | I searched but found nothing | 23:12 | |
| @a-cloned.push: "k$i" => $i.clone; | |||
| @a-cloned.push("k$i" => $i.clone); | |||
| What's the name for the first syntax, I haven't seen such a signature syntax from the signature doc but appears in some examples. | |||
| s/signature/argument/ | 23:14 | ||
| from here docs.raku.org/language/variables#T...declarator | 23:19 | ||