<div>I think the docs are just worded a little bit carefully. From what I can tell, it is the identity function on pairs (and on anything that isn't explicitly listed in the docs, actually).</div><div><br></div><div>But one note: in the common case, it looks like your code will copy all of the strings:<br>
</div><div><br></div><div>> (define x "abc")</div><div>> (substring x 0)</div><div>"abc"</div><div>> (eq? x (substring x 0))</div><div>#f</div><div><br></div><div>I guess these strings are not mutated, so you can probably avoid that in the start = 0 case (something I see the original code does).</div>
<div><br>Robby</div><div><br></div><br>On Monday, June 25, 2012, Danny Yoo wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi everyone,<br>
<br>
Is there a reason to use the function "datum-intern-literal" on a list<br>
structure? According to the documentation, datum-intern-literal does<br>
not traverse compound values, so I'm unsure about its use on list<br>
structures.<br>
<br>
I'm curious because I'm staring at the definition of decode-string in<br>
scribble/decode, and it's trying to apply datum-intern-literal against<br>
a whole list, which seems strange to me:<br>
<br>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br>
(define (decode-string s)<br>
(let loop ([l '((#rx"---" mdash)<br>
(#rx"--" ndash)<br>
(#rx"``" ldquo)<br>
(#rx"''" rdquo)<br>
(#rx"'" rsquo))])<br>
(cond [(null? l) (list s)]<br>
[(regexp-match-positions (caar l) s)<br>
=> (lambda (m)<br>
(datum-intern-literal<br>
(append (decode-string (substring s 0 (caar m)))<br>
(cdar l)<br>
(decode-string (substring s (cdar m))))))]<br>
[else (loop (cdr l))])))<br>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br>
<br>
<br>
I'm looking at this function because the Racket statistical profiler<br>
is telling me that it might be helpful to optimize it. I had expected<br>
something more along the lines of:<br>
<br>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br>
(define (decode-string s)<br>
(define pattern #rx"(---|--|``|''|')")<br>
(let loop ([start 0])<br>
(cond<br>
[(regexp-match-positions pattern s start)<br>
=> (lambda (m)<br>
(define the-match (substring s (caar m) (cdar m)))<br>
(list* (substring s start (caar m))<br>
(cond<br>
[(string=? the-match "---") 'mdash]<br>
[(string=? the-match "--") 'ndash]<br>
[(string=? the-match "``") 'ldquo]<br>
[(string=? the-match "''") 'rdquo]<br>
[(string=? the-match "'") 'rsquo])<br>
(loop (cdar m))))]<br>
[else<br>
(list (substring s start))])))<br>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br>
<br>
but I'm not sure about the role of the datum-intern-literal stuff with<br>
regards to lists.<br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</blockquote>