<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>See Ian's reply:</div><div><br></div><div><div>> (for/fold ((sum 0)) ((c "hello world"))</div><div> (+ sum (char->integer c)))</div><div>1116</div></div><div><br></div><div>Assuming you have a different goal in mind, here is how to convert the example from the Guide into an example that gives you a tiny bit of what you have in mind. </div><div><br></div><div><div>;; string-reader-example.rkt:</div><div><div>#reader "string-reader.rkt" #lang racket </div><div>(first "hello")</div></div><div><br></div><div>;; string-reader.rkt:</div><div>#lang racket </div><div><br></div><div>(provide (rename-out [$-read read]</div><div> [$-read-syntax read-syntax]))</div><div><br></div><div>(define ($-read in)</div><div> (parameterize ([current-readtable (string-readtable)]) </div><div> (read in)))</div><div><br></div><div>(define ($-read-syntax src in)</div><div> (parameterize ([current-readtable (string-readtable)])</div><div> (read-syntax src in)))</div><div><br></div><div>(define read-a-string </div><div> (case-lambda </div><div> [(ch in) `(string->list ,(read in))]</div><div> [(ch in src line col pos)</div><div> ;; an awful way of reading a symbol-like string -- do better here</div><div> (define x (read-syntax src in)) (read-char in)</div><div> ;; convert the string into a literat list of chars (via quote)</div><div> `(quote ,(string->list (symbol->string (syntax-e x))))]))</div><div><br></div><div>(define (string-readtable)</div><div> (make-readtable (current-readtable) #\" 'terminating-macro read-a-string))</div></div><div><br></div><div><br></div><div><br></div><br><div><div>On Mar 3, 2012, at 4:13 AM, Timothy Farland wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hi racket folk, lisp neophyte here (just finished HTDP),</div><div><br></div><div>I would like to use Haskell-style strings in my racket, where a string is defined as either '() or (cons character string), and is read from and displayed by values enclosed by double quotes.</div>
<div><br></div><div>i.e: "string" is understood as '(#\s #\t #\r #\i #\n #\g) and '(#\s #\t #\r #\i #\n #\g) is displayed as "string".</div><div><br></div><div>.. so one could do, for example (car "string") => #\s, or (cdr "string") => "tring" etc.</div>
<div><br></div>I've made altered versions of the basic list processing functions that act differently when given strings or lists, so they achieve this, but at the cost of a lot of runtime checks.<div><br></div><div>For a better approach I suspect one would need to deal with the 'reader,' but looking at the documentation, it seems a bit beyond my current understanding. </div>
<div><br></div><div>Has anyone else seen or built a language extension that achieves this, or could anyone point me to some next-step resources that will bring me up to the level where I can understand the reader documentation? Or is my enterprise here misguided?<br clear="all">
<div><br></div><div>Many thanks</div><div><br></div>-- <br>Tim Farland<br><a href="mailto:e%3Atwfarland@gmail.com" target="_blank">e:twfarland@gmail.com</a><br>
</div>
____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></body></html>