Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!swrinde!gatech!emory!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!csus.edu!sfsuvax1.sfsu.edu!emclean
From: emclean@sfsuvax1.sfsu.edu (Emmett McLean)
Subject: Re: J (simple) questions
Message-ID: <1993Feb17.022206.6635@csus.edu>
Sender: news@csus.edu
Organization: San Francisco State University
References: <1993Feb15.201003.9953@Princeton.EDU>
Date: Wed, 17 Feb 1993 02:22:06 GMT
Lines: 90


 NB.>  
 NB.>  1.If  a=. 75 and b=. 'a='
 NB.>  
 NB.>  how do I print out the following line:
 NB.>  
 NB.>  a=75
 NB.>  
 NB.>  In other words how do I concatenate (for purposes of display) a string  
 NB.>  with a value?
 NB.> Perhaps this is too obvious for any of the J documents to describe but all
 NB.>  I could find was the use of foreign conjunctions (1!:2) which I had a  
 NB.>  problem making work on J6.

   a =. 75
   b =. 'a='
   b , ": a      NB.>  use the J primitive verbs "appendItems" and "format"
a=75
   
 NB.  1!:2 is used to write to a text file on disk or to the terminal  
 NB.  See last example below.

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

 NB. Not in the tacit spirt of J of course but here is an explicit verb
 NB. which adds 20 to any number by looping 10 times and adding 2 each time.

   
  b =. i. 0 0             NB. initialize a character table
  b =. b, 'i =. 0'        NB. initialize loop counter
  b =. b, 'n =. 10'       NB. set number of interations
  b =. b, 'loop) '        NB. make a lable called loop
  b =. b, 'y. =. y. + 2'  NB. on each interation add 2 to y.
  b =. b, 'i =. >: i'     NB. increment loop counter by 1
  b =. b, '$. =. > (i = 10) { loop ; end ' NB. brach if loop counter i equals n
  b =. b, 'end) y.'       NB. set lable to exit loop
  b =. b : '' "0          NB. translate character table into an
                          NB. explicit definition verb called "b" adn
                          NB. define it so it works on 0 cells.

   5!:2 <'b'              NB. display explicit verb "b"
+-----------------------------------+-+-+
|+------------------------------+-++|"|0|
||i =. 0                        |:||| | |
||n =. 10                       | ||| | |
||loop)                         | ||| | |
||y. =. y. + 2                  | ||| | |
||i =. >: i                     | ||| | |
||$. =. > (i = 10) { loop ; end | ||| | |
||end) y.                       | ||| | |
|+------------------------------+-++| | |
+-----------------------------------+-+-+
   b 4 5 6    NB. check it out.
24 25 26
   b 4
24
 NB.>  
 NB.>  3. Is there any form of editing (other than simply using ctrl-enter to  
 NB.>  recapture one line) on the PC?
 NB.>  
 NB.  Yes you can type the following into a text file on your PC .
 NB.  And suppose you named it foo. then you can load it into J
 NB.  by typing "0!:2<'foo'" with no "'s. 

  b =. i. 0 0            
  b =. b, 'i =. 0'      
  b =. b, 'n =. 10'    
  b =. b, 'loop) '        
  b =. b, 'y. =. y. + 2' 
  b =. b, 'i =. >: i'   
  b =. b, '$. =. > (i = 10) { loop ; end ' 
  b =. b, 'end) y.'    
  b =. b : '' "0      
                    
  By the way here is an example of 1!:2

  b =. i. 0 0            
  b =. b, 'i =. 0'      
  b =. b, 'n =. 10'    
  b =. b, 'loop) '        
  b =. b, '1!:2&2 i'  NB. this print the variable i to the terminal
                      NB. on each interation.
  b =. b, 'y. =. y. + 2' 
  b =. b, 'i =. >: i'   
  b =. b, '$. =. > (i = 10) { loop ; end ' 
  b =. b, 'end) y.'    
  b =. b : '' "0      
                    
