Thanks to both of you. I'm trying to work either of those solutions into my program now. But I'd still like to understand how those two spells work, and in general what decides whether something gets evaluated earlier or later. Looks like that @: "0 trick somehow convinced the interpreter that it needed to wait for a parameter or something. No idea what 10&(13 means.
Adrian. On 23 March 2011 20:15, Mike Day <[email protected]> wrote: > Your problem is that "vary" is fixed when it's > defined. The random number is evaluated only > when (& whenever) you define "vary". > > eg from a J session: > vary =: +&(?10) NB. define it > vary NB. display it > +&4 > vary^:(i.5) 10 NB. run it > 10 14 18 22 26 > vary =: +&(?10) NB. 2nd try > vary > +&3 > vary^:(i.5) 10 > 10 13 16 19 22 > vary =: +&(?10) NB. 3rd try > vary > +&6 > vary^:(i.5) 10 > 10 16 22 28 34 > > One way to achieve what you evidently require > is > vary =: 10 & (13 : 'y+?x') > vary > 10&(] + [: ? [) > vary^:(i.5) 10 > 10 13 21 24 28 > > although I'd usually use an array approach, eg: > 10 + ?5#10 > 10 11 14 19 10 > > Mike > > > On 23/03/2011 11:43, Adrian May wrote: > >> Hi folks, >> >> You probably already guessed what the problem is. I want to write >> something >> like: >> >> n=.100 >> vary =. +&(?10) >> n=.vary n >> n >> n=.vary n >> n >> n =. vary^:10 (100) >> n >> >> but it only evaluates the ? once and reuses that value. I want a different >> number every time. How do I do that? >> >> Adrian. >> >> PS: I was hoping to keep my whole program to one line just to scare >> people. >> It seems to work better in a function but even then I have problems >> sometimes. What's the logic behind whether it re-evaluates ? or not? >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> >> > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
