You might look at avoiding the boxing; for example

?10 # ,:3 1024 768

1 259 473

1 628 503

0 672 357

2 1003 559

0 407 117

2 620 116

0 840 45

2 581 444

2 166 629

1 217 202





On Thu, Dec 24, 2020 at 5:48 AM emacstheviking <[email protected]> wrote:

> I have a simple verb that returns a list of randomised numbers
>
> stargen=: monad define
> 'maxx maxy'=.y
> (?2),(?maxx),(?maxy), 1
> )
>
> For the life of me I have failed to just call it and create a table of the
> results.
>
> Initially I tried 100 $ stargen 1024;768 but that just calls it once and
> cycle repeats the same value one hundred times, close but no tobacco
> related products in sight.
>
> Then I ended up with this version
>
>    sg =: 3 : '(?2),(?100),(?100)'
>    sg2 =: 3 : '(?3),(?0{::y),(?1{::y),1'
>
> and the nearest I got to what I need is this:
>
>    > (sg) each i. 10
> 0 53 53
> 0 52 25
> 0 38 96
> 1 92 75
> 0 31 47
> 1 87 65
> 1 74 11
> 0 30 75
> 0  4 51
> 1 64 99
>
> but when I use the version that takes 1024;768 as the y value (sg2) I get a
> domain error,
>
>    > (sg2 1024;768) each i. 10
> |domain error
> |   >(sg2 1024;768)    each i.10
>
> each is defined as &.> which as I understand it (probably wrong) first
> unboxes the list of integers 0..9 which wasn't even boxed in the first
> place (but I am stuck, after all), after the unboxing it then does the &.
> (under) which applies ....why am I tell you this, you know this.
>
> Eventually I considered making my verb (stargen) a dyad and tackling it
> this way, which works:
>
>    sg3
> 4 : '(?3),(?0{::x),(?1{::x),1'
>
> and running it like this:
>
>   > (1024;768)&sg3 each i. 10
> 2 1013 257 1
> 0  251 127 1
> 2  957 732 1
> 0  508 263 1
> 2  358 340 1
> 2 1012 731 1
> 0   82 436 1
> 1  228  57 1
> 1  990 759 1
> 1  102   4 1
>
> I just wanted a table of N rows of stargen output, passing in the current
> window dimensions. Fail! :D
> Looking for a better / neater / more J like way of doing this so I can
> learn for future sessions.
>
> Thanks
> Sean
> ----------------------------------------------------------------------
> 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