Reputation: 1902
I am looking into embedding J in Racket, and since I found an existing project, I'd like to build upon that. As it is now, evaluation happens by passing a J program string to a Racket form:
> (j "4 * 1 + 4")
> 20
Since J makes use of quotes, double quotes, and other ASCII characters that require escaping when passed as a string, I would like to change the evaluation strategy to:
> (j 4 * 1 + 4)
> 20
which corresponds to evaluating the cdr
of the Racket form, and apparently would require to locally change the reader. However, when I try to change the evaluation function to something like:
(define (j exp)
(jeval #reader"jexp.rkt" exp))
I get an "unbound identifier" error, since the input-port ' exp' is interpreted litterally without substituting 'exp' for its value. How can I manage that?
Upvotes: 3
Views: 105
Reputation: 17233
Altering the reader like this is not something that can be done late in the parsing process. In the example you give, how is Racket supposed to know when the embedded J program ends?
I think you want to take a look at the "Creating a Language" portion of the Racket Guide:
https://docs.racket-lang.org/guide/languages.html
Upvotes: 1