I think the eventual solution I came up with was somewhat similar to this. Here's my solution:

replaceZeroes =: (;@:;@:(_4([:<(((_1 1 (] i.&0)}"0 1 ])`])@.(# = i.&0)))\]))^:_

I spent some time trying to figure out how to apply the replacement repeatedly before boxing and then unbox at the end, to minimize boxing/ unboxing, but I couldn't get that to work. So in the above, the boxing/ unboxing happens for each replacement. This isn't so bad in my particular case since no list has more than three zeroes in it. If the lists had many zeroes, the whole thing would come apart, since I'm starting with 512 lists of 27 elements, so a bunch of zeroes would quickly result in millions of lists. As it is, I end up with less than a thousand.

Still I wonder that there seems to be no way to avoid boxing/unboxing? If I have a list and I want to transform that list, with the subsets I take potentially changing in length, I can't do that without boxes?

Say I have a list like this: 1 2 3 4 5 6 7 8

And I want the result to be a list that a duplicate for each prime in the list:

1 2 2 3 3 4 5 5 6 7 7 8

Are boxes the only/best way?

regards,

Geoff

On Mar 4, 2008, at 5:17 AM, Raul Miller wrote:

I have some comments in addition to R.E.Boss's comments
(and using his M)
  M=:1 _1  0  1,1  1 _1  1,:0  1  0 _1

A simple approach to supressing fill uses box (<) followed
by raze (;).  In other words:

  <@(_1 1 (] i.&0)}"0 1 ])`<@.(# = i.&0)"1 M
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to