On Mon, Dec 22, 2025 at 12:38:08AM +0100, 'Ralf Hemmecke' via FriCAS - computer 
algebra system wrote:
> Hi Waldek,
> 
> I just realized that macro expansion in the interpreter works differently
> than in the compiler.
> 
> %%% (253) -> to(C)(x,y) ==> (x::C) + (y::C)
> %%% (254) -> foo(x: Integer): Integer == to(Integer)(3+x, 2*x)
>    Function declaration foo : Integer -> Integer has been added to
>       workspace.
> %%% (255) -> foo(4)
>    Compiling function foo with type Integer -> Integer
> 
>    (255)  15
>                                          Type: PositiveInteger
> 
> That kind of macro seem to work in the interpreter.

IIRC this sometimes works, but not always.
 
> Unfortunately, it doesn't in SPAD, see below.
> 
> Is there any way to make that work?
> 
> I actually want even something like
>   mac(A,B)(x,y) ==> ...
> 
> and then use mac(U,V) as an argument in another macro.
> 
> Shouldn't that be possible?
> It would make me sad if this does really not work in SPAD.

First step, very important for such things, is to define what it
should do, what is considered correct and what should signal
error.  So, let me try.  You want staged macro expansion.
We could say that partially expanded macro is a "macro
function".  The simplest case is macro name, that is symbol
naming a macro.  But also you want 'mac(A,B)' to produce
macro function which could be applied to following arguments.
When evaluating an expression first step should be to check
if it is an application of macro function to arguments.  This
may require evaluating first part of an expression to get possible
value from nested macro expansions.  If given expression is
an application of macro function to arguments, and number of
arguments matches we should apply macro, that is substitute
arguments into right hand side of macro definition.  I assume
here that

mac(A,B)(x,y) ==>

really define macro function named 'mac' which after substituting
arguments for A and B gives new anonymous macro function which
can be applied to two arguments.

Now, what shall we do if number of arguments do not match.
AFAICS currently we signal error so we probably should do
so.  Related thing is what to do when we want to evaluate
something, but we get just a macro function, it seems that
we should also signal error in such a case.  Do this match
what you would like to use?

Now, considering possible uses, current Spad compiler assumes
that it can use almost as-is types appearing in 'with' part,
which means that we need to expand types.  This is not a
trouble for regular compilation, but needs changes to
algebra bootstrap.  This does not look very hard, but
I need to think how to do this without future maintanence
troubles.

-- 
                              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 visit 
https://groups.google.com/d/msgid/fricas-devel/aUibWRiW68j0SdbN%40fricas.org.

Reply via email to