🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). Log available at irclogs.raku.org/raku/live.html . If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 6 September 2022.
lizmat clickbaits rakudoweekly.blog/2025/03/03/2025-...ting-down/ 13:28
Guest48 bisectable: say Any === Mu 17:55
bisectable6 Guest48, Will bisect the whole range automagically because no endpoints were provided, hang tight
Guest48, Output on all releases: gist.github.com/aa29d99776a5cb7da5...6d0095a851
Guest48, More than 3 changes to bisect, please try a narrower range like old=2022.07 new=HEAD
Guest48 makes sense 17:57
> If no type is provided by the user Raku assumes the type to be Any. This includes containers, base-classes, parameters and return types. 18:00
This applies, then
> For containers the default type is Any but the default type constraint is Mu. 18:02
What does this mean, though
lizmat m: my $a; dd $a; $a = Mu; dd $a 18:05
camelia $a = Any
$a = Mu
lizmat m: my Any $a; dd $a; $a = Mu; dd $a
camelia Any $a = Any
Type check failed in assignment to $a; expected Any but got Mu (Mu)
in block <unit> at <tmp> line 1
Guest48 my @a; dd @a; 18:10
evalable6 []
Guest48 my \a = Mu; dd a;
evalable6 Mu
Guest48 couldn't the (\a, \b --> Bool) signature work based on the same principle, then? 18:12
lizmat not sure what you mean ? 18:13
Guest48 ruminating github.com/rakudo/rakudo/issues/5796 18:14
lizmat tries adapting the \a, \b candidate to Mu \a, Mu \b 18:17
breaks 6 tests in roast :-( 18:22
making it with that signature, breaks auto-threading 18:23
Guest48 auto-threading over ===? 18:25
lizmat m: say ?Int === Str|Num|Int
camelia any(False, False, False)
lizmat m: say ?(Int === Str|Num|Int) 18:26
camelia True
Guest48 Huh, this doesn't seem like a good idea at all.. 18:27
lizmat autothreading over === ?
Guest48 yes
lizmat well, how would === be different from other operators ? 18:28
m: say "a string" if "foo" ~~ Int | Num | Str
camelia a string
Guest48 m: say Int =:= Str|Num|Int
camelia False
Guest48 it is different
=== is a pretty darn low-level operation 18:29
lizmat =:= is more low level
Guest48 Still, these two are more similar than ~~ to either.
lizmat in any case, there are roast tests for it
Guest48 Then there is an answer to that issue. 18:31
lizmat tries something else 18:35
github.com/rakudo/rakudo/commit/3f6ac5a2d3 18:48
Guest48 m: say so 1&2 === 1&2
camelia False
Guest48 To me, this looks concerning with ===
lizmat m: say so 1 | 2 === 1 | 2 18:49
camelia True
lizmat m: say 1 & 2 === 1 & 2
camelia all(all(True, False), all(False, True))
Guest48 1&2 =:= 1&2 is False because the references don't match. Fair enough. But === distributes and anything that is higher-level than that will probably also distribute. 18:53
Guest48 Despite the fact that a Junction like this seems to have a stable hash: 18:54
m: say (1&2).WHICH eq (1&2).WHICH
camelia True
lizmat yeah, but that feels like DIHWIDT 18:56
lizmat afk for a few hours& 18:57
Guest48 I don't think equal-checking for a junction means intrinsically less sense than using === to query its elements
makes*
Especially since you can do this:
m: my %all-goes-here{Mu}; %all-goes-here{1|2} = 3; dd %all-goes-here 18:58
camelia Any = (my Any %{Mu} = any(1, 2) => 3)
Guest48 If a junction can end up as the key of a hash (probably also not a good idea but bugs exist), at the very least one should have a way to detect the value 18:59
Guest48 Anyway, the good news is the same as the bad news: using .WHICH will get you different behavior and then you might prefer that. It probably also works instead of the code in the issue. :) 19:01
Xliff Hello. 21:30
If I have a grammar with a proto, is there any way I can get the :sym value of the proto that matched? 21:31
librasteve hi - I think I saw an example of that ... rootling now 21:32
Xliff m: grammar A { proto aa { * }; token aa:sym<aa> { 'AA' }; token TOP { <aa> }; }; A.parse("aa").gist.say'
camelia ===SORRY!=== Error while compiling <tmp>
Two terms in a row
at <tmp>:1
------> TOP { <aa> }; }; A.parse("aa").gist.say<HERE>'
expecting any of:
infix
infix stopper
statement end
statement modifier…
Xliff m: grammar A { proto aa { * }; token aa:sym<aa> { 'AA' }; token TOP { <aa> }; }; A.parse("aa").gist.say
camelia No such method 'aa' for invocant of type 'A'. Did you mean 'at'?
in regex TOP at <tmp> line 1
in block <unit> at <tmp> line 1
Xliff m: grammar A { rule TOP { <aa> }; proto aa { * }; token aa:sym<aa> { 'AA' }; }; A.parse("aa").gist.say 21:33
camelia No such method 'aa' for invocant of type 'A'. Did you mean 'at'?
in regex TOP at <tmp> line 1
in block <unit> at <tmp> line 1
Xliff m: grammar A { rule TOP { <aa> }; proto method aa { * }; token aa:sym<aa> { 'AA' }; }; A.parse("aa").gist.say
camelia Cannot resolve caller aa(A:D); Routine does not have any candidates. Is only the proto defined?
in regex TOP at <tmp> line 1
in block <unit> at <tmp> line 1
Xliff m: grammar A { rule TOP { <aa> }; proto token aa { * }; token aa:sym<aa> { 'AA' }; }; A.parse("aa").gist.say
camelia Nil
timo "proto" by default gives you a sub 21:34
Xliff m: grammar A { rule TOP { <aa> }; proto token aa { * }; token aa:sym<aa> { 'AA' }; }; A.parse("AA").gist.say
camelia 「AA」
aa => 「AA」
Xliff So the only thing returned is the proto, not the exact multi (or sym).
Xliff Would love to see if there was a way to get "aa:<aa>" in that output, somehow. 21:35
timo how do you mean "returned"?
captured?
Xliff The parse output. I guess captured might be a better way. 21:36
timo thing about capture is that the caller is responsible for putting the result where it goes, not the callee
Xliff So... maybe an action class?
timo that's why you can <.aa> or <foo=.aa> etc
yeah, action classes go great with proto tokens with :sym 21:37
Xliff m: grammar A { rule TOP { <aa> }; proto token aa { * }; token aa:sym<aa> { 'AA' }; }; class AA-Actions { method aa:sym<aa> { say 'AA' }; }; A.parse("AA", action=AA-Actions.new).gist.say
camelia ===SORRY!=== Error while compiling <tmp>
Undeclared routine:
action used at line 1
Xliff m: grammar A { rule TOP { <aa> }; proto token aa { * }; token aa:sym<aa> { 'AA' }; }; class AA-Actions { method aa:sym<aa> { say 'AA' }; }; A.parse("AA", action => AA-Actions.new).gist.say
camelia 「AA」
aa => 「AA」
timo i think it's actions rather than action 21:38
Xliff m: grammar A { rule TOP { <aa> }; proto token aa { * }; token aa:sym<aa> { 'AA' }; }; class AA-Actions { method aa:sym<aa> { say 'AA' }; }; A.parse("AA", actions => AA-Actions.new).gist.say
camelia Too many positionals passed; expected 1 argument but got 2
in method aa:sym<aa> at <tmp> line 1
in regex aa:sym<aa> at <tmp> line 1
in regex aa at <tmp> line 1
in regex TOP at <tmp> line 1
in block <unit> at <tmp> line 1
librasteve Xliff: maybe this pattern would work for you docs.raku.org/language/grammar_tut...e_and_made ... specifically with the action - say $match<command>.Str; # OUTPUT: «update␤» ???
timo and action methods need to take the match object as first positional arg
Xliff m: grammar A { rule TOP { <aa> }; proto token aa { * }; token aa:sym<aa> { 'AA' }; }; class AA-Actions { method aa:sym<aa> ($/) { say 'AA' }; }; A.parse("AA", actions => AA-Actions.new).gist.say
camelia AA
「AA」
aa => 「AA」
Xliff Aha!
So the Action class is basically how I have to note differences in the proto? :P 21:39
librasteve oh - looks like you got there already!
timo well, you can do something specific in the multi token as well
it just doesn't happen on its own automatically 21:40
librasteve fwiw I have tried to not use actions and found that this is nigh on impossible due to the backtracking behaviours ... it is well worth trying out make / made and getting a feel for what they provide
timo you can use the <sym> rule to match what's in the :sym<here> of your token/rule/regex, and if you spell it <sym> rather than <.sym> it will also show up in the capture
but the "sym" you want isn't always literally what you want matched 21:41
it might be kind of interesting to be able to just put whatever you want into the match result, regardless of what the actual regex provides in terms of capturing bits. though possibly also rather confusing if you encounter it in someone else's code 21:44