Some minor nits:

I think you flip between u and f and I think they are equivalent, but
you do not actually mention this.

The convention for the control argument should, I think, be negative
for the &.|. connotation, rather than being "bit 0".

Also, I think I would use 1 for boxed and 2 for not boxed (for
mnemonic reasons).

In the mention of v, I think I would phrase that as "the selector to
apply to the result of all executions of u" instead of "the selector
to apply to the result of each execution of u", because to me, the
latter would imply something which would probably be better expressed
as a part of u's definition.

More serious issues:

I don't think that the implementation of Ndot2 and Ndot3 match the
description, but I am not sure if that is my mistake or a problem in
the implementation. Can you give me an example of their use in a case
where v is not 0?

Also, I am also not really comfortable with the forced parenthesis in
every use of this mechanism. Perhaps a conjunction which returns an
adverb would be acceptable?

And, finally:

This corresponds, roughly, to what a lot of literature calls a fold.
See, for example,
https://en.wikipedia.org/wiki/Fold_(higher-order_function)  So perhaps
instead of calling it insert (which / already is called) we should
instead call this a fold? That would leave us with F. (or perhaps even
fold.) for the name.

Thanks,

-- 
Raul

On Tue, Aug 2, 2016 at 8:43 PM, Henry Rich <henryhr...@gmail.com> wrote:
> As Marshall once noted, the biggest deficiency in J is looping over an array
> when you need a result from each iteration, and the calculation requires an
> initial value and some internal state. Your code looks like
>
> result {"_1 f/\. array , initialstate
>
> where each execution of f produces a result value plus the internal state to
> feed into the next iteration.  The problems are:
> * the result is the entire array of internal state, which is more, maybe
> MUCH more than you need, since the final result needs only a portion of the
> state
> * The state is probably not commensurate with a item of the array, so you
> end up boxing the initial state and the array items, which is very wasteful.
>
> I propose a new primitive, call it N. (for insert).  N. is an adverb that
> produces a conjunction.  In (x N.), x specifies options for the processing,
> much as the right operand of u;.n does.
>
> Definition:
>
> [x] u (n N.) v y
>
> where
>
> u is the function to be applied
> v is the selector to apply to the result of each execution of u, to produce
> the part saved in the final result
> x is the (optional) initial value (if omitted, f is applied first between
> the last 2 items of y)
> y is the argument array
> n selects from several variants:
>  bit 0=0  operation goes back to front
>  bit 0=1  operation goes front to back, as if using &.|.
>  bit 1=0  selected result from each iteration becomes one item of result
>  bit 1=1  selected result from each iteration is boxed before becoming an
> item of result
>
> Formal definition:
> Ndot0 =: 2 : 0
> v&{@> u&.>/\. (<"_1 y)
> :
> v&{@> u&.>/\. (<"_1 y) , <x
> )
> Ndot1 =: 2 : 0
> v&{@> u&.>/\.&.|. (<"_1 y)
> :
> v&{@> u&.>/\.&.|. (<"_1 y) ,~ <x
> )
> Ndot2 =: 2 : 0
> v&{&.> u&.>/\. (<"_1 y)
> :
> v&{&.> u&.>/\. (<"_1 y) , <x
> )
> Ndot3 =: 2 : 0
> v&{&.> u&.>/\.&.|. (<"_1 y)
> :
> v&{&.> u&.>/\.&.|. (<"_1 y) ,~ <x
> )
>
> Ndot =: 1 : 0
> assert. m e. i. 4
> select. m
> case. 0 do. Ndot0
> case. 1 do. Ndot1
> case. 2 do. Ndot2
> case. 3 do. Ndot3
> end.
> )
>
>
> I look forward to criticism of this proposal.
>
> Henry Rich
>
> ----------------------------------------------------------------------
> 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