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?
124 views Asked by Bob_Li At
1
assertis a name for the defined verbwhich looks complicated but actually is just testing for a
0anywhere in a vector using(0 e. ])If there is a zero then(12"_),which is a way to write a verb that returns12no matter what its argument, is sent to13!:8which is the foreign conjunction that signals errors. Not surprisingly12signals anasserterror 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 a1if they are and a0otherwise. This means that the standard way of usingassertand-:together are in this form.If the computed result matches the expected result there is no
asserterror, if it does not then anasserterror is raised. Using numerousasserttests allows a test driven development environment.