Hi all,

I’ve been putting together a little language to learn more about how the Racket 
#lang ecosystem works, and I’m hung up on bundling up the language as a 
collection. I’m not sure I correctly understand the point where the reader 
attaches to the macros that specify how to expand the language forms, and I 
want to check.

So, say I have a file semantics.rkt (in mylang/, the main dir of the 
collection) defining the macros that make up the language, and a reader 
lang/reader.rkt (in the same dir):
#lang s-exp syntax/module-reader
"../semantics.rkt"
#:read my-read
#:read-syntax my-read-syntax

(require "lang/parser.rkt" syntax/strip-context)
;; ...simple defs of my-read and my-read-syntax...

This much works. My question is how to attach the semantics.rkt file to my 
reader code correctly if I don’t use syntax/module-reader. If that’s not clear 
enough, a more detailed description of the problem follows.

Following the “Installing a Language 
<file:///Applications/Racket%20v6.10/doc/guide/language-collection.html>” 
section in the Racket Guide, I moved this reader code into a main.rkt file in 
the main dir of the collection (call it mylang/):
(module reader racket
  (require "lang/parser.rkt" syntax/strip-context)
 
  (provide (rename-out [my-read read]
                       [my-read-syntax read-syntax]))
 
  (define (my-read in) (syntax->datum (my-read-syntax #f in)))

  (define (my-read-syntax src in)
    (with-syntax ([(program-part ...) (parse-program-file src in)])
      (strip-context
       #'(module IGNORE "semantics.rkt"
           program-part ...)))))

I can then write
        #lang mylang
in another file, and it works as expected iff the file I’m loading is in the 
mylang/ directory as well, failing otherwise with an error like this:
/path/to/mylang/main.rkt:17:24: cannot open module file
  module path: #<path:/tmp/semantics.rkt>
  path: /tmp/semantics.rkt

The module language spec I’ve highlighted in red seems brittle; because 
Racket’s looking for semantics.rkt in the directory of the file containing 
#lang mylang and not mylang/, I’ve been assuming that’s where the problem is. 
Correct me if I’m wrong in this understanding: the #'(module ...) is 
effectively replacing the body of whatever program is written in #lang mylang, 
so the path-string "semantics.rkt" must be interpreted relative to that 
program’s source file.

Anyway, the solution I found is to replace "semantics.rkt" with 
mylang/semantics, but that seems like it might be brittle as well; is that the 
right way, though? If not, how should I be specifying the connection to the 
macros?

Thanks,
Jordan

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to