A patch for the translator
- Subject: A patch for the translator
- From: Andrej Vodopivec
- Date: Sun, 29 Nov 2009 14:34:14 +0100
The translator does not translate mdoin correctly:
(%i3) f(x) := for i in [1,2,3] do x^i;
(%o3) f(x):=for i in [1,2,3] do x^i
(%i4) :lisp (trace tr-mfun);
(TR-MFUN)
(%i4) translate(f);
Part of the trace output:
0: (TR-MFUN $F)
0: TR-MFUN returned
(PROGN
(DEFPROP $F T TRANSLATED)
(ADD2LNC '$F $PROPS)
(DEFMTRFUN ($F $ANY MDEFINE NIL NIL) ($X) (DECLARE (SPECIAL $X))
(DO (($I)
(MDO (CDR (LIST '(MLIST) 1 2 3)) (CDR MDO)))
((NULL MDO) '$DONE)
(SETQ $I (CAR MDO))
(DECLARE (SPECIAL $I)) <<--- declare in a wrong position!
(POWER $X $I))))
This is a patch for transl.lisp to correct the position of declare:
Index: transl.lisp
===================================================================
RCS file: /cvsroot/maxima/maxima/src/transl.lisp,v
retrieving revision 1.41
diff -u -r1.41 transl.lisp
--- transl.lisp 16 Aug 2009 04:34:53 -0000 1.41
+++ transl.lisp 29 Nov 2009 13:19:36 -0000
@@ -1437,8 +1437,8 @@
(tunbind 'mdo) (tunbind (cadr form))
(return
`(,mode do ((,var) (mdo (cdr ,init) (cdr mdo)))
- ((null mdo) '$done)
- (setq ,var (car mdo)) . ((declare (special ,var)) .
+ ((null mdo) '$done) .
+ ((declare (special ,var)) (setq ,var (car mdo)) .
,(cond ((atom (cdr action)) nil)
((eq 'progn (cadr action)) (cddr action))
(t (list (cdr action))))))))))
After the patch is applied I get:
(%i10) f(x) := for i in [1,2,3] do x^i;
(%o10) f(x):=for i in [1,2,3] do x^i
(%i11) compile(f);
0: (TR-MFUN $F)
0: TR-MFUN returned
(PROGN
(DEFPROP $F T TRANSLATED)
(ADD2LNC '$F $PROPS)
(DEFMTRFUN ($F $ANY MDEFINE NIL NIL) ($X) (DECLARE (SPECIAL $X))
(DO (($I)
(MDO (CDR (LIST '(MLIST) 1 2 3)) (CDR MDO)))
((NULL MDO) '$DONE)
(DECLARE (SPECIAL $I))
(SETQ $I (CAR MDO))
(POWER $X $I))))
(%o11) [f]
The trace output seems correct and the translation works as expected.
If nobody objects I will commit the patch.
Andrej