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. |
|||
01:44
MasterDuke left
|
|||
librasteve | I would like advice on how to avoid an explicit argument name in my code ... gist.github.com/librasteve/0ec5bb2...ec91baca92 | 05:07 | |
in this example (i) how can I avoid going sub fn( @a ) { given @a {...} } and (ii) can I use the feed operator (or similar) to feed the sub dims-match block directly and avoid having to declare / name the sub at all?? | 05:09 | ||
[the gist provided works fine, I am just hoping to improve my skills a bit] | 05:10 | ||
aruniecrisps | i still haven't figured out that matching stuff and it's really beginning to bother me | 06:51 | |
i feel like i should be able to get something like: given Point.new(x => 1, y => 1) { matches -> Point (Int :$x, Int :$y) { say $x + $y; } } | 06:52 | ||
not sure what i'm doing wrong here | |||
it feels really weird to me that i can do this in function declarations but not in given | 06:53 | ||
librasteve | @aruniecrisps you are trying to bolt on some new syntax to raku here ... typically that is not a trival topic (although raku has more power tools than most languages) ... I would suggest you review the source of Cro (the bit that bolts on the routing syntax) ... then work token by token in your new design with dd to inspect what you are getting is what you want ... I think you will need somehow to tease | 07:09 | |
apart the :() Signature from the Callable and then double check that smartmatch on sigs is doing what you want | |||
09:12
dakkar joined
|
|||
SmokeMachine | m: my @a = <a b c>; sub dims-match(Positional $_) { when 0 { say 0 }; when 1 { say 1 }; when * >= 2 { say ">= 2" } }; dims-match @a # librasteve : you could do something like this | 09:39 | |
camelia | >= 2 | ||
SmokeMachine | m: multi dims-match([]) { say 0 }; multi dims-match([$first]) { say $first }; multi dims-match(@a) { say ">=2" }; dims-match <a b c> # but I would probably do something like this... | 09:41 | |
camelia | >=2 | ||
10:15
hudo left
10:16
hudo joined
11:15
hudo_ joined
11:17
hudo left
|
|||
aruniecrisps | @librasteve i'm seeing how they're approaching it, they're basically setting up a context and for each get or post, put block etc they're adding that router to the list of handlers | 15:02 | |
i could do that, but i feel like I should just be able to transform a matches into a when so that i get the exact control flow as when | 15:13 | ||
I got it working but it's a hack for sure: sub matches(&f) { CATCH { when X::TypeCheck::Binding {;} # move on } $_ = CALLERS::<$_>; when &f { f |$_ }; } | 15:20 | ||
so this technically works: given $u { matches -> Point (Int :$x, Int :$y) { } matches -> Circle (Int :$radius) { } matches -> Square (Int :$width, Int :$height) { } default { } } | 15:22 | ||
but the problem is that it still goes through each and every single one of these matches clauses when the behavior i want is for matches to operate like a when clause | 15:24 | ||
because if i add a default clause that also executes | 15:25 | ||
@lizmat do you think i'd be able to pull something like what i'm looking for off using macros and RakuAST? | 15:35 | ||
lizmat | feels like a slang to me, but yes... | 15:36 | |
but I would suggest making a problem solving issue for it, so that you have it clear what you want to achieve, and have other eyes look at it :-) | 15:37 | ||
aruniecrisps | what do you mean? | 15:40 | |
lizmat | github.com/Raku/problem-solving/is...amp;title= | 15:41 | |
dakkar | aruniecrisps: gist.github.com/dakkar/97848d044d8...da74b86026 this code prints `point 5 3`; is that what you're looking for? | 15:46 | |
(yes, it's a bit nasty to hijack Code::ACCEPTS for this…) | 15:47 | ||
aruniecrisps | that works but i feel like you shouldn't have to add but mmm {} each and every time | 15:49 | |
dakkar | yes, I'm looking for a macro way of doing without | 15:51 | |
but I wanted to check I was not completly misunderstanding what you wanted ☺ | 15:52 | ||
aruniecrisps | @lizmat i created a new issue: github.com/Raku/problem-solving/issues/421 | 16:12 | |
lizmat | arunicrisps++ | ||
aruniecrisps++ rather :-) | 16:16 | ||
dakkar | gist.github.com/dakkar/97848d044d8...da74b86026 I don't get macros | 16:18 | |
aruniecrisps | just curious, what's going to happen to slangs when RakuAST is finalized? @lizmat? | ||
lizmat | well... if you have a slang that depends on the legacy grammar, you may need to change that to work with the Raku grammar | 16:19 | |
if you use the Slangify module raku.land/zef:lizmat/Slangify that should be relatively straightforward | 16:20 | ||
check its reverse dependencies for examples | |||
aruniecrisps | oh so the RakuAST API isn't going to really change how you make slangs? | 16:24 | |
lizmat | well, depending on how deep you'd want to affect the semantics of the language | 16:27 | |
some slangs currently depend on semi-documented Rakudo internals | |||
in RakuAST, we would like to provide a documented and stable API for those cases | |||
aruniecrisps | so is this utilizing RakuAST right now? github.com/0racle/raku-Slang-Other...se.rakumod | 16:35 | |
lizmat | no, it isn't really: if just has already adapted to the different API of the Raku grammar as opposed to the legacy grammar | 16:43 | |
the Raku grammar e.g. has a "vetPerlForSyntax" rule built in, which the legacy grammar doesn't | 16:44 | ||
so the handling of the legacy grammar needs to supply that itself | 16:45 | ||
github.com/0racle/raku-Slang-Other...akumod#L30 | |||
17:51
dakkar left
|
|||
aruniecrisps | @lizmat what is this line? github.com/0racle/raku-Slang-Other...akumod#L12 | 18:38 | |
lizmat | try to match <.block-for> rule without capturing, then try to match .kok rule without capturing, then execute code in block | 18:39 | |
code in regex limits LTM matching | |||
aruniecrisps | what is the .kok rule? | 18:40 | |
lizmat | keyword ok I believe | 18:41 | |
github.com/rakudo/rakudo/blob/main...r.nqp#L646 | |||
github.com/rakudo/rakudo/blob/main....nqp#L4819 in RakuAST | 18:43 | ||
note the commented out code: WIP :-) | |||
aruniecrisps | ah makes sense 🙂 | 18:44 | |
21:17
MasterDuke joined
22:38
Guest47 joined
22:40
Guest47 left
23:01
guifa joined
|
|||
librasteve | smokemachine: thanks -- I was trying this... | 23:01 | |
m: sub dm(@_) {when * == 0 {say 0} when * >=1 {say 42}}; dm <1 2 3>; | 23:02 | ||
Raku eval | Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Strange text after block (missing semicolon or comma?) at /home/glot/main.raku:1 ------> sub dm(@_) {when * == 0 {say 0}⏏ when * >=1 {say 42}}; dm <1 2 3>; | ||
librasteve | m: sub dm(@_) {when * == 0 {say 0}; when * >=1 {say 42}}; dm <1 2 3>; | 23:03 | |
Raku eval | 0 Use of uninitialized value of type Any in numeric context in sub dm at main.raku line 1 | ||
librasteve | and I should have done this | ||
m: sub dm($_) {when * == 0 {say 0}; when * >=1 {say 42}}; dm <1 2 3>; | 23:04 | ||
Raku eval | 42 | ||
librasteve | (actually my attempt with @_ errors with | 23:05 | |
Use of uninitialized value of type Any in numeric context in whatevercode at ...Library/CloudStorage/Dropbox/DockerWorld/raku-Physics-Unit/bin/../lib/.precomp/F9883CEFF28704D4E2B594F73D6B46062F30FF07/E3/E331847A1607CD7EE15208C2396B16FA2372B146 line 1 | |||
SmokeMachine | Don’t you like the multi dispatch solution? | ||
librasteve | i love them both ! | 23:06 | |
but ... for me the when/smartmatch syntax is cleaner and the intent is clearer (and it's only one loc to change!) | 23:07 | ||
now I reread the error msg, I guess I could have got there myself ... was distracted by the precomp blurb | 23:08 | ||
SmokeMachine | Really? I have the opposite opinion… :) | ||
librasteve | timtowtdi |