0

I have created a module which provides various functions, including #%module-begin. I want to use it with at-exp syntax, which I can do using the following #lang line:

#lang at-exp s-exp "my-library.rkt"

However, this does not read unknown symbols as strings, as would happen for example when using the scribble/text language. How can I provide this functionality from my library, to save me writing quote marks around all my strings?

I think it may have something to do with the #%top function. Perhaps I can require it somehow from scribble/text and then provide it from my library?

Richard Parsons
  • 277
  • 1
  • 9
  • 1
    Your question is a little ambiguous: as asked, it would imply that you want unbound identifiers to be replaced with strings, but given you’ve mentioned `scribble/text`, it sounds like what you *actually* want is to start the at-reader in text mode, using the behavior of [`read-inside` and `read-syntax-inside`](http://docs.racket-lang.org/scribble/reader-internals.html#%28def._%28%28lib._scribble%2Freader..rkt%29._read-syntax-inside%29%29). Is that accurate? – Alexis King Jan 23 '16 at 03:27
  • I'm ignorant as to what the difference is. My goal is to turn unquoted symbols into strings so that I don't have to quote them when writing. Does starting the at-reader in text mode do more than that? For example, I don't want it to display the rendered text when run, which is something that I see that scribble/text does. Edit: When I say quoted, I mean "like this", not 'like 'this. – Richard Parsons Jan 23 '16 at 08:50
  • The `scribble/text` language does print it out, but only in the same way that `#lang racket/base "hello"` prints out `"hello"`. But that's `#%module-begin`'s job to handle that. If you don't want that to happen, you should provide a `#%module-begin` to make sure that `(#%module-begin "hello")` doesn't print out `"hello"`. – Alex Knauth Jan 23 '16 at 15:49
  • Thanks Alex - it's so obvious now! – Richard Parsons Jan 23 '16 at 19:00

1 Answers1

2

What scribble/text does, is it starts reading the file in "text" mode, whereas at-exp starts reading the file in "racket" mode. Messing with #%top is not what you want here. To do the same thing as scribble/text, you would need a version of at-exp that starts in text mode. That doesn't exist (yet) though.

The function read-syntax-inside from scribble/reader does this. However, you will have to define your own #lang language that uses it. For that, you might find this documentation helpful, but there's no quick answer.

Update:

I looked at the implementation of scribble/text, and the answer seems a lot quicker than I thought it would be. Something like this should work:

my-library/lang/reader.rkt:

#lang s-exp syntax/module-reader

my-library/main

#:read        scribble:read-inside
#:read-syntax scribble:read-syntax-inside
#:whole-body-readers? #t
#:info        (scribble-base-reader-info)

(require (prefix-in scribble: scribble/reader)
         (only-in scribble/base/reader scribble-base-reader-info))

Testing it:

#lang my-library
This is text
@(list 'but 'this 'is 'not)

I tested this with my-library/main.rkt re-providing everything from racket/base.

Alex Knauth
  • 8,133
  • 2
  • 16
  • 31