|
From: Stavros M. <mac...@gm...> - 2024-07-29 23:18:54
|
The matrix/array/etc. input functions are defined in the *numericalio* section
of the manual, so I suppose that it's not surprising that they have strange
behavior for non-numbers. In fact, the overview page says "The *numericalio*
functions may attempt to do something sensible faced with nonatomic [not
just non-numeric?] expressions, but *the results are not specified here and
subject to change*."
It seems to me that the "sensible" thing to do with non-numbers is to give
an error. That is far more likely to be useful to users than producing
peculiar results when there's a typo or a bug in upstream software or
whatever.
On the other hand, I'd expect them to work for all Maxima numbers,
including rationals. Currently, they read 1/3 as [1,/,3], which isn't
terribly helpful. If at some point Maxima defined a syntax for complex
numbers, I'd expect those to work, too -- but we can cross that bridge when
we get to it.
On the third hand, if there's demand for reading non-numbers, we should
have well-defined functions along the lines of *read_tokens,
read_expressions*, *read_csv *(following the standard), etc. rather than
the current undocumented and surprising behavior.
In fact, it looks like the code isn't designed to produce consistent
results for nonatoms. I tested using *read_matrix*:
*Input* *Output* *Comment*
a a
- IGNORES this line completely -- "numericalio: trailing sign
(-1) at end of line; strange, but just eat it."
-3 -3 OK
-a -a (= -1*a, even though it's two tokens)
+a a DROPS the +
--a -a DROPS first "-"
++a a DROPS plus signs
A "-" at the beginning of the line does strange things:
-,1 ((MLIST) ((MTIMES) -1 |$,|) 1) <<< not an error??
Isn't read_matrix supposed to produce a matrix (all rows the same length?)
-- doc says "If some lines have different lengths, ‘read_matrix’ complains."
But I got this matrix back:
,,,, => [false,false,false,false,false] -- length 5
-,1 => [, [[(-1)*\,,1]] -- length 1
-,,1, => [(-1)*\,,1,false] -- length 3
-,,, => [(-1)*\,,false,false]] -- length 3
Tested in 5.46.0, SBCL 2.3.0.
-s
|