The following syntax error should be caught by draw:
(%i2) draw2d(explicit(sin));
Maxima encountered a Lisp error:
Condition in MACSYMA-TOP-LEVEL [or a callee]: INTERNAL-SIMPLE-PROGRAM-ERROR: MACSYMA-TOP-LEVEL [or a callee] requires more than one argument.
Automatically continuing.
To enable the Lisp debugger set *debugger-hook* to nil.
At first glance, it seems as if we need to modify
explicitto take rest args so that we can check the number of args and produce a nice error function.defmfunwould do this for us, but that would expose a$explicitfunction that we probably don't want to have.Perhaps a new
defmfun-internalmacro would be useful for cases like this. Basically likedefmfun, but doesn't create$foofunction.I think that is one approach. A related one is to have a beefed-up
defunthat allows a syntax likeThis could expand into a
defunwith all args made optional and a collection ofassertions to do the argument type checking and emit an error when needed. That might have uses beyonddraw. This would also incorporate Gunter's suggestion.Another option is write an argument parser for
drawand catch the syntax errors there.Thanks for explaining what
type-of-funandfun-error-messagewould do.While such things are possible and also part of defstructs and defclasses, it seems unnatural for lisp functions (and macros) to do the same. (Yes, loop allows this.) It seems typically lisp style would be to
declarethese, and/or usecheck-typeexplicitly to detect types.But I understand it makes it easier to see (sort of) that the arguments are expected to have certain types. But this could also be seen from the
declarestatements.I think this has limited utility, at least in the context of draw. For example, the type of xmin has to be basically T because xmin can be any kind of maxima expression that evaluates to a numerical value. So I'm not sure what type-of-xmin would really say.
On the other hand, if this is really desired, I think it can be layered on top of the new
defun-checkedby extracting the variable names and callingdefun-checkedappropriately, and updating the body to add the appropriate declarations orcheck-typeto check the argument type and produce the given error message.I don't follow. Why would you check the unevaluated expression for
xmin? Its value must be numerical, no?Would it make sense and not too much overhead if
defmfun-internalaccepted an optional argument with a more specific text about whatexplicit()and similar do?What does this optional argument with text do? How is it supposed to be used? It sounds somewhat like a docstring for
explicit, but I'm not sure.defmfunand friends already support a docstring.Can you, Leo, explain a bit more on what "type-of-fun" does and what "fun-error-message" is supposed to do?
I think I can guess, but, I want to know what you had in mind.
I personally would rather have the error message in the code since it's more general that way because in general you might want to give more information about what's illegal. I really error messages that say "illegal", when there's enough information to say "illegal because smin (xmin-val) must be <= xmax (xmax-val)".
Ray, I have in mind that
type-of-funcould be a type checker for the argumentfun. It would returntornil. Andfun-error-messagecould be a string or a thunk that emits an informative error in the event thattype-of-funevaluates tonil. I think both could be optional, so that iftype-of-funis omitted, the default evaluates totand iffun-error-messageis omitted, some default error message is emitted.I think this could be scaffolded on top of
defun-checked.I hacked something together, kind of resurrecting the old
defun-checked(but in a different way). Now I getI just changed
(defun explicit ...)to(defun-checked explicit ...).defmfunnow usesdefun-checkedto do the heavy lifting.You can find the changes on the rtoy-3970-defmfun-internal branch.
Last edit: Raymond Toy 2022-05-06
Ray: I didn't test out your branch, but I glanced at some commits. It looks like you undid the change which removes the leading
$from names when creating the impl names, so it looks like$FOOagain has an impl name$FOO-IMPL.Removing the leading
$was introduced because the impl names were visible inaproposresults. See bug [#3643].Related
Bugs:
#3643Good point. I'll make sure to fix that soon.
This is fixed in commit [9f073b].
I think I got all of the functions used by draw updated to catch incorrect number of args and produce a nice maxima error and message, in line with how other maxima functions work.
I did not, however, incorporate Leo's suggestion about enhancing
defun/defmfunto include type info and error strings. I think if that's really desired, we can implement that on top ofdefun-checkedand/ordefmfun.Related
Commit: [9f073b]