Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!spool.mu.edu!howland.reston.ans.net!bogus.sura.net!darwin.sura.net!haven.umd.edu!socrates!socrates!rockwell
From: rockwell@socrates.umd.edu (Raul Deluth Miller-Rockwell)
Subject: Re: J (simple) questions
In-Reply-To: rockwell@socrates.umd.edu's message of Wed, 17 Feb 1993 00:32:56 GMT
Message-ID: <ROCKWELL.93Feb18094020@socrates.umd.edu>
Sender: rockwell@socrates.umd.edu (Raul Deluth Miller-Rockwell)
Organization: Traveller
References: <1993Feb15.201003.9953@Princeton.EDU> <ROCKWELL.93Feb16193256@socrates.umd.edu>
Date: Thu, 18 Feb 1993 14:40:20 GMT
Lines: 35

Raul Deluth Miller-Rockwell:
.   l=.l,  '$. =., x.#,: loop_start -. loop_end     NB. repeat x. times'

Oops.  I should have written:
l=.l,  '$. =. (,x.#,: loop_start -. loop_end), end  NB. repeat x. times'

The original form just happened to work, because the last value
generated inside the loop just happened to be the value I wanted the
function to return.  And, to be honest, this would be true of many
looping functions.

On the other hand, the concept of a "simple loop" generally implies
that it is part of a sequential program, and that the steps following
the loop will be executed upon loop termination.  Or, in my opinion,
a "simple loop" isn't all that simple.

In any event, the code I posted should have looked like this:

   l =. 0 0 $''
   l=.l,  'result =. 0#y.                              NB. start with an empty'
   l=.l,  '$. =. (,x.#,: loop_start -. loop_end), end  NB. repeat x. times'
   l=.l,  'loop_start)'
   l=.l,  'result=. result, y.                         NB. simple operation'
   l=.l,  'loop_end)'
   l=.l,  'result                                      NB. return result'
   sample=. '' : l

Raul

P.S.  emacs tip: to execute fragments like this from within your
newsreader (assuming you read news inside of emacs), run J inside a
shell window (or, I presume, a j-interaction-mode window).  Move your
cursor to the begining of the j code fragment in the article, and hit
Control-@.  Then move to the end of the code fragment and type ESC W.
Finally, move into the shell window, type Control-Y and hit return.
