Macro optimisation in Racket

hello,

i need to optimise some scheme code i wrote.
I can do that by "inlining macro expansion" and in other case by doing both and substituing procedure symbolic result instead of re-calculus all the numeric values at each step of loop for example.

About macros my question with Racket is :
if a macro is expanding to a result, is it done before computation only one time in the code execution ,at beginning, or is it done each time (for example in a loop) the macro call is encountered?

it changes a lot, if it is done first, i have no need of optimise that, execept for macro that call a procedure that can be symbolically optimise! that another case too...

example of the general case:

{x <+ 7}

is expanded by SRFI 105 reader as:

(<+ x 7)

this is done before execution by Raket SRFI-105 curly infix reader

now

the above expression is expanded as:

(define x 7)

by evaluation of <+ macro but if (<+ x 7) is in a loop is it expanded at each iteration of the loop or as it been done definitively at start of the program?

note : for <+ this is a simple case but i have case more complex (macro evaluating to procedure calls)

Macro expansion happens at compile time.

See the big picture section:
https://soegaard.github.io/mythical-macros/#1.3

4 Likes

thanks. great explanation. it is what i was thinking but i had doubt.
and furthermore i find interesting API Racket function to reuse on your page.

i will skip time doing what is automatically done by racket as optimisation and focus on the infix precedence optimisation in my Scheme+ code that are done at runtime and should be done symbolically at first time because the calculus does not change in a loop ,only numerical values changes.