You can box y, repeat it with dyadic #, and then raze the boxes:

   3 ([: ; [#<@]) 'hi'
hihihi
   3 ([: ; [#<@]) 1 2 3
1 2 3 1 2 3 1 2 3
   3 {{ ; x # <y }} 1 2 3
1 2 3 1 2 3 1 2 3

The 'J By Point and Click' lab introduces a graphical debugger that you could 
use in place of manually added debugging output.

I don't really follow your (d;d) question but you could define either verb in 
terms of the other:

   repeat =: [: ; [#<@]
   2 repeat 'x'
xx
   repeat2 =: 0&{:: repeat 1&{::
   repeat2 2;'x'
xx
   repeat3 =: repeat2@;
   2 repeat3 'x'
xx

In general I'd not worry too much about which is right, and instead be quick to 
notice when a choice leads to more trouble when used.

------- Original Message -------

On Thursday, January 27th, 2022 at 7:23 AM, Pawel Jakubas 
<[email protected]> wrote:

> Dear J enthusiasts,
>
> I am defining `x repeat y` function, that is appending y to itself x times.
>
> And defined something like below (on intention like that to ask a couple of
>
> questions).
>
> f=: 4 : 0
>
> assert (x < 10)
>
> segment=.>0{y
>
> if. (x = 1) do. (>1{y) else. (x-1) f (segment;( (>1{y),segment) ) end.
>
> )
>
> d
>
> 1 2 3
>
> 1 f (d;d)
>
> 1 2 3
>
> 2 f (d;d)
>
> 1 2 3 1 2 3
>
> 3 f (d;d)
>
> 1 2 3 1 2 3 1 2 3
>
> 1.  Is there a way to customize assert message. So instead of
>
>     11 f (d;d)
>
>     |assertion failure: assert
>
>     | assert(x<10)
>
>     have for example message "only x less than 10 is accepted"
> 2.  How to introduce debugs? For example I would like to print x as f
>
>     executes
> 3.  Do we have by the way `repeat` in J as I try to define?
> 4.  I intentionally defined f like above as it needs (d;d) as y. Let's
>
>     assume I want higher level `repeat` dyad that is
>
>     x repeat d
>
>     and
>
>     defines inside `f` dyad as above and calls it
>
>     x f (d;d)
>
>     What are good practices to to separate x,y from repeat and not to mix them
>
>     in the defined function f (ie. have them decoupled).
>
>     Thanks in advance and cheers,
>
>     Pawel
>
> 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