Why does 'matrix' evaluate its arguments anomalously?



Yuck. Yuck. Yuck.  Is that really true?  GCL has no way of handling > 64
args?  I suppose one way of handling that is simply to say that it is an
implementation restriction....

But if we want to preserve both correct semantics and no arbitrary
implementation restrictions, I suppose we could make $matrix into a Maxima
function, like this:

(mputprop '$matrix '((lambda) ((mlist) ((mlist) $x)) ((build_matrix) $x))
'mexpr)

(defmfun build_matrix (rows)
  (if (not ($listp rows))
      (merror "check_matrix -- internal error ~M" rows)
    (setq rows (cdr rows)))
  (dolist (row rows)
    (if (not ($listp row)) (merror (intl:gettext "matrix: row must be a
list; found: ~M") row)))
  (matcheck rows)
  (cons '($matrix) rows))

Pretty ugly.  Is there a better way?

          -s

On Sat, Nov 19, 2011 at 17:14, Robert Dodier <robert.dodier at gmail.com>wrote:

> On 11/11/11, Stavros Macrakis <macrakis at alum.mit.edu> wrote:
>
> > Can anyone think of a reason that matrix shouldn't be simply this:
> >
> > (defmfun $matrix (&rest rows)
>
> OK, I remember now why matrix isn't an ordinary function.
> GCL has a limitation of 64 arguments for a function, so attempting
> to define a matrix with > 64 rows triggers an error.
> That bug was noticed and a work around put in place; see commit message
> below.
> If there is a better way to handle the situation, while still keeping it
> workable for GCL, I'd be interested to hear about it.
>
> best
>
> Robert Dodier
>
> PS.
> commit 9bcad16b9eedcb8725197313808bc88fe1ce6b88
> Author: robert_dodier <robert_dodier>
> Date:   Thu Oct 12 15:18:45 2006 +0000
>
>    (1) Work around GCL number of arguments limitation in $matrix.
>    src/mlisp.lisp: change $matrix from defun to defmspec, and
> evaluate arguments within $matrix.
>      From point of view of caller, $matrix should work same as before
> (but without bug).
>    tests/rtest2.mac: new test cases for matrix function.
>
>    (2) Avoid unintended upper/lower case inversion in declare(foo,
> alphabetic) (in src/mlisp.lisp).
>      Also process all characters in a string instead of just one at a time.
>