On 02/20/2012 08:38 AM, Robert Dodier wrote:
> On 2/16/12, Stavros Macrakis <macrakis at alum.mit.edu> wrote:
>
>> Since strings are not (currently) in the domain of the Maxima comparison
>> operators, this should either give an error or return 'unknown'. I think I
>> know what Robert's preference would be....
> string value. (At present, is("a" < "b") triggers an error, but that's
> a separate problem; it should be true.)
Just to keep the mailing list record straight, it triggers
an untrapped lisp error (I filed a bug report). gcl even makes me
think my RAM maybe got too hot ("memory may be damaged").
I wonder about the history of why languages differ on how
they implement string comparison, and where maxima fits in.
Mathematica does not transform "a" < "b", but the user can
redefine this to do a string comparison. perl, although
untyped, uses different symbols from numeric for all string
comparisons. I guess that was a choice, perhaps for efficiency.
A related issue is, Mma gives Length[<string>] --> 0, maxima
length(<string>) triggers a lisp error. You could argue
that both Mma and maxima behavior are better than returning
the string length because Part and part won't look inside a
string. One could change length(<string>) to return the
input form with no message. I imagine this would cause much
confusion because many users would try it and be confused by
the results.
But, this stuff could be configurable, at different
levels. The maxima function definition macro defmfun1 (in a
version that I did not post yet) allows a runtime attribute
to be set to choose whether argument checks trigger a maxima
error or just print a message and return the form, like
Mathematica.
(%i2) nest(f,x,3);
(%o2) f(f(f(x)))
(%i3) nest(8,x,3);
nest: Argument '8' is not a function in nest(8,x,3).
(%i4) set_match_form(nest); /* maybe not a good name*/
(%o4) true
(%i5) nest(8,x,3);
nest: Argument '8' is not a function in nest(8,x,3).
(%o5) nest(8,x,3)
By the way, many Mathematica users who write largish
programs find debugging and controlling the number of
messages difficult.
P.S. The untrapped lisp error for length("dog") is better
than the trapped error for length(1).
(%i1) length("dog");
Maxima encountered a Lisp error:
The value "dog" is not of type LIST.
(%i1) length(1)
length: argument cannot be a number; found 1 /* what argument would be valid ? */
-- an error. To debug this try: debugmode(true);
/* The user has seen this 10^6 times, and decides not to take another crash
course in lisp syntax and printing a stack trace */
The reason the first kind of message is better is because it came from a generic
error trapping mechanism where some thought or review of the message is
possible. The second message is ad-hoc, written into the body of length().
P.P.S. But, apparently '-1' is not a number if inflag is false;
(%i1) length(-1);
(%o1) 1
-- John Lapeyre