On Tue, Jan 25, 2011 at 11:18 AM, Ron Jeffries <[email protected]> wrote:
> Gilles, in particular, detected that I may have dived in too deep,
> and suggested that I go back to J for C programmers and work through
> that. I had started with it but didn't really find it tasty, but on
> his advice I'm going again.
I will agree that maintaining perspective probably matters at least as
much as code juggling.
> I noticed in an early example, the accounts one, this patch of C code:
>
> while(3 == fscanf(fid,"%f%f%f",acctno,xactnday,xactnamt) {
> for(acctx = 0;acct[acctx].ano != acctno;++acctx);
> acct[nacct].weightbal +=
> acct[nacct].currbal * (xactnday - acct[nacct].prevday);
> acct[nacct].currbal += xactnamt;
> acct[nacct].prevday = xactnday;
> }
>
> A similar patch appears at the end of the example.
>
> I'm quite rusty on C but it appears to me that the for loop finds
> the value of acctx such that we have the right account number acctno
> ... but that the subsequent code updates account number nacct,
> which, as the incremented value of nacct after the input read loop,
> is in fact an uninitialized account struct.
>
> Am I missing something? If not, maybe the example in JfC needs
> updating. If nothing else, this surely shows that J is not subject
> to this kind of error, or at least not quite so easily.
This is from
http://www.jsoftware.com/help/jforc/a_first_look_at_j_programs.htm?
Anyways, I think you are right: that code does not look like it
will work.
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm