<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">This is what syntax-parameters are for.<br>
<br>
(require racket/stxparam)<br>
(define-syntax-parameter m (lambda (stx) (raise-syntax-error 'm
"dont use this outside deeper")))<br>
<br>
(define-syntax-rule (deeper e)<br>
(syntax-parameterize ([m (lambda (stx) #'1)])<br>
e))<br>
<br>
(deeper (m)) -> 1<br>
<br>
On 10/16/2012 04:18 PM, John Clements wrote:<br>
</div>
<blockquote
cite="mid:2A3809E8-FCF5-4637-A560-43AC004EFC14@brinckerhoff.org"
type="cite">
<pre wrap="">This seems like a straightforward question; apologies if I just haven't dug deep enough to find the answer.
I want to define a macro whose meaning depends on its context. More specifically, I want to define an "outer" macro that gives a particular meaning to the "inner" macro.
I can see how to get the job done in a yucky way, using mutation:
#lang racket
;; I want m's meaning to depend on its context
(define-syntax (m stx)
#`#,(unbox the-box))
(define-syntax (deeper stx)
(syntax-case stx ()
[(_ arg)
;; I want to change the meaning of m, here:
(set-box! the-box 16)
#'arg]))
;; yucky mutation-based way to get the job done
(define-for-syntax the-box (box 13))
(deeper (m 134))
… but it seems like there must be a simple way for the outer binding to say "whatever meaning the inner macro wants it to have".
Don't tell me, it's define-for-inner-syntax/local-expand. I just made that up, so I hope it's wrong :).
John
</pre>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">____________________
Racket Users list:
<a class="moz-txt-link-freetext" href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a>
</pre>
</blockquote>
<br>
</body>
</html>