PATCH: Translating maxima macros



Hi Stavros,

thanks for your reply. I know that Lisp macros are expanded at compile
time, that is why I am confused. I still think that Maxima macros are
expanded at run time. I have found the option variable macroexpansion,
which has the default value false. I think that the documentation for
macroexpansion states that if it has the value false, then you get a
source-to-source transformation every time the macro is called. I
don't think that the macro with_parameters would work correctly if
this was not true.

So is it true that if macroexpansion is false, then we should not
expand macros at compile time?

Andrej



On Tue, Dec 1, 2009 at 6:23 PM, Stavros Macrakis <macrakis at alum.mit.edu> wrote:
> Yes, the semantics of macros in Lisp and in Maxima have always been to
> expand at compile time so that they have zero runtime overhead.
> Surely you don't want source-to-source transformations to be happening
> every time through a loop?
>
> ? ? ? ? ? ? ?-s
>
> On Tue, Dec 1, 2009 at 5:06 AM, Andrej Vodopivec
> <andrej.vodopivec at gmail.com> wrote:
>> Hi,
>>
>> The maxima translator currently expands maxima macros at compile time
>> not at run time. I think this should be corrected. Here is a patch to
>> expand macros at run time.
>>
>> Andrej
>>
>> Index: transl.lisp
>> ===================================================================
>> RCS file: /cvsroot/maxima/maxima/src/transl.lisp,v
>> retrieving revision 1.42
>> diff -u -r1.42 transl.lisp
>> --- transl.lisp 1 Dec 2009 07:31:34 -0000 ? ? ? 1.42
>> +++ transl.lisp 1 Dec 2009 10:03:15 -0000
>> @@ -748,15 +748,16 @@
>> ?(defun toplevel-optimize-1 (form &aux (op (car form)) prop)
>> ? (cond ((or (atom op)
>> ? ? ? ? ? ? (member 'array op :test #'eq)) form)
>> - ? ? ? ((progn (setq op (car op))
>> - ? ? ? ? ? ? ? (setq prop
>> - ? ? ? ? ? ? ? ? ? ? (if $transrun ? ? ; crock a minute.
>> - ? ? ? ? ? ? ? ? ? ? ? ? (or (get op 'translated-mmacro)
>> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? (mget op 'mmacro))
>> - ? ? ? ? ? ? ? ? ? ? ? ? (or (mget op 'mmacro)
>> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? (get op 'translated-mmacro)))))
>> - ? ? ? ?(mmacro-apply prop form))
>> - ? ? ? ((setq prop ($get op '$optimize))
>> + ? ? ? ;; DONT EXPAND MACROS AT TRANSLATION TIME
>> + ? ? ? ;((progn (setq op (car op)) nil))
>> + ? ? ? ; ? ? ? (setq prop
>> + ? ? ? ; ? ? ? ? ? ? (if $transrun ? ? ; crock a minute.
>> + ? ? ? ; ? ? ? ? ? ? ? ? (or (get op 'translated-mmacro)
>> + ? ? ? ; ? ? ? ? ? ? ? ? ? ? (mget op 'mmacro))
>> + ? ? ? ; ? ? ? ? ? ? ? ? (or (mget op 'mmacro)
>> + ? ? ? ; ? ? ? ? ? ? ? ? ? ? (get op 'translated-mmacro)))))
>> + ? ? ? ; (mmacro-apply prop form))
>> + ? ? ? ((progn (setq op (car op)) (setq prop ($get op '$optimize)))
>> ? ? ? ? ;; interesting, the MAPPLY here causes the simplification
>> ? ? ? ? ;; of the form and the result.
>> ? ? ? ? ;; The optimize property can be used to implement
>> Index: fcall.lisp
>> ===================================================================
>> RCS file: /cvsroot/maxima/maxima/src/fcall.lisp,v
>> retrieving revision 1.14
>> diff -u -r1.14 fcall.lisp
>> --- fcall.lisp ?1 Dec 2009 07:34:34 -0000 ? ? ? 1.14
>> +++ fcall.lisp ?1 Dec 2009 10:03:15 -0000
>> @@ -82,6 +82,9 @@
>> ? ? ? ?((macro-function f)
>> ? ? ? ? (eval (cons f list-argl)))
>> ? ? ? ?((not (symbolp f)) (merror (intl:gettext "apply: expected symbol or
>> function; found: ~M") f))
>> + ? ? ? ;;; EXPAND MAXIMA MACROS
>> + ? ? ? ((setq f-prop (or (get f 'translated-macro) (mget f 'mmacro)))
>> + ? ? ? ?(meval (mmacro-apply f-prop `((,f) , at argl))))
>> ? ? ? ?((setq f-prop (get f 'mfexpr*))
>> ? ? ? ? (funcall f-prop (cons nil argl)))
>> ? ? ? ?((setq f-prop (mget f 'mexpr))
>> _______________________________________________
>> Maxima mailing list
>> Maxima at math.utexas.edu
>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>
>