But .EVAL is evil, right? --B.
On Sun, May 23, 2021 at 9:38 PM Daniel Sockwell <dan...@codesections.com> wrote: > > > For example, you can't get a count of the number of elements in a junction > > Well, if you're willing to stoop to ugly enough hacks, there's _always_ a > way :D > > any('a', 'b').raku.substr(3).EVAL.elems # OUTPUT «3» > > > My guess would be that the `ACCEPTS` method for a Junction > is special cased to handle the junction > > I'm not sure that it's all _that_ much of a special case – it seems like > it mostly follows from the fact that ~~ *both* calls .ACCEPT *and* creates > a boolean context > (https://docs.raku.org/language/contexts#index-entry-Boolean_context) > > In other words, `'e' ~~ 'e'` is _not_ technically equivalent to `'e' eq 'e'` > – it's actually equivalent to `?('e' eq 'e')`. Of course, in that case the > boolean context didn't make a difference because the comparison already > returned a Bool. But it does make a difference in the Junction case: > > any('d', 'e', 'f') ~~ 'e'; > # is the same as > ?(any('d', 'e', 'f') eq 'e'); > > And, indeed, both return True. > > Hope that helps at least a bit! > > – codesections