Interesting. I was just churning through an explicit conjunction for the
two-monad case when I saw this. That was a fun little exercise, but then I
wondered about the general case, and then I saw your email. The timing was
excellent.
The main complication that I was wondering about was having (, x`:6@{:)
rather than just (, x`:6). I can see that being useful if the previous
monad (y`:6@{:) had returned a vector rather than a scalar. It's a little
confusing because I'd call it a false parallel {: in (y`:6@{:). That one
was structural, all about assembling the sequence, while the other is an
extension to non-scalar returns. Of course, I could be misreading it.
I don't understand the mechanism of altSeq, in particular what the `'' at
the end is doing. Gerund with the empty string? Is that just to enforce the
creation of a gerund?
I'm not sure why Alternating includes @] before the ^:. That looks like it
should be a no-op to me.
And, why (+ #)? I would have written ([: >: [). (+ #) is equivalent (since
1=#scalar), and it's shorter, but is it also allowing for some other
possibility that I'm not seeing?
Regards,
Johann
On Fri, Mar 1, 2013 at 8:00 AM, Raul Miller <[email protected]> wrote:
> Here's a generalized approach (not necessarily better, but convenient
> if you need a variety of these kinds of sequences):
>
> Alternating=: (1 :0)("0)
> (+#) {. (, (altSeq/m)`:6)@]^:((#m) >.@%~ [)
> )
>
> altSeq=:4 :0
> (, x`:6@{:)@(y`:6@{:)`''
> )
>
> Here's a couple examples:
>
> 9 +:`>: Alternating 1
> 1 2 4 5 10 11 22 23 46 47
> 9 ]`+:`>: Alternating 1
> 1 2 4 4 5 10 10 11 22 22
>
> Note that (Alternating) is a parse time word. The phrase (+:`>:
> Alternating) builds something that can be thought of as code, much
> like a compiler builds code. But if you inspect this result you'll
> see some differences from my original post.
>
> +:`>: Alternating
> ((+ #) {. (, (, +:@{:)@(>:@{:))@]^:(2 >.@%~ [))"0
>
> Can you think of why I might have introduced these complications? I
> think that one of my changes is questionable and should perhaps be
> removed or changed - do you have an idea of which change that would be
> (and can you talk about why it should be changed)?
>
> Thanks,
>
> --
> Raul
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm