f =: (+^:10)&0 
f 5 
50 

the f below, uses x as the "original y", and y is an additional number to be 
added to (set to 0 here to be equivalent to no parameter).

in ^:, the x parameter to the resulting verb is a constant.




----- Original Message -----
From: Jon Hough <[email protected]>
To: "[email protected]" <[email protected]>
Cc: 
Sent: Sunday, August 2, 2015 12:06 PM
Subject: Re: [Jprogramming] Understanding ^:

Thanks, yes my attempt doesn't work, and it was a bit silly. I was just trying 
to give the simplest possible example of my problem. I think my example hasn't 
shown the issue I'm talking about.
I want to do some iteration on y, where each step of the iteration has access 
to the original y value. I'm not sure how to do this, because it seems that 
everything to the left of ^: has no access to the initial value.


> Date: Sun, 2 Aug 2015 15:55:14 +0000
> From: [email protected]
> To: [email protected]
> Subject: Re: [Jprogramming] Understanding ^:
> 
> first you are using + monadially here.
> 
> A conjunction (most of them) becomes a verb after it has 2 arguments bound to 
> it.  So,
> 
> f =: +^:10
> 
> is a dyadic (or monadic verb, but monadic + is not that interesting)
> 
>  5 (+^:10) 0 
> 50 
> 
>  5 (+^:10) 2 
> 52 
> 
> 
> A way to double 10 times, that looks a bit similar but is a monadic adverb
> 
>  10 (+:^:)   2 
> 2048 
> 
> 
> A dyadic adverb needs 2 parameters on the right
> 
> f =. +^:
> 
> 5 (10 f)   2 
> 52 
> 
> 
> 
> 
> ----- Original Message -----
> From: Jon Hough <[email protected]>
> To: "[email protected]" <[email protected]>
> Cc: 
> Sent: Sunday, August 2, 2015 11:26 AM
> Subject: [Jprogramming] Understanding ^:
> 
> 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

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

Reply via email to