[racket] bad syntax; literal data is not allowed, because no #%datum syntax transformer is bound

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Tue Aug 30 14:24:24 EDT 2011

It could be, if that's what you intended.  I guess I just assumed it
was raw data.  You could give it any lexical context you like.  See
for instance the racket/include bindings for include and
include-at/relative-to, which behave very much like Neil's program.
The former uses the context of the include form, while the latter
takes an extra argument to determine the context.  These forms are
both implemented by a "do-include" macro, which has a loop where it
reconstructs the entire syntax object to preserve the source locations
of each piece, while applying the lexical context everywhere.

Carl Eastlund

On Tue, Aug 30, 2011 at 2:10 PM, Robby Findler
<robby at eecs.northwestern.edu> wrote:
> 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 <cce at 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 <cce at 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 <neil at 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/



Posted on the users mailing list.