On Sun, 15 Mar 2020, Sven Schreiber wrote:
Hi,
often in user-defined functions we have a bunch of error checks like this:
if maybe_bogus_input
funcerr("cannot do that")
endif
What about adding the if condition to the funcerr() function as a scalar
second argument? So the above would become:
funcerr("can't do that", maybe_bogus_input)
I admit right away that this is mainly one of my syntactic-sugar ideas,
to save 2/3 of the needed lines of code - because in my function
packages and addons the error and input checking block often becomes
quite long.
(However, perhaps there is even a little bit more to it, because one
could pass the extended funcerr() variant to feval() which might open up
new ways.)
I like the idea here, but my inclination would be to do it via a
function-variant of "catch", as in
catch(maybe_bogus_input, "can't do that")
meaning: if the antecedent is true, do funcerr with the consequent
as error message.
Either way it's an overloading and I'm not sure my suggestion is
better, but to my mind it's more logical to put the condition first,
then the response, and we can't prepend an argument to funcerr
without backward incompatibility. An alternative would be a new
errif() or errorif() function that does the same as catch() above.
Hope everybody's well!
Amen. OK so far here.
Allin