#279 Strings mishandled in constantp, orderlessp, comparison

None
closed
Robert Dodier
Lisp Core (472)
5
2012-12-14
2003-03-28
Stavros Macrakis
No

Most parts of Maxima incorrectly treat Maxima strings
(e.g. "foo") as variables, not as manifest constants.
This is understandable, since they are represented
internally as Lisp symbols, but is still incorrect.

A few places get it right. For example, setting a string
to a value ("f":3) gives an error. But note that mset
doesn't even use the standard mstringp predicate....

In many places, the problem with strings is simply that
illegal operations don't give errors, e.g. depends("f",g).

But in other places, meaningful operations give incorrect
answers:

constantp("foo") => false BAD
This is easy to fix, and the runtime overhead shouldn't
be an issue nowadays. Though perhaps it would be
better to give string symbols an explicit plist property.

orderlessp(foo,"foo") => true, though the convention is
that all manifest constants come before variables. Cf.
sort([2,%pi,foo,"foo"]) => [2,%PI,foo,"foo"]

Probably the biggest problematic area is in
comparisons. Since string comparisons don't work,
strings become pretty useless in Maxima programming.

The following comparisons give errors:

is("a"<"b")
is("a"<="b")
is("a" # "b")
is(equal("a","b"))

Though the following predicates work correctly:

is("a"="a") => true
is("a"="b") => false
is("a" # "a") => false
is("a" # "b") => true
is("a"<="a") => true
is(equal("a","a")) => true

Not by coincidence, the correct cases are those where
the rules for variables give the correct result....

Of course, it would be better to convert Maxima strings
to use Lisp strings, but in the meantime.... Note, by the
way, that Maxima DOES depend on the fact that strings
are interned to do things like put the OPR property on
&+. But this can of course be fixed.

Maxima 5.9.0 GCL 2.5.0 mingw32 Windows 2000

1 Attachments

Discussion

  • Robert Dodier
    Robert Dodier
    2006-07-04

    • labels: --> Lisp Core
     
  • Robert Dodier
    Robert Dodier
    2007-06-04

    • assigned_to: nobody --> robert_dodier
     
  • Robert Dodier
    Robert Dodier
    2007-06-04

    Logged In: YES
    user_id=501686
    Originator: NO

    I'd like to see this problem get fixed. Assigning this report to myself accordingly.

     
  • Robert Dodier
    Robert Dodier
    2012-12-14

    • status: open --> closed
    • milestone: --> None
     
  • Robert Dodier
    Robert Dodier
    2012-12-14

    Some of the problems are the subject of other bug reports (#1494, #2357) and the rest yield correct results now. Therefore closing this report.

    I've attached a script (rtest_bug279.mac) which tests the results mentioned in this report. Pasting the output here as I don't see a way to attach 2 files at a time.

    Maxima 5.29.1 http://maxima.sourceforge.net
    using Lisp CLISP 2.49 (2010-07-07)
    Distributed under the GNU Public License. See the file COPYING.
    Dedicated to the memory of William Schelter.
    The function bug_report() provides bug reporting information.
    (%i1) batch ("/home/robert/maxima/playpen/rtest_bug279.mac", test);

    batch: write error log to #<OUTPUT BUFFERED="" FILE-STREAM="" CHARACTER="" home="" robert="" maxima="" playpen="" rtest_bug279.ERR="">
    *** Problem 1 **
    Input:
    errcatch(f : 3)

    Result:
    assignment: cannot assign to f
    []

    ... Which was correct.

    *** Problem 2 **
    Input:
    errcatch(depends(f, g))

    Result:
    depends: argument must be a symbol; found: f
    []

    ... Which was correct.

    *** Problem 3 **
    Input:
    errcatch(constantp(foo))

    Result:
    declare: argument must be a symbol; found foo
    []

    ... Which was correct.

    *** Problem 4 **
    Input:
    orderlessp(foo, foo)

    Result:
    false

    ... Which was correct.

    *** Problem 5 **
    Input:
    sort([2, %pi, foo, foo])

    Result:
    [2, %pi, foo, foo]

    ... Which was correct.

    *** Problem 6 **
    Input:
    is(a < b)

    Result:
    error-catch

    This differed from the expected result:
    true

    *** Problem 7 **
    Input:
    is(a <= b)

    Result:
    error-catch

    This differed from the expected result:
    true

    *** Problem 8 **
    Input:
    is(a # b)

    Result:
    true

    ... Which was correct.

    *** Problem 9 **
    Input:
    is(equal(a, b))

    Result:
    false

    ... Which was correct.

    *** Problem 10 **
    Input:
    is(a = a)

    Result:
    true

    ... Which was correct.

    *** Problem 11 **
    Input:
    is(a = b)

    Result:
    false

    ... Which was correct.

    *** Problem 12 **
    Input:
    is(a # a)

    Result:
    false

    ... Which was correct.

    *** Problem 13 **
    Input:
    is(a # b)

    Result:
    true

    ... Which was correct.

    *** Problem 14 **
    Input:
    is(a <= a)

    Result:
    true

    ... Which was correct.

    *** Problem 15 **
    Input:
    is(equal(a, a))

    Result:
    true

    ... Which was correct.

    13/15 tests passed

    The following 2 problems failed: (6 7)
    (%o1) [/home/robert/maxima/playpen/rtest_bug279.mac, 6, 7]