On Tue, Mar 09, 2021 at 12:31:34AM +0800, oldk1331 wrote:
> But this macro only expands to this function call, it does not do
> computation at compile time.
>
No. Macro is executed at compile time and result used as expansion.
Most of our macros use "`" (backtick) to delay evaliation and
just insert some variable pieces inside, like:
(defmacro QAREF1(v i)
`(aref (the (simple-array T (*)) ,v) ,i))
Here backtick means that main part will be taken literaly and
only 'v' and 'i' replaced by parameters. But in
(defmacro |mk_DF|(x e) (|make_DF| x e))
there is no backtick, so it runs at compile time. See:
(1) -> )lisp (macroexpand '(|mk_DF| 17 -3))
Value = 0.017
(1) -> )lisp (macroexpand '(QAREF1 17 -3))
Value = (AREF (THE (SIMPLE-ARRAY T (*)) 17) -3)
Of course, in the second case code is wrong because 17 is not a
vector and -3 is not valid index (negative). But 'macroexpand'
does not execute code (and in some weird context this code
could be valid, so 'macroexpand' just dully performs expansion).
--
Waldek Hebisch
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/fricas-devel/20210308165827.GB1217%40math.uni.wroc.pl.