Thank you, Viktor, that is great!
(For latecomers, the question was how to write a tacit verb that checks its arguments, for
example a monad"0 that returns the natural logarithm of its argument but exits with an error
message if the argument is not real and positive excluding _ (infinity).)
Then
Assert =: [:`...@. NB. Viktor Cerovski
f =: [: ^. (<&_ * >&0) Assert"0
f
[: ^. [:`...@.(<&_ * >&0)"0
f 1 2 3 4
0 0.693147 1.09861 1.38629
f 0j1
|domain error: f
| f 0j1
f b. 0 NB. The following is my fault, not Viktor's
_ _ _
Viktor puts the "0 in the right place. If I really wanted monad"0 I could have used ^. @ ...
for the composition and (] :[:) in the definition of Assert.
How can I produce my own error message, for example "error: arguments must be
positive excluding _"?
Viktor Cerovski wrote:
(snip)
Assert=:[:`...@.
(<&_ * >&0) Assert
[:`...@.(<&_ * >&0)
(<&_ * >&0) Assert"0 (1 2 3 4)
1 2 3 4
(<&_ * >&0) Assert"0 (1 2 3 4 0)
|domain error
| (<&_*>&0)Assert"0(1 2 3 4 0)
^. (<&_ * >&0) Assert"0 (1 2 3 4)
0 0.693147 1.09861 1.38629
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm