Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to locally change reading rules in racket?

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?

like image 688
Raoul Avatar asked Jan 19 '26 17:01

Raoul


1 Answers

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

like image 116
John Clements Avatar answered Jan 21 '26 09:01

John Clements



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!