What is the function of combining assert
and -:
in J? Under what circumstances will we apply assert
in order to proceed? Thank you very much.
What is the function of the 'assert' keyword in the J programming language?
95 views Asked by Bob_Li At
1
assert
is a name for the defined verbwhich looks complicated but actually is just testing for a
0
anywhere in a vector using(0 e. ])
If there is a zero then(12"_)
,which is a way to write a verb that returns12
no matter what its argument, is sent to13!:8
which is the foreign conjunction that signals errors. Not surprisingly12
signals anassert
error which is what you want having usedassert
. The0 0 $
in the front assures that after the error interaction begins on the very next line.The monadic form
-:
(Half) does not usually come into play when used withassert
. Dyadic-:
(Match) comes into play as a way to see if two things are a match to each other and it returns a1
if they are and a0
otherwise. This means that the standard way of usingassert
and-:
together are in this form.If the computed result matches the expected result there is no
assert
error, if it does not then anassert
error is raised. Using numerousassert
tests allows a test driven development environment.