This isn't the first (or second, or third, or fourth...) time that
I've seen complications arise with regard to junctions.  Every time,
the confusion arises when some variation of the question "is it a
junction?" is raised.  Ultimately, this is because Perl is trying it's
darnedest to treat Junctions as their members; this is something that
it doesn't try anywhere else, leading to a counterintuitive approach.
The other big example of this phenomenon that I've seen has to do with
passing parameters into a routine: Should the code auto-parallelize,
executing the code separately for each value in the junction, or
should it execute only once, passing the parallelization buck on to
whatever routines it happens to call?  That is, should parallelization
be eager or lazy?  (I'm pretty sure that this was resolved, although
I'm not recalling how.)

The problem that Richard just identified is that Junctions don't fully
manage to hide themselves when it comes to their method calls.  Let's
say that I'm writing a role that deals with quantum mechanics  (say,
Quantum), and for whatever reason I decide that I need an eigenstate
method.  Now we've got a problem: if I ever find myself dealing with a
Junction that has at least one Quantum among its eigenstates, what
happens when I call the .eigenstates method?  I'm betting that I'll
get Junction.eigenstates, rather than a Junction of
Quantum.eigenstates.  In fact, I see no easy way to get the latter.

I'm thinking that maybe Junction shouldn't be a type.  Instead, it
should be a "meta-type", in (very rough) analogy to the concept of the
meta-operator.  In particular, Junction bears a certain resemblance to
the hyper-operator.  Thus far, it's the only meta-type; and, like
meta-operators, additional meta-types should be added sparingly.

As I see it, the difference between a type and a meta-type is that all
of the meta-type's methods are accessed via HOW.  You wouldn't say
"$x.eigenstates" to access a Junction's eigenstates; you'd say
"$x.^eigenstates" for that.  (Further speculation: maybe there's a
meta-type that defines the default HOW methods.)

That still doesn't solve the problem that Richard first raised,
though.  To do that, I'm thinking that his original suggestion should
also be implemented: in the same way that an item can be treated as a
one-item list for the purposes of list context (and vice versa), a
non-Junction should be able to be treated as a Junction with a single
eigenstate (i.e., a Singleton) for the purposes of junctive semantics.
 That is, $x.^eigenstates === ($x) if $x is not a junction.  Not only
does this reduce the need to test for junctions, but it also makes
that test fairly straightforward: count the eigenstates.  If you only
have one, it isn't a junction.  (Further speculation: perhaps
undefined values have _no_ eigenstates...)

Jonathan Lang

Reply via email to