One way to get the simple repeat function is this:

   ] d =: >: i.3
1 2 3
   f =: [ ;@# {.@]
   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

If you don’t call f with d;d but simply with d,
then you can just define

   f =: ;@#

which I consider an answer to your question 3.


Am 27.01.22 um 14:23 schrieb Pawel Jakubas:
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

--
----------------------
mail written using NEO
neo-layout.org
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to