thinkmoore
2017-2-7 14:55:13

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


thinkmoore
2017-2-7 14:56:21

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


florence
2017-2-7 16:02:48

@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?


stamourv
2017-2-7 16:25:19

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


ben
2017-2-7 18:07:54

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


notjack
2017-2-7 18:08:52

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


ben
2017-2-7 18:09:18

ok, makes sense


ben
2017-2-7 18:09:32

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


ben
2017-2-7 18:09:47

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


notjack
2017-2-7 18:10:17

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


ben
2017-2-7 18:10:20

(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)


ben
2017-2-7 18:10:44

meh, fair enough


georges-duperon
2017-2-7 19:19:28

@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.


stamourv
2017-2-7 20:12:23

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


stamourv
2017-2-7 20:12:32

Happy to merge once the discusison settles down.


dnf85
2017-2-7 20:59:34

@dnf85 has joined the channel


pocmatos
2017-2-8 06:49:54

Is automatic test discovery available in rackunit?


ben
2017-2-8 06:53:33

what code are you trying to write?


ben
2017-2-8 06:54:08

(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)


pocmatos
2017-2-8 07:17:02

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