Although I have been using J for a while now, it has become a hobby of
mine to code with it. As a consequence I spend very little time
writing in J (perhaps 2 to 3 hours a week). As J and programming in
general has very little to do with my full time employment (in fact
they employ very different skill sets), its very easy to 'forget' how
things can be done.

The points you have outlined are simply, mistakes on my part as I
still class myself in a very elementary stage.

I raise my hat to you for the detailed explanations on how you
simplified my original t1 verb. As this mailing list is usually the
only way I get to learn how to do things better.

t1 =: 4 : '(_1{a) -: (0{ a=. y >\/ (x))'
t2 =: 4 : '({. -: {:) y ]\ x'

Its very nice how you broke t1 down into components and explained how
to simplify them, until the final result was t2,
I highly appreciate it.

Also, thanks Matthew and Viktor for the additional verbs.

On Tue, Nov 10, 2009 at 11:36 PM,  <[email protected]> wrote:
> 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
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to