On Fri, Feb 11, 2005 at 02:12:51PM -0600, Patrick R. Michaud wrote: > I briefly grepped through the apocalypses/synopses and couldn't > find the answer -- how do I tell a scalar context to expect a > junction of values? In particular, is there a way for me to pass > a junction to a routine without it autothreading and without having > to bury the junction in an array or some other structure?
If you have control over that routine, argument prototypes is probably the way to go. To wit: pugs> sub myRand ($j) { rand }; (myRand(any(1,2))).perl "((0.33283094755206977 | 0.815772904389485))" pugs> sub myRand (Junction $j) { rand }; (myRand(any(1,2))).perl "(0.9624736987665468)" If you don't have control over the routine, maybe taking a reference is the way to go: pugs> sub myRand ($j) { rand }; $ref := \ (1|2); (myRand($ref)).perl "(0.5057952976799094)" Note that "\ (1|2)" is evaluated as "ref(any(1,2))", not "any(ref(1),ref(2))". The reason is that currently I'm prohibiting autothreading if any of the below is true: * $context.isa(Bool) * $context.isa(Junction) * Any.isa($context) Hence, because the "\" primitive has a prototype of: &infix:<\> (Any $x) returns Ref Its first argument is not autothreaded. As usual, please sanity-check the heuristics above. :-) Thanks, /Autrijus/
pgpbtYWbEyfXX.pgp
Description: PGP signature