[Jprogramming] Understanding ^:

Raul Miller rauldmiller at gmail.com
Sun Aug 2 18:16:16 UTC 2015


I think Pascal has pretty much already covered it, but these are equivalent:

   f^:5 n
   f f f f f n

And these are also equivalent:
   m f^:3 n
   m f m f m f n

Thanks,

-- 
Raul


On Sun, Aug 2, 2015 at 11:26 AM, Jon Hough <jghough at outlook.com> wrote:
> 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


More information about the Programming mailing list