And there are structural solutions as well.

   boxdraw_j_ 1

   f_silly =: (}.@:[ [ smoutput@:,)&.:>

   (f_silly/ , {:)^:4'initial value';'constant'
initial valueconstant
nitial valueconstant
itial valueconstant
tial valueconstant
+---------+--------+
|ial value|constant|
+---------+--------+

Date: Sun, 2 Aug 2015 16:26:47 +0100
From: Jon Hough<[email protected]>
To:"[email protected]"  <[email protected]>
Subject: [Jprogramming] Understanding ^:
Message-ID:<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

I'm attempting some functions that use verb power (^:) , but I'm a little lost 
when it comes to the concept of what is getting iterated.
For example, in pseudo code:
function f(y){
a = y; //cache initial value

counter = 10;
while(counter-->0){
y = y + a;
}
return y;}
In the above code, y was initially cached for later use. Trying this in tacit J 
I did:
f =: +]^:10
which completely gives the wrong result. Obviosuly the above function is not 
interesting, and I'm attempting more interesting things, but the principle is 
the same, how can I cache the initial value for use in each iteration when 
using ^:? Do I need to use explicit verbs instead?
Thanks,
Jon             

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to