Hi,<br><br><div class="gmail_quote">2013/4/29 Tomás Coiro <span dir="ltr"><<a href="mailto:tomcoiro@hotmail.com" target="_blank">tomcoiro@hotmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div dir="ltr">I'm trying to wrap my head around them and be able to use them.<br>I'm trying to write something for a Clojure compability layer in Github and i just find it impossible to use the make-readtable procedure to start doing something.<br>
<br><br>Can someone show me the code to make this #"hello" expand to (regexp "hello") ?<br></div></div></blockquote><div><br></div><div>Here is one way to read #"hello" as (regexp "hello").</div>
<div><br></div><div>#lang racket</div><div><br></div><div>(define (read-until port ch)</div><div> (list->string</div><div> (for/list ([c (in-port read-char port)]</div><div> #:break (eqv? c ch))</div><div>
c)))</div><div><br></div><div>;; A syntax object that has the "original?" property:</div><div>(define orig-stx (read-syntax #f (open-input-string "dummy")))</div><div><br></div><div>(define (lex# default-rt)</div>
<div> (case-lambda</div><div> [(ch port) ((lex# default-rt) ch port #f #f #f #f)]</div><div> [(ch port src line col pos)</div><div> (match (peek-char port)</div><div> [#\" (read-char port)</div><div>
(define str (read-until port #\"))</div><div> (define len (+ (string-length str) 3)) ; #"" is 3 characters</div><div> (define srcloc (vector src line col pos len))</div>
<div> (datum->syntax #f (regexp str) srcloc orig-stx)]</div><div> [else </div><div> (read-syntax/recursive src port #\# default-rt)])]))</div><div><br></div><div>(define (extend-readtable rt)</div>
<div> (make-readtable rt #\# 'terminating-macro (lex# rt)))</div><div><br></div><div>(parameterize </div><div> ([current-readtable (extend-readtable (current-readtable))])</div><div> (read-syntax 'foo (open-input-string "(1 2 #\"foo\" 3 4 #hash() )")))</div>
<div> </div><div>Note that if we modify the readtable entry for # then we need</div><div>to handle all cases beginning with #. In lex# everything by #" is</div><div>handled by the old readtable.</div><div><br></div>
<div>-- </div><div>Jens Axel Søgaard</div><div><br></div></div>