define read-until-next-curl port clumsy way to read up until the first

 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
(define (read-until-next-curly port)
"clumsy way to read up until the first }."
(read-token (lambda (c) (not (char=? c #\}))) port))
(define (replace-underscore exprlist)
(define (replace-underscore-item y)
(if (equal? y '_) 'x y))
(map replace-underscore-item exprlist))
(define (make-lambda-form exprlist)
`(lambda (x) (,@exprlist)))
(define (eval-string s)
(with-input-from-string s read))
(define (transform-into-lambda s)
(let* ((expr (eval-string s))
(expr2 (replace-underscore expr)))
(make-lambda-form expr2)))
(set-read-syntax! #\{
(lambda (port)
(let* ((s (read-until-next-curly port))
(t (string-append "(" s ")")))
(read-byte port) ; read trailing '}'
(transform-into-lambda t))))