Why does 'matrix' evaluate its arguments anomalously?
Subject: Why does 'matrix' evaluate its arguments anomalously?
From: Stavros Macrakis
Date: Fri, 11 Nov 2011 17:33:24 -0500
The matrix function evaluates its arguments anomalously:
x1: 'x2$
apply('matrix,'[[x1]]) => matrix([x2])
Compare this with other functions with n arguments:
apply('append,'[[x1]]) => [x1]
This is because matrix is defined as an mspec, evaluating its own arguments:
(defmspec $matrix (L) ... (let ((rows (mapcar #'meval (cdr L)))) ,,,)
while append is defined like this:
(defmfun $append (&rest args)...)
I suspect this is purely a historical artifact from an ancient version of
MacLisp/meval which didn't have &rest arguments.
Can anyone think of a reason that matrix shouldn't be simply this:
(defmfun $matrix (&rest rows)
;; special case not necessary for 0 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))