This channel is intended for people just starting with the Raku Programming Language ( Logs are available at
Set by lizmat on 8 June 2022.
02:24 lucs_ is now known as lucs 02:38 razetime joined
jaguart for a void sub/method is the signature (... --> Nil) or (... --> Empty) - or something else? 02:42
oh - docs: 'Note that the lack of a returns trait is used to indicate void return type' 02:43
hmm which actually makes a retun type of Mu ¯\_(ツ)_/¯ 02:51
03:13 Kaiepi left 05:33 Kaiepi joined
Nemokosch It's Nil 09:00
Btw it's not even true - the lack of a returns trait does nothing with the return type 09:01
--> Nil enforces sunk context 09:02
09:25 NemokoschKiwi joined 09:32 NemokoschKiwi left
lizmat m: class A { method sink() { say "sunk" } }; sub a(--> Nil) { }; a 09:50
camelia sunk
10:20 Kaiepi left 11:23 Kaiepi joined
Anton Antonov Can I use `lazy` in front of an argument of a sub and expect the argument to be given inside the sub "asis"? (I guess I am too lazy to program that experiment myself...) 12:11
lizmat the only way to get things "as is" is to use \ or "is raw" 12:15
m: sub a(\foo) { dd foo }; a (1,2,3)
camelia (1, 2, 3)
lizmat m: sub a(\foo) { dd foo }; a [$1,2,3] 12:16
camelia [Any, 2, 3]
lizmat m: sub a(\foo) { dd foo }; a $[1,2,3]
camelia $[1, 2, 3]
lizmat m: sub a($foo is raw) { dd $foo }; a $[1,2,3]
camelia $[1, 2, 3]
lizmat m: sub a($foo is raw) { dd $foo; $foo[2] = 42 }; my @bar = 1,2,3; a @bar; dd @bar 12:17
camelia Array @bar = [1, 2, 3]
Array @bar = [1, 2, 42]
lizmat m: sub a($foo is raw) { dd $foo; $foo[2] = 42 }; my @bar = 1,2,3; a $@bar; dd @bar
camelia $[1, 2, 3]
Array @bar = [1, 2, 42]
lizmat m: sub a($foo is raw) { dd $foo; $foo = 42 }; my $bar = (1,2,3); a $bar; dd $bar 12:18
camelia List $bar = $(1, 2, 3)
Int $bar = 42
lizmat Anton Antonov a few examples :-) 12:19
Anton Antonov @lizmat Thank you very much! Trying the examples now... 12:31
@lizmat Is it possible to see the structure of `foo` in your examples? Meaning, can I figure out is `foo` , say, an arithmetic expression, and if yes, see its terms? 12:42
lizmat no, everything is evaluated *before* it is sent as an argument 12:56
what you want, is macro territory really :-) 12:57
Anton Antonov Right -- so, I thought... 13:04
"everything is evaluated before it is sent as an argument" -- That is why my first question was about using the prefix `lazy` in front of a sub argument. 13:09
lizmat ah, I see 13:13
ok, but no, lazy just effectivey sets the "is lazy" flag on iterators that are not lazy
Nemokosch This is not Prolog, after all 😛 13:21
13:29 poohman joined
poohman hello all, 13:30
13:43 Kaiepi left 13:44 Kaiepi joined
Anton Antonov <@297037173541175296> I have Raku-expectations pre-conditioned by Mathematica usage, but I understand what you mean... 🙂 14:06
@lizmat Thank you for clarifying `lazy` !
14:18 Kaipei joined 14:21 Kaiepi left 14:28 Kaiepi joined 14:29 Kaipei left 14:33 poohman left 15:36 poohman joined
poohman somegrammar.parse($lines).made.grep({$_}) vs somegrammar.parse($lines).made.grep($_) 15:37
can someone explain the difference between {$_} vs $_ as the matcher
is {$_} considered as a regex?
the first one removes the 'Nil's
but I want to understand how the match is made 15:38
16:16 razetime left 16:32 poohman left 16:40 poohman joined
lizmat # poohman 16:41
tl;dr; each element is smart-matched with the target 16:42
if you specify just $_ as the target, it will take the value of $_ at the time of the call to .grep 16:43
which is usually not what you want: you want the $_ refer to each value of the list
16:43 jgaz joined
lizmat anyways, I think the blog posts will answer your question(s), if not, lemme know :-) 16:44
16:47 poohman left 16:49 poohman joined
poohman Thanks lizmat 16:50
16:50 Kaipei joined 16:52 Kaiepi left 16:59 poohman37 joined 17:02 poohman left 17:04 Kaipei left
poohman37 poohman: hi Can I not name a token as "to"? 17:10
It says substring length cannot be negative 17:12
I name it as to_time and it was Ok
it is a token in a Grammar
Nemokosch can you provide a bit more context? 17:14
poohman37 Nemokosch:<script src="> 17:34
in line 17 you have token named "to" 17:35
I have to change that to get it running 17:36
lizmat hmmm... could be that the method is leaking in there somehow... 17:39
Nemokosch can you copy it in some... unembedded form? 😅
poohman37 <Nemokosch> cant you see it properly? 17:41
I just clicked the arrow at the end and it show the gist in this browser quite cleanly 17:42
Nemokosch no, it's some cursed JS that could probably be used for embedding the gist into a website 17:43
poohman37 how do you share code here generally? 17:44
been a while
Nahita <>
poohman37 just the link? got it 17:46
thanks Nahita
17:51 Kaiepi joined
Nahita np 17:54
Nemokosch poohman: something is odd indeed... 18:22
m: grammar Demo2 { token TOP { <to2> }; token to2 { \d+ }; }; my $var2 = Demo2.parse("111"); grammar Demo { token TOP { <to> }; token to { \d+ }; }; my $var = Demo.parse("111"); say $var<to>, $var2<to2>; say $var<t 18:26
o> eqv $var2<to2>;
18:27 poohman37 left
m: say $*RAKU.compiler.version 18:28
it's older and the behavior of 2022.12 and 2022.07 isn't even the same
neither is necesarily valid anyway
18:29 NemokoschKiwi joined quite trippy output on different Rakudo releases 18:31
18:39 avuserow left
definitely 2017.04.3 issue 18:40
18:41 jgaz left
I wonder if there was a similar issue for pos previously 18:50
18:53 avuserow joined
interestingly, it didn't ever use to be this bad for the name pos 19:14
other than that, the situation is clear(ish) - Grammar inherits from Match, Match has a method called `to` and regexes of a Grammar are registered as methods 19:16
19:17 NemokoschKiwi left
MasterDuke yes, there a several names that cause problems in grammars, this pops up every once in a while. do the docs have a "traps" section for it? 19:29
19:47 Kaiepi left
Nemokosch gotcha 20:14
having said that, there just must be some remedy... having to reason about an open list of identifier names is a feature killer 20:17
why aren't the token names installed with some prefix instead, similarly to operators? 20:18
20:18 equinox joined
MasterDuke hm...that might be a good suggestion for a rakudo issue 20:34
equinox hi
would you say the following error is LTA? 20:35
m: my &f; f(2)
camelia Impossible coercion from 'Int' into 'Callable': no acceptable coercion method found
in block <unit> at <tmp> line 1
equinox at first glance i didn't understand it
but then it hit me it was trying to do Callable(2) coercion
since &f is a type object at that point
well in the code i had, i had `my &f = ... if ...;` 20:36
and the condition wasn't true, so this happened
Nemokosch Imo the question is rather: should we accept this behavior in the first place?
m: my &f; f 2 20:38
says the same thing which makes no sense whatsoever
This is clearly a function invocation, not any coercion...
21:45 equinox left 22:05 kjp left 22:16 kjp joined
jaguart m: say Routine.WHY 22:34
camelia Cannot look up attributes in a Routine type object. Did you forget a '.new'?
in block <unit> at <tmp> line 1
jaguart m: say Code.WHY
camelia No documentation available for type 'Code'. Perhaps it can be found at
jaguart the last one is kind of clever - it actually returns a Nil with a .gist 22:48
Is it possible to examine Nil - e.g. docs say parents are: Cool Any Mu, but 23:02
m: say Nil.^parents 23:03
camelia ()
jaguart m: say Int.^parents
camelia ()
Nemokosch where do you read this stuff to begin with, by the way?
jaguart m: say Nil.^parents(:all)
camelia ((Cool) (Any) (Mu))
jaguart ah
Nemokosch I couldn't find where it supposedly says no return trait implies "void function", either
jaguart 23:04
Second para - just after first code-block
Nemokosch Hey, you didn't say that you are talking about NativeCall in particular 23:06
jaguart I just searched 'void' to find equiv of Raku void subs 23:08
m: sub x {...}; say &x.of.^name 23:10
camelia Mu
Nemokosch Okay, so what basically happened is that you used a term that isn't really used within Raku and ended up on the side for interacting with C libraries
jaguart which is why I assumed no --> means returns Mu
my new question is: How do I pass around Nil - it always seems to arrive as an Any 23:12
even with 'is raw'
Nemokosch This gives me some flashbacks... not a great fan of how Nil is treated 23:13
jaguart actually -must be something in my stack, one-liners work :( 23:14
Nemokosch with "is raw", it seems to work for me
jaguart yeah - must have missed one in the stack somewhere
Nemokosch generally, if you _assign_ Nil to a container, it will be reset to its default value
jaguart yes - not assigining, introspecting 23:15
Nemokosch let me show you something that I really wish to fix but I'm not sure there is a point before RakuAST 23:18
23:18 NemokoschKiwi joined
NemokoschKiwi m: my Int &f = sub ($a --> Int) { $a + 5 }; say f 10; 23:20
camelia 15
NemokoschKiwi so far so good, right? It can check for a return value because Callable can have a type parameter 23:21
jaguart yes
NemokoschKiwi However, ironically enough
m: my &good = Nil; my Int &bad = Nil;
camelia Type check failed in assignment to &bad; expected Callable[Int] but got Callable (Callable)
in block <unit> at <tmp> line 1
NemokoschKiwi the default value doesn't match the type constraint 🥴 23:22
23:23 NemokoschKiwi left
jaguart Doesnt that make sense? assuming that &good returns Mu? 23:25
m: my Mu &good = Nil; say &g.WHICH 23:26
camelia ===SORRY!=== Error while compiling <tmp>
Undeclared routine:
g used at line 1
jaguart m: my Mu &good = Nil; say &good.WHICH
camelia Type check failed in assignment to &good; expected Callable[Mu] but got Callable (Callable)
in block <unit> at <tmp> line 1
jaguart m: my Mu &good = Nil;
camelia Type check failed in assignment to &good; expected Callable[Mu] but got Callable (Callable)
in block <unit> at <tmp> line 1
Nemokosch I'm not sure what the default signature is
jaguart m: my &g; say &g.of.^name 23:27
camelia Mu
jaguart m: my Int &g; say &g.of.^name
camelia Mu
jaguart hmmm
Nemokosch yeah this .of doesn't seem to be doing anything useful. I don't know if this is a bug
Anyway, I wonder if `Callable` is compatible with `Callable[X]` for any X 23:28
jaguart its also a bit weird that ( --> Str ) {...} is different to () returns Str {...}
in the context of signature comparison 23:29
you would think these would just be sugars
Nemokosch in some way it's different, that's for sure - it can take "return values" in a pretty limited way
namely terms 23:30
last time on the Raku Study Group meetup, we kinda had fun with this, Bruce Gray managed to come up with an expression that worked for setting a return value of -1 23:31
jaguart why is -1 disallowed? 23:37
Nemokosch -1 is not a term on its own but an expression of the unary minus and 1
I don't think there is any theoretic reason why it couldn't work - the grammar of the language simply doesn't handle this 23:38
or at least the grammar used by Rakudo 23:39
there is quite a lot of parser magic around negative numbers in expressions: be warned that unusual things can happen without parens and the placement of whitespaces can also change the result 23:41
jaguart unexpected
Nemokosch The question we need to ask ourselves: what is -1.succ ? 23:47
or better said, what would we expect it to be?
jaguart one unit to the right on the number line? 23:51
Nemokosch Let's take that semantics of the succ method for granted. What would be the result you expect? 23:52
jaguart but not in raku I see
Nemokosch Because this is a valid expression in Ruby and Raku as well and the result is different
23:56 NemokoschKiwi joined
jaguart because negation of 1.succ 23:56
isn't that a precedence thing
NemokoschKiwi yes
m: (-1).succ.say
camelia 0
NemokoschKiwi m: -1 .succ.say
camelia 0
NemokoschKiwi mind the space
23:57 NemokoschKiwi left
jaguart yeah implied -(1.succ) vs (-1).succ - that is going to catch everyone 23:58
Nemokosch let me put it very bluntly: it's not worth it to push the parser towards the edges
jaguart feels like this should be a case well handled rather than an edge case :( 23:59