# Error 'unbound identifier' while read-syntax on expand phase

**URL:** <https://racket.discourse.group/t/error-unbound-identifier-while-read-syntax-on-expand-phase/1582>\
**Category:** Questions & Answers\
**Tags:** macro, reader, syntax\
**Created:** [December 27, 2022, 11:04pm UTC](https://racket.discourse.group/t/error-unbound-identifier-while-read-syntax-on-expand-phase/1582 "2022-12-27T23:04:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![corpix](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/corpix/32/925_2.png) [@corpix](https://racket.discourse.group/u/corpix)\
**Post date:** [December 27, 2022, 11:04pm UTC](https://racket.discourse.group/t/error-unbound-identifier-while-read-syntax-on-expand-phase/1582/1 "2022-12-27T23:04:46Z")

</div>

Hi! I have a problem which I could not wrap my head around...

There is an error 'unbound identifier' in transform stage when I try to load some configuration with 'read-syntax'. This works at runtime stage.

What I try to do is get the syntax object for the symbols in the file, I need it to use srcloc (I am writing a small DSL for running tasks).  
Here is a minimal code which shows the problem [sample-loader.rkt · GitHub](https://gist.github.com/corpix/e8756eea24f49bde850b95b15588b87e)

> sample-loader.rkt

```scheme
#lang racket
(require (for-syntax racket))

(define-syntax (sample stx)
  (syntax-case stx (file)
    ((_ (file path))
     (let ((file (syntax->datum #'path)))
       (call-with-input-string
        (file->string file)
        (lambda (port) (read-syntax file port)))))))

(sample (file "./sample.rkt"))

; ./sample.rkt::2: say-hello: unbound identifier;
; also, no #%app syntax transformer is bound
; at: say-hello
; in: (say-hello)
; Source locations:
; ./sample.rkt:1:0

```

> sample.rkt

```scheme
(say-hello)

```

The question is: how this could be fixed?  
Thank you.

---

<div class="post-metadata">

**Author:** ![corpix](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/corpix/32/925_2.png) [@corpix](https://racket.discourse.group/u/corpix)\
**Post date:** [December 27, 2022, 11:16pm UTC](https://racket.discourse.group/t/error-unbound-identifier-while-read-syntax-on-expand-phase/1582/2 "2022-12-27T23:16:21Z")

</div>

Whoopsie.  
I have rewrite my sample... looks like as my mistake.  
This error is still reproducible for me in my personal project, but not in this sample:

```scheme
#lang racket
(require (for-syntax racket))

(define-syntax (sample-quote stx)
  (syntax-case stx ()
    ((_ xs ...) (syntax '(xs ...)))))

(define-syntax (sample stx)
  (syntax-case stx (file)
    ((_ (file path))
     (with-syntax ((expression (let ((file (syntax->datum #'path)))
                                 (call-with-input-string
                                  (file->string file)
                                  (lambda (port) (read-syntax file port))))))
       (syntax (sample-quote expression))))))

(sample (file "./sample.rkt"))

; '((say-hello)) 

```

So, I think it solved.
