Discussion:
[Maxima-discuss] Cannot declare string of one character as alphabetic
Roland Salz
2017-07-22 19:48:56 UTC
Permalink
Maxima 5.40.0, console, sbcl:



A string of two characters can be declared alphabetic successfully with

declare("+-", alphabetic); -> done

But a string of one character throws me to the debugger

declare("-", alphabetic); ->

The value

MMINUS

is not of type

SEQUENCE

when binding SEQUENCE



Since a string of one character is a valid string, I don't understand that.



Best regards,

Roland
Robert Dodier
2017-07-23 17:16:10 UTC
Permalink
Post by Roland Salz
But a string of one character throws me to the debugger
declare("-", alphabetic); ->
The value
MMINUS
is not of type
SEQUENCE
when binding SEQUENCE
"-" (likewise "+" "*" etc) is converted to the corresponding operator
symbol, namely MMINUS. This is a bug in declare -- it should process the
string verbatim. I see DECLARE1 (src/mlisp.lisp) calls GETOPR before
processing the alphabetic declaration. Presumably GETOPR should be
called after alphabetic (and any other declaration that expects a
non-symbol; I don't know if there are any).

We can argue about whether Maxima should allow operator characters to be
declared alphabetic, but for the sake of consistency it should be
allowed (you get what you say you want, Maxima won't stand in your way),
and anyway it is already possible -- just double the character and
GETOPR won't notice it, e.g.: declare("++", alphabetic);

best

Robert Dodier
Roland Salz
2017-07-23 17:44:22 UTC
Permalink
-----Original Message-----
Sent: Sunday, July 23, 2017 7:16 PM
We can argue about whether Maxima should allow operator characters to
be declared alphabetic, but for the sake of consistency it should be
allowed
Thanks for your investigations on this.
There seems to be no problem with declaring "+" or "-" alphabetic:

declare("+-",alphabetic);
a+ : 1;
a+ + 2; -> 3
a+ - 2; -> -1

As you can see from my following mail, the "-" as alphabetic is quite convenient if you want to access lisp-functions
directly from maxima with ?<lisp-function>, since "-" is "alphabetic" in lisp.
anyway it is already possible -- just double the character and GETOPR
won't notice it, e.g.: declare("++", alphabetic);
This is only a workaround, no solution. If the manual says, we can use a string (any string) as argument to declare,
then I think it should work for all strings, including the single-character string. It will not be such an exceptional
case that someone tries to make a single character alphabetic.

Best regards,
Roland
Roland Salz
2017-07-23 18:00:44 UTC
Permalink
PS:

Well, I see that Maxima allows strings to even begin with a self-declared alphabetic character. This of course causes
problems:

declare("+-",alphabetic);
+a: 1; -> 1
+a+2; -> +a+2
+a +2; -> error


-----Original Message-----
From: Roland Salz [mailto:***@gmail.com]
Sent: Sunday, July 23, 2017 7:44 PM

Loading...