BUG? scanmap(..., bottomup) with function returning number
Subject: BUG? scanmap(..., bottomup) with function returning number
From: Albert Reiner
Date: 29 Oct 2004 14:58:39 +0200
Hi,
consider the following (here I only have Maxima 5.9.0, but I have seen
the same in a later version at home, too):
,----
| (C1) scanmap(lambda([e], if atom(e) then 5 else e), a+b);
|
| (D1) 10
| (C2) scanmap(lambda([e], if atom(e) then 5 else e), a+b, bottomup);
|
|
| Type-error in KERNEL::OBJECT-NOT-LIST-ERROR-HANDLER: 5 is not of type LIST
`----
I suppose there is no reason why it should be illegal to return a
number (is anything else represented as a Lisp atom?), so this looks
like a bug to me.
As far as I can tell, the problem comes from this call to SUBST0
,----[ src/comm2.lisp ]
| (DEFMFUN SCANMAP1 N
| (LET ((FUNC (ARG 1)) (ARG2 (SPECREPCHECK (ARG 2))) NEWARG2)
| (COND ((EQ FUNC '$RAT) (MERROR "SCANMAP results must be in general representation."))
| ((> N 2)
| (COND ((EQ (ARG 3) '$BOTTOMUP)
| (COND ((MAPATOM ARG2) (FUNCER FUNC (NCONS ARG2)))
| (T (SUBST0 (FUNCER FUNC
^^|^^^
-------------------------------'
| (NCONS (MCONS-OP-ARGS
| (MOP ARG2)
| (MAPCAR #'(LAMBDA (U)
| (SCANMAP1
| FUNC U '$BOTTOMUP))
| (MARGS ARG2)))))
| ARG2))))
| ...
`----
As subst0 explicitly expects something that is not a Lisp atom:
,----[ src/comm.lisp ]
| (DEFMFUN SUBST0 (NEW OLD)
| (COND ((ALIKE (CDR NEW) (CDR OLD))
| ...
`----
It seems to me that either SUBST0 is the wrong function to call, or
that it should be something like
,----
| ...
| (T (let ((aux (FUNCER FUNC
| (NCONS (MCONS-OP-ARGS
| (MOP ARG2)
| (MAPCAR #'(LAMBDA (U)
| (SCANMAP1
| FUNC U '$BOTTOMUP))
| (MARGS ARG2)))))))
| (if (atom aux) aux (SUBST0 aux ARG2))
| ...
`----
instead; however, I don't quite understand the Maxima code and whether
that would be correct.
Anyway, while I can work around the problem, I would appreciate it if
this were fixed.
Best regards,
Albert.