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:00
Manifest0 left
02:19
teatime joined
02:21
teatwo left,
tea3po left
02:22
teatwo joined
|
|||
avuserow | can I use pattern matching on `when` to assign to variables somehow? `when :(Str $s, :$as!) {...}` matches in my case but does not define `$s` or `$as` | 03:32 | |
m: my $f = ["foo", :as<bar>]; given $f {when Pair {say "pair"}; when :(Str, :$as!) {say "got here: $s"}; default {say "default"}} | 03:35 | ||
camelia | ===SORRY!=== Error while compiling <tmp> Variable '$s' is not declared. Perhaps you forgot a 'sub' if this was intended to be part of a signature? at <tmp>:1 ------> r"}; when :(Str, :$as!) {say "got here: ⏏$s"}; default {say "d… |
||
avuserow | m: my $f = ["foo", :as<bar>]; given $f {when Pair {say "pair"}; when :($s, :$as!) {say "got here: $s"}; default {say "default"}} | 03:37 | |
camelia | ===SORRY!=== Error while compiling <tmp> Variable '$s' is not declared. Perhaps you forgot a 'sub' if this was intended to be part of a signature? at <tmp>:1 ------> ir"}; when :($s, :$as!) {say "got here: ⏏$s"}; default {say "d… |
||
avuserow | I guess "destructuring" is the term when making a pointy block but it doesn't seem to work here. :shrug: | 03:41 | |
03:54
kjp left,
kjp joined
|
|||
CIAvash | avuserow: That is not possible ATM, but you can use my module: codeberg.org/CIAvash/PatternMatching or codesections's module: github.com/codesections/_ | 05:40 | |
gfldex | avuserow: ofc you can: gist.github.com/gfldex/88209367b5f...e9a6b2d481 | 10:38 | |
gfldex .oO( With Raku it's almost always a "how"-question. ) | 10:40 | ||
avuserow | Looks like the solutions generally use MMD under the covers to match and declare the variables | 13:37 | |
Thanks for the links | |||
14:16
teatime left,
teatwo left
16:05
Manifest0 joined
|
|||
avuserow | is there a way to provide better help text explaining why a `where` constraint isn't satisfied? | 17:59 | |
m: sub foo(@a where *.elems < 2) {...}; foo([1, 2, 3]) | |||
camelia | Constraint type check failed in binding to parameter '@a'; expected anonymous constraint to be met but got Array ([1, 2, 3]) in sub foo at <tmp> line 1 in block <unit> at <tmp> line 1 |
||
avuserow | and actually I'm doing this with a slurpy param, so I'm more restricted | 18:01 | |
m: sub foo(*%a where *.elems < 2) {...}; foo(:1a, :2b, :3c) | 18:02 | ||
camelia | Constraint type check failed in binding to parameter '%a'; expected anonymous constraint to be met but got Hash ({:a(1), :b(2), :c(3)}) in sub foo at <tmp> line 1 in block <unit> at <tmp> line 1 |
||
Nemokosch | I'm inclined to say, add a fallback candidate only for reporting back | 18:24 | |
avuserow | that works for me :+1: | 18:29 | |
gfldex | avuserow: that's how i tackle that problem: gfldex.wordpress.com/2020/08/09/whereceptions/ | 20:00 | |
avuserow | gfldex++, that's a nice solution | 20:06 | |
20:30
blue-coffee joined
20:39
blue-coffee left
23:24
Manifest0 left
|