The comparison is actually unfair to the J version.

   - The C program requires the global variables xsize0 and xsize1,
   particularly tricky in this case because if the matrix is of size m,n then
   xsize0 must be initialized to m-1 and xsize1 to n-1.  All the time, you
   eyes, your mind, are screaming at you to say xsize0=m; xsize1=n;
   - The C program gives a wrong answer if all the elements of x are
   non-positive.
   - You have to be careful if x is 64-bit floats rather than merely
   "float".  If you're lucky the C compiler will balk if you try to use it on
   64-bit floats; if you are not it will proceed but sometimes gives a wrong
   answer.



On Fri, Nov 18, 2011 at 2:40 PM, Kip Murray <[email protected]> wrote:

> By all means, post questions here.
>
> And I think you will like J for C programmers (click on JfC at top of
> vocabulary page), here is a sample from Chapter 2 Culture Shock:
>
> Here's an example.  Figure out what the following code does:
>
> int i, j, maxcol = 0;
> float maxval = x[0][0];
> for(i = 0;i<=xsize0;++i) {
>   for(j = 0;j<=xsize1;++j) {
>     if(x[i][j] > maxval) {
>       maxval = x[i][j];
>       maxcol = j;
>     }
>   }
> }
>
> Not too hard.  When the code finishes, maxval is the largest element in
> the array x, and maxcol is the column number it was in.  As it happens,
> all I wanted was the column number, but there was no way for you to know
> that.
>
> The same code in J:
>
> maxcol =. (i. >./) >./ x
>
> With some practice, you will learn to read this code just as easily as
> you read the C.  You will recognize the / as an indicator of a loop that
> accumulates a result, and the i. as an indicator of a search.  The =.
> and =: tokens indicate assignment.
>
> What happened to the if statement?
>
> It's built into the >. primitive.  Just as most loops are hidden inside
> primitives, so are most conditionals.  The functions you write can also
> contain built-in conditionals.
>
> What's the statement delimiter?
>
> There isn't one.  Statements are exactly one line long.
>
> I've looked at some J code.  Every other character is a period or a
> colon.  I've got spots before my eyes.  How can anybody read this stuff?
>
> . . .
>
>
> On 11/18/2011 3:45 PM, Raul Miller wrote:
> > If you cannot find the right reference material, then just post questions
> > here.
> >
> > We have a "J for C Programmers" book, but we do not have a "J for K
> > Programmers".  And in some ways, J is more complicated to use than K.  (K
> > tends to be simpler for 1 dimensional data and for tree structures.)
> >
> ----------------------------------------------------------------------
> 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