J prefers that the "initial value" be equivalent to the "identity
value" for your operation, and gives a significant performance boost
to your code if you can express it in those terms.

That said, yes, you can express things using an arbitrary initial value.

for example:

arbred=:1 :0
:
   > u&.>/(<"_1 y),<x
)

   0 0 +arbred 1 2 3
6 6

I hope this helps.

-- 
Raul


On Mon, Jun 22, 2015 at 9:53 PM, Marshall Bockrath-Vandegrift
<[email protected]> wrote:
> Hi all,
>
> I'm still in the process of learning J, and trying to adapt ideas from
> other languages.  In many (other?) functional programming languages it is
> possible to reduce over a collection starting with a provided initial value
> which does not belong to the reduced collection.  To attempt to put this in
> J terms, such an operation would allow the initial value and result of each
> reduction step to have a different shape than that of the the items of the
> value being reduced. As far as I can tell, the standard `/` adverb provides
> no such facility. Is there a J idiom for this?
>
> Thanks,
>
> -Marshall
> ----------------------------------------------------------------------
> 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