nex3 / arc

Paul Graham's Brand New Lisp

This URL has Read+Write access

pg and rtm <> (author)
Sat Jul 04 16:42:33 -0700 2009
rntz (committer)
Sat Jul 04 16:42:33 -0700 2009
commit  aaccf343eb29e3de884c980b26e02f5460c759a8
tree    b8988387154bb24dd743f10888e2351052520375
parent  fa2d724d960eb51c10d1653921c0ae72a580789f
arc / brackets.scm
100644 49 lines (32 sloc) 1.252 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
; From Eli Barzilay, eli@barzilay.org
 
;> (require "brackets.scm")
;> (use-bracket-readtable)
;> ([+ _ 1] 10)
;11
 
(module brackets mzscheme
  
; main reader function for []s
; recursive read starts with default readtable's [ parser,
; but nested reads still use the curent readtable:
 
(define (read-square-brackets ch port src line col pos)
  `(fn (_)
     ,(read/recursive port #\[ #f)))
  
; a readtable that is just like the builtin except for []s
 
(define bracket-readtable
  (make-readtable #f #\[ 'terminating-macro read-square-brackets))
  
; call this to set the global readtable
 
(provide use-bracket-readtable)
 
(define (use-bracket-readtable)
  (current-readtable bracket-readtable))
  
; these two implement the required functionality for #reader
    
;(define (*read inp)
; (parameterize ((current-readtable bracket-readtable))
; (read inp)))
 
(define (*read . args)
  (parameterize ((current-readtable bracket-readtable))
    (read (if (null? args) (current-input-port) (car args)))))
 
(define (*read-syntax src port)
  (parameterize ((current-readtable bracket-readtable))
    (read-syntax src port)))
 
; and the need to be provided as `read' and `read-syntax'
 
(provide (rename *read read) (rename *read-syntax read-syntax))
 
)