[Jprogramming] Evolution of a J code

Miller, Raul D rdmiller at usatoday.com
Fri Jan 6 08:49:08 HKT 2006


Randy MacDonald wrote:
> I've not seen a good way to explain how to go from for loops
> to something J-like. I think I got that concept too quickly. 
> It would be interesting to see how that step could be explained.

Note that loops are not always avoidable.

The "J-like" approach typically requires that you're dealing 
with "all" of the data.  If some unknown amount of data may 
appear in the future, you'll need either a loop or an event
handler.

That takes care of the first problem: you need your data in
an array before you can process it.

Once you have an array, I think it's a matter of drawing
analogies between J operations and traditional flow-of-control
operations.

The loop itself is implicit (see the definition of "rank"
for details).

If statements often correspond to data selection (# or maybe {).
Temporary variables often correspond to doing something using 
reduce (/) or power (^:)

But the biggest thing you need is a good, clean, comprehensible
description of what you're trying to accomplish.  That, and a
fair bit of playing around with the language should get you
a long way.

(And, as an aside, no matter what computer language you're
working with, if you don't play around with it you'll never
get good with it.)

-- 
Raul


More information about the Programming mailing list