|
00:25
getimiskon left
|
|||
| gfldex | m: say my $hey-raku-what-kind-of-problems-can-i-solve-with-you; | 01:22 | |
| m:``` | 01:30 | ||
| sub postfix:<?>(\p) { p } | |||
| say my $hey-raku-what-kind-of-problems-can-i-solve-with-you?; | |||
| ``` | |||
| I will be damned if I can't put that into a blog post. :) | 01:31 | ||
|
02:57
mjgardner left
02:58
mjgardner joined
|
|||
| riffraff | hey folks, I'm playing with grammars, and I have a problem: I want to match a pascal-style string, where the length of the string is an int at the prefix, e.g. 1a 3abc 5abcde. I think I could do by defining | 08:03 | |
| a rule that takes a parameter e.g. ``` grammar Pascal { | 08:05 | ||
| token TOP { <length><payload($<length>)> } | |||
| token length { <[0..9]> } | |||
| token payload($length) { 'x' x { $length.Int } } | |||
| } | |||
| ``` | |||
| but I always seem to ge Nil as $length in <payload > | |||
| did I imagine this syntax? | |||
| a rule that takes a parameter e.g. ``` grammar Pascal { | |||
| token TOP { <length><payload($<length>)> } | |||
| token length { <[0..9]> } | |||
| token payload($length) { 'x' x { $length.Int } } | |||
| } | |||
| ``` | |||
| but I always seem to get Nil as $length in <payload > | |||
| hey folks, I'm playing with grammars, and I have a problem: I want to match a pascal-style string, where the length of the string is an int at the prefix, e.g. 1a 3abc 5abcde. I think I could do this by defining | |||
| Nemokosch | in Pascal? | 09:15 | |
| I've never seen anything like this in Pascal | |||
| riffraff | AFAIR it was the way strings were represented, with prefix length, rather than being null terminated like in C | 09:29 | |
| stackoverflow.com/questions/250689...s#25079998 | 09:30 | ||
| lakmatiol | The issue afaik is that at the time you are trying to do the call, $/ is unset | 09:50 | |
| Try <payload({$<length>})> | 09:51 | ||
| Nemokosch | represented internally, not in the language though | 10:25 | |
| riffraff | sure | ||
| lakmatiol | is there a way to pass a factory to `is default(BagHash.new)` for example. If you give it a sub, it just calls the sub, but this way all defaults share the same BagHash | 12:25 | |
| Nemokosch | are you going to mutate the default value? | 12:35 | |
| lakmatiol | yes | ||
| Nemokosch | why? | ||
| lakmatiol | in this specific example, I need an array which contains more arrays | 12:38 | |
| i eventually figured out you can just the `:U` variants of .push etc, but it would be nice to be able to set a default | 12:40 | ||
| Nemokosch | default function argument or default type value? | ||
| lakmatiol | default type value | 12:52 | |
| sth like `my @a is default([])` | |||
| sth like `my @a is default([]);` | |||
| Nemokosch | I don't know a language that has mutability and this would work | 13:00 | |
| C in a way | |||
| lakmatiol | python has a defaultdict which takes a function that produces the default values, and I believe julia has a similar features with its macros | 13:02 | |
| python has a defaultdict which takes a function that produces the default values, and I believe julia has a similar feature with its macros | |||
| Nemokosch | well, that's not a part of the language | 13:03 | |
| one could implement a defaultdict in many languages | 13:04 | ||
| maybe even in Java these days | |||
| lakmatiol | hmm, yeah, seems is default can't do this | 13:05 | |
| well, IG just handrolling a defaultdict is the way to go | |||
| Nemokosch | > Sets the default value with which a variable is initialized, and to which it is reset when Nil is assigned to it. Trait arguments are evaluated at compile time. Closures won't do what you expect: they are stored as is and need to be called by hand. | 13:06 | |
| sounds like a rip | |||
|
13:33
TempIRCLogger left
13:37
TempIRCLogger joined
13:41
TempIRCLogger left,
TempIRCLogger joined
13:45
TempIRCLogger left
13:46
TempIRCLogger joined
|
|||
| shift-eleven | Is there no check if a string is uppercase, or a character, or would I have to use a regex? | 15:23 | |
| well it seems using the `<:Lu>` regex pattern is my best bet and works well | 15:50 | ||
| gfldex | m: say "Abc".&{ .uc eq .Str }; | 16:55 | |
| shift-eleven | ah alright, thanks! | 17:05 | |
|
18:26
getimiskon joined
|
|||