Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!yale!gumby!wupost!howland.reston.ans.net!gatech!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: tsar.Princeton.EDU!fuchs's message of Mon, 15 Feb 1993 20:10:03 GMT
Message-ID: <ROCKWELL.93Feb16193256@socrates.umd.edu>
Sender: rockwell@socrates.umd.edu (Raul Deluth Miller-Rockwell)
Organization: Traveller
References: <1993Feb15.201003.9953@Princeton.EDU>
Date: Wed, 17 Feb 1993 00:32:56 GMT
Lines: 54

Ira H. Fuchs:
   1.If  a=. 75 and b=. 'a='
   how do I print out the following line:
   a=75

b,":a

   In other words how do I concatenate (for purposes of display) a string  
   with a value?

In other words, when concatenating for display purposes, turn the
value into a string.  Note that this assumes that your value can be
displayed on one line.  The more general case (where the value is an
arbitrary sized array) is better dealt with by displaying the label on
a separate line from the value:

print =. 1!:2&2
print b
print ":a

or perhaps by linking the two together as atoms:

b ; ": a

Note that ": turns a value into a character array with equivalent
display characteristics.

   2. I'd like a very simple (not the Newton-Raphson method) example
   that uses $. to do branching or looping. (I know that this may not
   be in the spirit of J, but please humor me).

l =. 0 0 $''
l=.l,  'result =. 0#y.                          NB. start with an empty'
l=.l,  '$. =., x.#,: loop_start -. loop_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

(x sample y) should, I believe, give the same result as ((,&y)^:(*/x) 0#y)
And, for simple values, the same as x#y

   3. Is there any form of editing (other than simply using ctrl-enter to  
   recapture one line) on the PC?

Sure, 8!:9, or something like that.  Also, you can write something out
to a file (text 1!:2 <'file'), edit it with some dos-based editor
(0!:1 'edit file'), then read it back in (1!:1 <'file').  DOS likes to
add junk to your text (and end of file mark, with random garbage
following), and there's a carriage return/linefeed problem to be
addressed, but that's not always all that important.

Raul
