Skip to content

Instantly share code, notes, and snippets.

@samth
Created October 30, 2011 17:47
Show Gist options
  • Save samth/1326178 to your computer and use it in GitHub Desktop.
Save samth/1326178 to your computer and use it in GitHub Desktop.
Common Lisp's #. in Racket
#lang racket
#reader"read-eval.rkt"
(begin
#.(begin (define x 30) '(void))
'(1 2 #.x))
#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