I think that that kind of structure is perfect for simulation code. If you are using a ‘random number generator’ or similar, it’s good to convey to the reader that something unusual is going on — it’s not really function calls.
This works perfectly for that. Thanks, — Raul On Monday, August 13, 2018, Ulrich Vollert <[email protected]> wrote: > Hello, > > for some weeks, I am learning J in my (very little) spare time. And I have > a (beginner) question. > > After reading a lot (first place: „Learning J“) and doing some exercises, > I am developing a small Monte Carlo simulation. > > I have a dyadic verb „play“ which does a simulation step (calling random > generator, calculating) and answering a result. My first attempt to call > this verb in a loop was: > > simuls=: 1000 NB. count of simulations > > i=. simuls > result=.0 > while. i > 0 do. > result=.result + x play y > i=.i-1 > end. > result % simuls > > But this doesnt look and feel as J style. My second attempt is to > duplicate the second argument as often as I want to do the simulation: > > (+/%#) x play_hand (simuls # y) > > or shorter: > > (+/%#) @: play_hand simuls&# > > I am wondering whether this is a good solution (for instance: space > efficiency)? Would a solution with Power (^:) a better approach? > > Thanks in advance for your comments. > Ulrich > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
