Howell, Leonard wrote:
> Thanks for the useful emails. I need to digest their content and see how I
> might use them. In the meantime, I did a line-by-line translation of Jim
> Weigang's APL code into J and initial testing looks favorable. I will beat on
> it harder over the next couple of days before declaring it finished. If
> anyone would like the code, I can post it here. Most of the translation was
> straightforward, except for one line in APL that does this:
>
> APL: 1 0 0 1 0 0 0 1 0\1 2 3 gives the result: 1 0 0 2 0 0 0 3 0
>
> but I did not know how to easily do this in J, so I used a line of code
> recently posted in the J-forum as:
>
> expand=:4 : '((I. x.) i. i. # x.){y.,0'
>
> implemented as 1 0 0 1 0 0 0 1 0 expand 1 2 3 to achieve the desired result.
>
> this of course works fine but I was surprised that I could not find a
> "shorter" method for doing it. Is there one?
expand is defined in the standard library, as #^:_1 .
Load J, then:
1 0 0 1 0 0 0 1 0 expand 1 2 3
1 0 0 2 0 0 0 3 0
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm