chambln has left #racket ["ERC (IRC client for Emacs 26.3)"]
dmiles has joined #racket
wingsorc has quit [Ping timeout: 248 seconds]
badkins has quit [Remote host closed the connection]
endformationage has joined #racket
ziyourenxiang has quit [Ping timeout: 258 seconds]
<endobson>
If I have a macro m, that is called like (m foo-id) where foo-id is bound at phase 1 to an sexpression. m is meant to take that sexpression, and use it to generate its output syntax
<endobson>
What is the easiest way of doing this?
<endobson>
I currently have m generating code that looks like (begin (define-syntax (go stx) ...) (go))
<endobson>
and having the body of go uses the foo-id
<endobson>
but it feels that is very convoluted
<endobson>
I feel like eval with the right namespace or something like syntax-local-value would make this a lot simpler
Trieste has quit [Ping timeout: 258 seconds]
Trieste has joined #racket
<lexi-lambda>
endobson: Yeah, normally you do something like that by binding foo-id as a transformer binding at phase 0 and using syntax-local-value. But depending on what you’re doing there might be a better way. Maybe consider looking at syntax-local-eval.
<endobson>
lexi-lambda: Yes that is exactly the function I was looking for
<lexi-lambda>
syntax-local-eval is significantly safer than true unrestricted eval. It uses internal definition contexts under the hood.
<endobson>
lexi-lambda: eval is totally safe, just don't look at it funny
<endobson>
my most recent annoyance with it is that (begin (module ...)) is different than (module ...)
<lexi-lambda>
Well, I suppose it is safe if you set the context up properly. :) But that’s hard to get right, and syntax-local-eval essentially takes a code path that ensures it’s set up properly!
<endobson>
oh yes for this case
ArthurStrong has joined #racket
<lexi-lambda>
endobson: What’s different about (begin (module ...))?
<endobson>
If top-level-form is a pair whose car is a symbol or identifier, and if applying namespace-syntax-introduce to the (datum->syntax-converted) identifier produces an identifier bound to module in a phase level that corresponds to namespace’s base phase, then only that identifier is enriched.
pticochon has quit [Ping timeout: 265 seconds]
<endobson>
So just a very weird edge case
badkins has joined #racket
brettgilio has joined #racket
badkins has quit [Ping timeout: 258 seconds]
<lexi-lambda>
endobson: Ah, that is inconvenient, isn’t it? I guess it makes some sense, though.
ArthurStrong has left #racket [#racket]
<lexi-lambda>
I guess you could add another special case for begin that does the same thing while recursively flattening begins.
<endobson>
Really it is that the top level is hopeless
<lexi-lambda>
Indeed.
cantstanya has quit [Ping timeout: 240 seconds]
cantstanya has joined #racket
badkins has joined #racket
badkins has quit [Ping timeout: 240 seconds]
lorikeet has quit [Quit: Connection closed for inactivity]
badkins has joined #racket
orivej has joined #racket
brettgilio has quit [Ping timeout: 260 seconds]
orivej has quit [Ping timeout: 265 seconds]
[ouo] has quit [Read error: Connection reset by peer]
badkins has quit [Remote host closed the connection]