On Sun, May 23, 2021 at 9:15 PM Joseph Brenner <doom...@gmail.com> wrote:
>
> Junctions continue to surprise me:

That must be either that your mental model doesn't match the
default design, or you're being tripped up by DWIMs, or WATs
that can't be removed due to the overall DWIM of junctions
(which usually work great).

>     my $junction = any( 'a', 'b', 'c' );
>     my $char = 'b';
>     say $char ~~ $junction; # True

Does that function (`~~`) do the default thing with junctions
or is it a special case?

As a general point, hopefully you're seeing why we want to
*avoid* special casing as far as is reasonable. Each special
case needs to really pull far more than its *individual* weight
because there's an inevitable *overall* weight as one needs
to get a clear mental model of the default situation *and* the
special cases.

My guess would be that the `ACCEPTS` method for a Junction
is special cased to handle the junction as a single thing rather
than not doing so. I mean, special case a Junction function to
treat itself as a Junction? That makes sense to me! It's the sort
of thing I find easy to, er, accept. *This* is OK to me. Especially
if it supports functionality that could not be supported without
the special case, which applies in this case.

>     say $char eq $junction; # any(False, True, False)

I'd guess that `eq` is just like 99.9% of functions.

And so it is:

* The `eq` is called three times.

* The results are gathered together and a junction of the
   appropriate kind that combines the results is returned.

The special case here is the `say` (or rather the `gist` that
`say` calls).

> I would've thought that there'd be no difference there

Right, because you're not allowing for DWIMs. (Yet, ironically,
asking for a DWIM for the `find` case, when the justification
for it is on much less firm ground.)

> The smartmatch checks that it's comparing string types,
> and does something like an eq on them, right?
> So why would going straight to an eq be different?

Because Larry felt it was a suitable DWIM. worth the
WAT you've just experienced.

> But then, there are other cases where junction-in,
> junction-out is the only thing that makes sense:
>
>     say $junction ~ 'z';
>     # any(az, bz, cz)

Right. That's `~`, which, like 99.9% of all functions/ops,
is not special cased.

--
love, raiph

Reply via email to