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

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Tue Aug 30 06:42:56 EDT 2011

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.