[plt-scheme] creating new readers

From: Jon Rafkind (workmin at ccs.neu.edu)
Date: Sat Oct 25 20:45:04 EDT 2008

I am trying to understand how to write a new reader that can be used 
with #lang.

I have an empty x.ss with
#lang foo

and foo/lang/reader.ss with

--snip--
#lang scheme

(provide (rename-out (my-read read)
                     (my-read-syntax read-syntax)))

(define (my-read port)
  (syntax->datum (my-read-syntax #f port)))

(define (my-read-syntax name port)
  (let* ((p-name (object-name port))
         (name (if (path? p-name)
                 (let-values (((base name dir?) (split-path p-name)))
                   (string->symbol (path->string (path-replace-suffix 
name #""))))
                 'page)))
    #`(module #,name scheme #,(foo))))

(define (foo)
  #'(begin
      (define q 1)
      (+ q 2)))
--end snip--

But when I run x.ss I get
lang/reader.ss:20:9: compile: unbound identifier in module in: q

I'm not sure what category of things to look into.. syntax marks, 
certificates, module-begin?


Posted on the users mailing list.