On this page:
5.1.1 Example
Version: 4.2.1

5.1 Quote Literals Used as Expressions

Synopsis: Do not use naked syntactic literals (numbers, strings, etc) as expressions. Instead, put the datum inside of a quote expression.

Macros that consume syntactic literals (eg, literal numbers and literal strings) should avoid the temptation to also use those literals directly as self-evaluating expressions. The meaning of “self-evaluating” data is determined by the binding of #%datum in scope where the literal occurs. That binding of #%datum may not be the standard binding; it might assign other behavior to “self-evaluating” data, or the binding might be absent entirely.

The latter case – an absent #%datum binding, resulting in a no #%datum transformer bound syntax error – is often caused by converting the datum into a syntax object with an empty lexical context, as in the following code:
  (datum->syntax #f num)
Another way this problem can manifest is if the lexical context has a #%datum binding but not in the relevant phase. This is usually due to a forgotten for-template import in an auxiliary module (see Code Generators).

5.1.1 Example

Here is a broken variant of the define-record-type macro from the Static Information example:

  (module records scheme
    (provide define-record-type)
    ; syntax (define-record-type record-type-id field-count-number)
    (define-syntax (define-record-type stx)
      (syntax-case stx ()
        [(define-record-type name field-count)
         #'(begin (define record-type (gensym))
                  (define-syntax name
                    (list ((syntax-local-certifier) #'record-type)
                          ; SHOULD BE (quote field-count)
                          field-count)))])))
  
  (module records-client scheme/base
    (require 'records)
    (define-record-type pair 2))
The 2 in the second module occurs in a context where there is no transformer-phase binding for #%datum.