A generic problem with generalities is over-generalization.

In this case, I was generalizing your original request by thinking
about what would happen if I added more layers.  My thoughts were
about using a sequence of more than two gerunds, but I also tried to
think about arguments greater than rank 0.

Using {: with the x gerund becomes important if we have more than two
of them.  altSeq combines two gerunds and altSeq/ extends that to a
sequence of arbitrarily many gerunds.  [I could, instead, have forced
an error for the case when more than two gerunds were present or
documented that I was not supporting those cases.]

The @] before the ^: is to prevent the verb derived by altSeq/ from
seeing the left argument which will be the number of times we are
applying this "alternating gerund verb".

The (+ #) could indeed have become [ + 1: or something equivalent, in
this particular version.  However that takes me to the next issue:

("0)

Is it worth thinking about arguments with greater than zero rank?  If
not, maybe this should just be removed.  Or, maybe zero is the only
rank that makes sense for the left argument and the right argument
should be rank 1.  Or maybe the right argument should be rank _1.  Or
maybe both are valid?  If both are valid, I could remove ("0) or
change it to ("0 _) or ("0 _1) and document the issue.  Basically I
think of ("0) in this context as a cheap hack to avoid dealing with a
correctness issue where I currently have no requirements to motivate
my choice.

Of course, I didn't really have any requirements in the first place.
For example, maybe my requirements should have been that I needed to
represent the result as a polynomial.  That would result in very
different code and different possibilities for error cases.

FYI,

-- 
Raul

On Fri, Mar 1, 2013 at 9:41 AM, Johann Hibschman <[email protected]> wrote:
> 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to