
is there a good way to do cross-phase communication between macros and runtime, but where the macro phase is happening dynamically during the runtime phase? That is, I’m eval’ing some code, and I’d like to redefine a macro in the code I’m evaling based on my current runtime state

actually I may be able to do without, but i’m still curious

@thinkmoore in general, cross-phase communication is prohibited. There are some work arounds (like message passing through the logging system, or the file system) but the aren’t great, and its probably better to do without if you can. You also might be able to use a #:cross-phase-persistent module, but those are extremely prohibitive as to what their contents may be.
if you only need to communicate one way (eval to what its evaluating) and know what language what youre evaluating is in, maybe you could inject some code into the code-to-be-evaled that describes the current state? Or maybe the macro could expand into runtime code that looks at the current runtime state?

@notjack: Neat! Will have a look later today.

@notjack did you think about using Scribble for the post?

@ben I considered it but I wanted to get something simple working first so I wouldn’t be distracted from writing a draft

ok, makes sense

I was about to reply on GH with “you should link to the docs http://docs.racket-lang.org/reference/syntax-model.html#%28part._expand-steps%29”

and then I thought, links like that would be much easier in scribble

They’re easier but it’s still pretty easy in markdown too :)

(if you want an example, Asumu has wrote some scribble posts for the neu-prl blog https://github.com/nuprl/website/blob/master/blog/_src/posts/2016-06-27-tutorial-using-racket-s-ffi.scrbl)

meh, fair enough

@thinkmoore Something that I have seen working is communicating via 3D syntax. As long as your values do not involve structs, it should work, but can break in quite a few ways (structs seem to not always be the same, even if they are effectively of the same phase, e.g. communicate phase 1 → 0 → 1 might not give the “obvious” struct type). I also had some exported variable is not defined
and link: namespace mismatch
errors when that sort of code is required at a different meta-level. #lang racket
(require racket/stxparam) ;; Provides syntax-parameter-value at phase 1
(eval #'(begin (define-syntax (extract stx)
#`'#,syntax-parameter-value)
(extract)))
A different solution is phase1-eval
from syntax/macro-testing
, which takes a different (cleaner) approach.

@notjack: Love it. I was expecting just a package showcase, but got both a tutorial and a package showcase. :)

Happy to merge once the discusison settles down.

@dnf85 has joined the channel

Is automatic test discovery available in rackunit?

what code are you trying to write?

(if you put your tests in a submodule named test
, then raco test
will run all the tests “automatically”, but I’m not sure that’s what you want)

@ben thanks, that’s what I needed. I didn’t know about the raco test
command. :slightly_smiling_face: