Woops! I just realized I factored something wrongly...!?
On Fri, Feb 11, 2005 at 01:22:51PM -0600, Patrick R. Michaud wrote:
> # return true if $x is a factor of $y
> sub is_factor (Scalar $x, Scalar $y) { $y % $x == 0 }
> [...]
> # a (somewhat inefficient?) is_prime test for $bar
> if is_factor(none(2..sqrt($bar)), $bar) { say "$bar is prime"; }
>
> Just because I'm curious, here's the the prime test spelled out for
> $bar==23, testing if 23 is a prime number:
>
> is_factor(none(2..sqrt(23)), 23)
>
> -> is_factor(none(2..4), 23)
>
> -> { 23 % none(2..4) == 0 }
> [...]
...and here's where I went awry. According to S09, the derivation
should instead be
-> is_factor(none(2..4), 23)
-> none( is_factor(2, 23), is_factor(3, 23), is_factor(4, 23) )
-> none( 0, 0, 0 )
-> true
In other words, the junction isn't passed to the function, but
instead the function is "autothreaded" to be called individually
for each value in the junction.
S09 also says:
In any scalar context not expecting a junction of values, a
junction produces automatic parallelization of the algorithm.
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?
Pm