Hi Ian,
> t1 =: 4 : '(_1{a) -: (0{ a=. y >\/ (x))'
Uuuh... let's _simplify_ this.
(x) doesn't gain you anything, x will do. (Too much C macros? :-)
In y >\/ x what is the / supposed to do? Was it an attempt to
make "... tl 2 3 4" compute three matrices with different widths?
I'd really like to know. However, it does actually nothing in this
context, and I strongly suggest to change the simplified y >/ x
into a y ]\ x so readers of your code don't start searching for
boxes. You want to have a list of you unaltered sliding windows,
and the identity function expresses this clearly.
In your problem statement, you wrote "want to compare the first
element with the last element". Lucky you: J has "first" and
"last" as primitives {. and {: so there's no need for fidgeting
around with indexes. We'll also reorder their application to match
your original problem statement more closely:
tl =: 4 : '({.a) -: ({:a =. y ]\ x)'
Repeated occurences of anything in the code can usually be factored
out in some way. ({.a) -: ({:a) is crying out loud to be re-written
with a fork: ({. -: {:) a and at that point you don't even need
your temp variable anymore:
tl =: 4 : '({. -: {:) y ]\ x'
To quote Laurie Anderson: "much, Much, MUCH... better."
BTW, this might give you some ideas, too:
(3 ,: _3) {. 'abcdefghijklmnopqrstuvwxyz'
abc
xyz
Martin Neitzel
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm