🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). This channel is logged for the purpose of keeping a history about its development | evalbot usage: 'm: say 3;' or /msg camelia m: ... | Logs can be inspected at colabti.org/irclogger/irclogger_log/raku
Set by lizmat on 1 May 2021.
00:02 reportable6 left 00:03 reportable6 joined 00:07 bigdata left 00:10 finsternis joined 00:19 dogbert17 joined 00:23 dogbert11 left 00:24 dogbert11 joined 00:26 dogbert17 left
kybr m: my $f = { $^a + $^b }; $f.signature.params 00:28
camelia ( no output )
kybr m: my $f = { $^a + $^b }; $f.signature.params.raku.say
camelia (Mu $a, Mu $b)
kybr is there a syntax (other than pointy block) to give $a and $b default values? 00:29
00:45 DiffieHellman left 00:46 DiffieHellman joined 01:10 frost-lab joined
moon-child m: my $x = sub ($a = 5, $b = 7) { $a + $b }; say $x(); say $x(14) 01:13
camelia 12
21
moon-child kinda
codesections also kinda: 01:17
m: my $f = { (.<a> // 1) + (.<b> // 2) }; say $f(); say $f({:a(5):b(9)})
camelia 3
14
kybr yeah, i'm going to call that a no. thank you though. i am doing a thing where i have to analyse the signature of a given block (names, order, default values) in order to create the things that are passed to that block. 01:34
pointy block works well for that. maybe there's another way. 01:35
01:36 kvw_5_ joined
kybr m: my $f = { $^a(2) + $^b(2) }; $f.signature.params.say ; say $f({$_;}, {$_;}) 01:37
camelia (Mu $a Mu $b)
4
01:39 kvw_5 left 02:39 greppable6 left, linkable6 left, benchable6 left, bloatable6 left, nativecallable6 left, evalable6 left, reportable6 left, tellable6 left, unicodable6 left, statisfiable6 left, coverable6 left, notable6 left, shareable6 left, sourceable6 left, quotable6 left, bisectable6 left, squashable6 left, committable6 left, releasable6 left 02:40 bisectable6 joined, statisfiable6 joined, quotable6 joined, reportable6 joined, nativecallable6 joined, releasable6 joined 02:41 unicodable6 joined, benchable6 joined, shareable6 joined, linkable6 joined, tellable6 joined, notable6 joined 02:42 greppable6 joined, evalable6 joined, sourceable6 joined, bloatable6 joined, committable6 joined, coverable6 joined, squashable6 joined
raydiak kybr: I think the only "normal" way besides pointy blocks to define a Callable with an explicit Signature is subs/methods. Anything else is going to be something more rare, like maybe deep mop or nqp magic, or a user-defined Callable (or thing acting as a Callable), possibly from a slang providing special syntax for the aforementioned...that kind of stuff 02:57
bisectable6: say Sub.^methods(:all).first: *.name eq "CALL-ME" 03:04
bisectable6 raydiak, Will bisect the whole range automagically because no endpoints were provided, hang tight
raydiak, ¦6c (53 commits): «Nil␤»
raydiak, Nothing to bisect!
raydiak ^ wrt that, regardless of what the docs say, looks like CALL-ME was always just a user-facing override, not something used by the default internal implementation 03:07
kybr raydiak: thank you. i managed to make something work for my situation. i control the things i pass in, so i can give them a way to accept defaults. 03:08
m: my class Arg { has $.value; method CALL-ME($v) { $!value = $v } } ; {$^a(2) + $^b(3)}(Arg.new, Arg.new)
camelia ( no output )
kybr m: my class Arg { has $.value; method CALL-ME($v) { $!value = $v } } ; {$^a(2) + $^b(3)}(Arg.new, Arg.new).say 03:09
camelia 5
kybr that'll work for me
raydiak I look forward to finding out what in the world you're working on :) 03:16
if you want those to just be defaults but not override any specified value, you probably want $!value //= $v instead of = 03:24
also not sure if it's any relevance at all, but fwiw in case you didn't already know, Signatures and Parameters can be defined, accessed, and passed around as first-class objects on their own without being attached to a callable
03:33 parv left 03:40 rindolf joined 04:27 jackjkal joined 04:40 jackjkal left 04:46 aindilis left 04:54 Kaiepi left 04:55 Kaiepi joined 05:08 Kaiepi left 05:21 parabolize left 05:52 Kaiepi joined 05:57 [Sno] joined 06:00 |Sno| left 06:02 reportable6 left, reportable6 joined 06:08 canbenshanlo joined 06:18 brtastic joined 06:21 brtastic1 joined 06:23 brtastic left, brtastic1 is now known as brtastic 06:25 tadzik left 06:27 ufobat joined, ufobat_ joined 06:28 masak left 06:30 masak joined 06:31 masak is now known as Guest75199, tadzik joined 06:33 torbjorn left 06:39 ufobat left 06:40 ufobat_ left 06:45 ufobat joined 06:48 canbenshanlo left 06:56 domidumont joined 07:01 wamba joined 07:22 pecastro joined 07:24 Sgeo left 07:50 dakkar joined 08:20 wamba left 08:29 avar left 08:31 avar joined, avar left, avar joined 09:00 kiti_nomad[m] left 09:27 squashable6 left 09:29 squashable6 joined 09:31 canbenshanlo joined 09:33 squashable6 left 09:38 squashable6 joined 09:40 squashable6 left 09:41 squashable6 joined 09:46 dogbert11 left 09:53 brtastic left, brtastic1 joined 09:56 brtastic joined 09:57 thundergnat left, brtastic1 left 10:04 brtastic1 joined 10:05 brtastic left, brtastic1 is now known as brtastic 10:06 Black_Ribbon left 10:14 karupanerura left 10:15 wamba joined, karupanerura joined 10:40 abraxxa1 left 10:44 abraxxa joined 10:48 abraxxa left 10:49 abraxxa joined 10:52 wamba left 10:53 wamba joined 10:57 DarthGandalf left 11:14 DarthGandalf joined 11:16 DarthGandalf left, lichtkind joined 11:20 brtastic left 11:21 squashable6 left 11:23 DarthGandalf joined 11:25 squashable6 joined 11:27 asymptotically joined 11:32 DarthGandalf left 11:37 parv joined, DarthGandalf joined 11:44 DarthGandalf left 11:45 DarthGandalf joined 12:02 reportable6 left, reportable6 joined 12:16 iconicibex joined 12:17 iconicibex left 12:29 iconicibex joined, iconicibex left, giltgoose joined 12:30 giltgoose left 13:02 foostrap joined 13:15 Some-body_ joined, DarthGandalf left 13:16 Some-body_ is now known as DarthGandalf 13:22 DarthGandalf left, frost-lab left 13:41 DarthGandalf joined 13:48 wamba left 13:51 buffet left 13:57 mowcat joined 13:59 Sgeo joined 14:03 Guest75199 is now known as masak 14:21 foostrap left 14:33 parv left 14:35 ufobat_ joined 14:39 ufobat left
canbenshanlo is there another way to get a range from a string? 14:58
m: say "1..10".&EVAL.WHAT
camelia (Range)
14:58 parabolize joined
Altreus Manually? i.e. extract the ints and construct a range from them 15:04
[Coke] In general, EVAL is how to get a thing from a String, unless there's a direction conversion, like .Int 15:08
m: say '1..10'.Range.^name
camelia No such method 'Range' for invocant of type 'Str'. Did you mean
'rand'?
in block <unit> at <tmp> line 1
[Coke] so, given no .Range, your EVAL is probably the most direct.
canbenshanlo Range.new(|"1..10".split('..').map: *.Int) isn't pretty 15:09
[Coke] True, but in general, neither is getting code from strings. 15:17
15:17 domidumont left
codesections Here's one that might be slightly prettier (though maybe more fragile): 15:23
m: say Range.new: |("1..10" ~~ m:g/\d+/)».Int
camelia 1..10
canbenshanlo Thanks for that! But I'm sticking to EVAL for now, so I can keep the one-liner 15:37
16:07 asymptotically left 16:27 abraxxa left 16:33 mowcat left 16:36 dakkar left 16:58 Kaiepi left, Kaeipi joined 17:03 domidumont joined 17:15 Merfont joined, Kaeipi left 17:21 rindolf left 17:23 rindolf joined 17:46 abraxxa joined 17:47 brtastic joined 17:52 Manifest0 left 17:54 domidumont left 17:58 aindilis joined 18:00 brtastic left 18:02 reportable6 left
codesections I have a trait that works in the module it's defined in, but throws this error when I try to use it from a different file: 18:03
P6opaque: no such attribute '@!dispatchees' on type Routine in a Scalar when trying to get a value
18:03 reportable6 joined
codesections Have any of you run into that before/have any idea how I could resolve it? (It seems related to compile-time/order, but adding a BEGIN block didn't solve anything) 18:04
18:12 Merfont left 18:13 Merfont joined
codesections er, nevermind ... the trait does work, but only when certain other modules aren't used. That gives me somewhere to start at least 18:14
18:24 Manifest0 joined 18:25 aukkras left 18:27 rindolf left 18:31 aukkras joined
lizmat that feels like there's a decont missing somewhere 18:33
I assume the trait is adapting @!dispatchees ??
codesections ^^ 18:34
codesections no, which struck me as odd too. It is messing with related things, though
lizmat ah, you're messing with where the Routine object is stored somehow ? 18:35
that would need to be deconted
codesections hmm, well, I just got it working by moving some things around. Not sure I fully understand what the issue was, but *shrug* 18:39
thanks
18:44 swaggboi left 18:48 wamba joined 19:00 ufobat_ left 19:26 brtastic joined 20:20 parv joined 20:26 parabolize left 20:28 parabolize joined
kybr what's the state of the art for binary grammars or pack/unpack? 20:36
canbenshanlo just curious, but is there something like this in raku? `sub foo(--> $x) { ... modify $x and it gets returned automatically upon exit ...}` 20:37
codesections canbenshanlo: I don't believe so, though the last expression of the sub is returned automatically, which helps avoid the need for something like that. Out of curiosity, what language has syntax like that? It's new to me 20:44
canbenshanlo nim, called result variables
nim-by-example.github.io/variables/result/ 20:45
lizmat kybr: if you're familiar with Perl's pack/unpack, then maybe modules.raku.org/dist/P5pack is for you 20:46
tonyo codesections: pascal has that too 20:49
some form of vb had it back in the old days too 20:50
kybr lizmat: thank you. i never learned it well. 20:53
lizmat yeah, pack/unpack is one of those things I also continuously needed to look up
20:55 parabolize left
codesections canbenshanlo: looking at the nim example, it'd be pretty easy to implement in Raku with a wrapper function and a dynamic variable. Like so: 20:56
m: sub res(&fn, |c) { my $*result; fn(|c); $*result}; say res { for 'a'..'z' { $*result.push: $_}}
camelia [a b c d e f g h i j k l m n o p q r s t u v w x y z]
20:57 parabolize joined 20:58 simcop2387 left
tonyo codesections: www.tutorialspoint.com/pascal/pasc...ctions.htm 20:59
codesections tonyo: interesting. So, in Pascal it's either 'result' or name the user defines in the fn signature (unlike Nim, where it's always result) (I mean, judging from the respective docs) 21:03
21:03 simcop2387 joined
canbenshanlo codesections: another slight difference between pascal and nim, if i'm not mistaken: nim default-initializes these variables. if your function returns an int according to the signature, but you are never writing to the result var, then you are still getting 0. 21:07
codesections canbenshanlo: I would have *thought* that the same would be true for my Raku version, but it's not. 21:12
m: sub f(--> Int:D) {}; dd f();
camelia Nil
codesections ^^^ that doesn't seem right
21:16 MasterDuke joined 21:25 pecastro left 21:29 pecastro joined 21:32 mowcat joined 21:35 wamba left
moritz wasn't there some kind of weird exception when it comes to Nil and type checks? 21:39
m: say Nil ~~ Int:D
camelia False
21:41 brtastic left 21:50 abraxxa left
lizmat you can always return Nil 21:53
m: sub a(--> Int:D) { Nil }; dd a 21:54
camelia Nil
22:07 aluaces left 22:26 swaggboi joined 23:26 quotable6 left, sourceable6 left, reportable6 left, statisfiable6 left, greppable6 left, unicodable6 left, nativecallable6 left, tellable6 left, bisectable6 left, coverable6 left, squashable6 left, linkable6 left, releasable6 left, notable6 left, evalable6 left, benchable6 left, shareable6 left, bloatable6 left, committable6 left, quotable6 joined, statisfiable6 joined, nativecallable6 joined, linkable6 joined 23:27 squashable6 joined, unicodable6 joined, committable6 joined, sourceable6 joined, bisectable6 joined, releasable6 joined, notable6 joined, tellable6 joined 23:28 coverable6 joined, greppable6 joined, reportable6 joined, evalable6 joined 23:29 bloatable6 joined, benchable6 joined, shareable6 joined 23:48 pecastro left 23:53 [Sno] left