On Wed, Mar 23, 2011 at 7:43 AM, Adrian May
<[email protected]> wrote:
> You probably already guessed what the problem is. I want to write something
> like:
...
> vary =. +&(?10)
...
> but it only evaluates the ? once and reuses that value. I want a different
> number every time. How do I do that?

If you examine the definition for vary, you will see that you have
picked a random number and incorporated that random number into its
definition.  But what you really want is for ? to wait until you have
passed an argument to vary before ? evaluates.

To accomplish that, in place of the noun 10, you should be using a
verb that always returns the result 10.  That way, it will not
evaluate until you pass it an argument.

One way to accomplish this would be:

vary=: +&(? bind 10)

But you can also give 10 a rank which automatically produces a
constant valued verb.  (And bind does that for you.)

FYI,

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

Reply via email to