[Jprogramming] Evolution of a J code
Miller, Raul D
rdmiller at usatoday.com
Wed Dec 21 22:09:09 HKT 2005
Oleg Kobchenko wrote:
> for (i ...) {
> a[i] = a[i] > 0.5 ? 1 : -1;
> }
>
> or even
>
> for (i ...) {
> a[i] = 1 + -(int)(a[i] > 0.5);
> }
Note that these two "a" arrays seem to be different after
the loop.
The first loop modifies the array so that it contains
the values 1 or -1.
The second loop modifies the array so that it contains
the values 1 or 0, and is roughly equivalent to the
J expression a <: 0.5
As an aside, I find that unnecessary steps in a program
tend to make that program hard to understand (and
hard to understand programs tend to contain hidden
errors).
--
Raul
More information about the Programming
mailing list