The power of J resides to a great extent in its array processing capabilities. Processing bunches of numbers runs at speeds comparable to the best compiled code. With large arrays the time spent interpreting J statements almost vanishes. When processing many statements to calculate a single number J runs more like other interpreted languages.
Then there are considerations on how statements are interpreted. Tacit statements get a lot of the interpretation done when the statement is executed and can be used over and over without having to re-interpret it. Maybe. Not the case if it is within an explicit definition. Maybe. Likewise, using recursion, rank and each usually give better performance than using explicit loops. Again, maybe. They do not give better performance if they contain explicit verbs. At least, in the current version of the J engine. I would suggest that rather than worry about explicit vs implicit loops you back off and look for parallel or array approaches to a problem. Then use timing tools to find the places in your code which are taking a lot of time. Then work to optimize them. If you have some very inefficient code which is taking very little time then why bother making it efficient. Another consideration is readability. How comfortable are you reading explicit loops vs recursion etc.? Make your code so you can read it most easily. Your coding style will probably change as you become more familiar with J. And you will begin to understand better how the engine interprets statements. On Mon, Mar 14, 2011 at 7:30 AM, Robert O'Boyle <[email protected]>wrote: > Hi > > When I was first got into J, I found the following statement in Chapter 6 > of > J for C at > file:///C:/j602/help/jforc/loopless_code_i_verbs_have_r.htm#_Toc191734341 > > Order of Execution in Implied Loops > > Whenever a verb is applied to an operand whose rank is higher than > the verb's rank, an implied loop is created, as we have discussed > above. > The order in which the verb is applied to the cells is undefined. The > order used on one machine may not be that used on another one, and the > ordering may not be predictable at all. If your verb has side effects, > you > must insure that they do not depend on the order of execution. > > Current versions of the interpreter apply the verb to cells in > order, but that may change in future releases. > > I also read in either J for C or LJ that one should avoid control > structures > (for, while, etc) as much as possible due to the performance penalty. This > put me in quite a bind re much of my work which is temporally based. So I > have generally used rank to do much of my looping (thus my recent query) > but > always being wary of potential issues in future J versions. It would be > good > for J to clarify all this. > > Bob > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Raul Miller > Sent: March 14, 2011 9:28 AM > To: Programming forum > Cc: Zsbán Ambrus > Subject: Re: [Jprogramming] Recursive algorithm > > On Mon, Mar 14, 2011 at 7:15 AM, Zsbán Ambrus <[email protected]> wrote: > > (For loops could have the advantage that I think jsoftware has made > > some vague statements on the mailing lists that if you use the rank > > operator on verbs with side effects, it might not always call the verb > > as many times or in the right order in some case of optimizations in > > future versions. This is belivable because (u/\. y) already does such > > an optimization, and in fact I think that's a right idea.) > > I do not recall any official statement of that nature, *ever*. > > I believe that that is "folk wisdom" based on experience with other > languages. > > -- > Raul > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
