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:09
teatime left
02:10
teatime joined
|
|||
aruniecrisps | @SmokeMachine how did you call cro using raku -Ilib? | 02:53 | |
09:03
hudo joined
09:04
hudo left
09:05
hudo joined
09:07
hudo__ left
09:08
dakkar joined
14:11
lizmat_ joined
14:14
lizmat left,
samebchase left,
samebchase joined
14:25
lizmat_ left,
lizmat joined
|
|||
i saw this article: | 15:38 | ||
gfldex.wordpress.com/2021/02/25/custom-when/ | |||
it would be really nice if you could just have a construct in raku that allows you to pass a pointy block to match on the arguments so you could get straight pattern matching | 15:39 | ||
lizmat | aruniecrisps not sure I follow, could you elaborate ? | 16:00 | |
aruniecrisps | so right now we have when statements that are used in given , which largely amount to a call to .ACCEPTS being in the when's condition block, but I was hoping to take advantage of raku's pattern matching capabilities that it has for signatures within the given block itself | 16:05 | |
macro matches($f) { when {{{$f}}}.signature { say {{{$f}}}.signature; {{{$f}}}($_) } } class Point { has Int $.x; has Int $.y } my $u = Point.new(:x(2), :y(3)); my &f = -> Int :$x, Int :$y { say $x; }; say $u ~~ &f.signature; given $u { matches -> Int :$x, Int :$y { say $x; } } | 16:06 | ||
so i've been playing around with this | |||
Nahita | probably misunderstood but there is this maybe it helps | 16:33 | |
aruniecrisps | you could do that @Nahita , it's just in my mind it makes more sense to have it look like this: given $u { matches -> Point(Int :$x, Int :$y) { } matches -> Circle(Int :$radius) { } matches -> Square(Int :$width, Int :$height) { } default { } } | 16:36 | |
obviously matches can be replaced with resembles or whatever word the community feels is best | |||
it looks like a logical extension of already existing syntax, for, with ,and if can use pointy blocks, but when can't | 16:39 | ||
SmokeMachine | recently I was playing with something like this: usercontent.irccloud-cdn.com/file/.../image.png | 16:59 | |
m: sub match(&func) { $_ = CALLERS::<$_>; when &func.signature { func |$_ } }; for [(42, "bla"), (13), ("ble")] { match -> Int $num, Str $str { say $num; say $str }; match -> Int $i { say $i; True }; match -> |c { say c } } | |||
camelia | 42 bla \(42, "bla") |
||
aruniecrisps | this is what i've been trying | 17:02 | |
cdn.discordapp.com/attachments/768...dca76& | |||
for some reason destructuring classes is so hard with this @SmokeMachine | 17:05 | ||
SmokeMachine | the if you just want to descruct it, would something like this be enough? | 17:09 | |
m: class Point { has $.x; has $.y }; my :(Point (:$x, :$y)) := \(Point.new: :1x, :2y); say $x; say $y | |||
camelia | 1 2 |
||
aruniecrisps | you could, but i wanted to see whether that would work in a match statement | 17:29 | |
@SmokeMachine | |||
17:40
dakkar left
18:35
notna joined
19:20
notna left
19:30
teatime left
22:32
discord-raku-bot left,
discord-raku-bot joined
|