Can the thing coming out of the read-syntax be an expression? If so, what lexical context should it have?
Robby On Tue, Aug 30, 2011 at 1:00 PM, Carl Eastlund <c...@ccs.neu.edu> wrote: > Oops. It's not NAME that's the problem. It's #,my-read-stx that > needs to change to (quote #,my-read-stx) instead. > > Carl Eastlund > > On Tue, Aug 30, 2011 at 1:41 PM, Carl Eastlund <c...@ccs.neu.edu> wrote: >> Just put an explicit "quote" form around it. Replace NAME with (quote >> NAME) in the template. >> >> Right now there is no form to tell the expander how to expand NAME. >> So the expander looks at the lexical context to see "how do I expand >> this form". But NAME did not come from a lexical context, so it has >> none. You don't really want to give it some, either -- it's not a >> program, it's data. Wrapping it with quote tells the expander what it >> needs to know via the context on the identifier "quote", and NAME can >> thus stay as data without lexical context. >> >> Carl Eastlund >> >> On Tue, Aug 30, 2011 at 6:42 AM, Neil Van Dyke <n...@neilvandyke.org> wrote: >>> I'm getting this error in some code with a macro transformer that produces >>> syntax that includes some bits of child syntax that are sourced via >>> "read-syntax". >>> >>> The below example demonstrates. >>> >>> Assuming that I really do want to use "read-syntax", how do I do this >>> properly? (I assume that proper is not losing the "#%datum" by something >>> like "(quasisyntax/loc stx #,(syntax->datum stx))".) >>> >>> >>> #lang racket/base >>> >>> (require (for-syntax racket/base) ;; necessary >>> (for-template racket/base) ;; doesn't help #%datum problem >>> (for-label racket/base) ;; doesn't help #%datum problem >>> ) >>> >>> (define-syntax (my-macro stx) >>> (syntax-case stx () >>> ((_ NAME) (let ((my-read-stx (read-syntax "my-sourcename" >>> (open-input-string >>> "\"hello\"")))) >>> (quasisyntax/loc stx >>> (string-append "Well, " #,my-read-stx ", " NAME "!")))))) >>> >>> (my-macro "yourname") >>> ;;=exception=> compile: bad syntax; literal data is not allowed, because no >>> #%datum syntax transformer is bound in: "hello" >>> >>> >>> -- >>> http://www.neilvandyke.org/ > > _________________________________________________ > For list-related administrative tasks: > http://lists.racket-lang.org/listinfo/users > _________________________________________________ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users