Created
October 30, 2011 17:47
-
-
Save samth/1326178 to your computer and use it in GitHub Desktop.
Common Lisp's #. in Racket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
#reader"read-eval.rkt" | |
(begin | |
#.(begin (define x 30) '(void)) | |
'(1 2 #.x)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require (prefix-in r: racket)) | |
(define ns (make-base-namespace)) | |
(define (make-rt) | |
(make-readtable (current-readtable) | |
#\. | |
'dispatch-macro | |
(λ (ch in . args) | |
(define expr (r:read in)) | |
(define r (eval expr ns)) | |
r))) | |
(define (read . args) | |
(parameterize ([current-readtable (make-rt)]) | |
(apply r:read args))) | |
(define (read-syntax a b . args) | |
(parameterize ([current-readtable (make-rt)]) | |
(r:read-syntax a b))) | |
;(read (open-input-string "(1 2 #.(+ 10 20))")) ;; produces '(1 2 30) | |
(provide read read-syntax make-rt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment