[Maxima] argument checking, was: About submatrix and its meaning
robert.dodier at gmail.com
Mon Nov 23 10:02:53 CST 2009
On 11/22/09, Richard Fateman <fateman at cs.berkeley.edu> wrote:
> How about
> foo(x,y,??x>y):= ....
> so the predicate can involve all the parameters.
> Note also the possibility of extending this idea to function
> discrimination based on types or predicates
> myabs(x??x<=0):= -x;
> which brings us closer to (for example) common lisp object system,
Hmm, I guess this is the famous "multiple dispatch" scheme.
I dunno --- maybe we could save ourselves some trouble by simply
exposing CLOS to the user? Just dreaming at this point.
> and incidentally to Mathematica.
Well, more precisely, closer to Maxima's own simplification system.
Which leads me to wonder what is the appropriate behavior for
failed predicates. Typically in functions (but not always) a failed
argument test triggers an error message. But in simplification rules,
it's just a non-match, nothing happens. It seems there's room for
both behaviors, in different contexts. But I don't see a simple way
to indicate one or the other. Maybe foo(x ?? P) for "do nothing" and
foo(x !! P) for "report error" ? Seems kind of clumsy.
Incidentally a different notation could move the test predicate
outside the list of arguments, maybe:
foo(x) := ... assuming P(x);
I've toyed with macros to enable a similar syntax for simplification
rules, in which foo(x) --> ... assuming P(x) turns into appropriate
More information about the Maxima