'only x less than 10 is accepted' assert 0

|only x less than 10 is accepted: assert

| 'only x less than 10 is accepted' assert 0

 3 (] $~ [ * $@]) 1 2 3

1 2 3 1 2 3 1 2 3


13 'only x less than 10 accepted'"_`(] $~ [ * $@])@.(10 > [) 1 2 3

only x less than 10 accepted


builtin assert function is poorly defined.  it should return y if not 0/fail

assert =: ][ 13!:8^:((0 e. ])`(12"_))


3 (] $~ [ * $@])^:('only x less than 10 accepted' assert 10 > [) 1 2 3

1 2 3 1 2 3 1 2 3


   13 (] $~ [ * $@])^:('only x less than 10 accepted' assert 10 > [) 1 2 3

|only x less than 10 accepted: assert








On Thursday, January 27, 2022, 08:24:07 a.m. EST, 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