<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Op 19-4-2012 22:08, namekuseijin schreef:
<blockquote
cite="mid:CAK-u0g7nG2UxXNgZ8LOyAenLaSLPprzA8OUyGkCCh1=bTbpDdw@mail.gmail.com"
type="cite">On Thu, Apr 19, 2012 at 11:04 AM, Roelof Wobben <<a
moz-do-not-send="true" href="mailto:r.wobben@home.nl">r.wobben@home.nl</a>>
wrote:<br>
> (define (edit e k)<br>
> (cond<br>
> [ (and(key=? "right" k) (> (string-length
(editor-post e)) 0))<br>
> (make-editor(string-append (editor-pre e) (string-first
(editor-post e) ))<br>
> (string-rest (editor-post e) ))]<br>
> [ (and(key=? "left" k) (> (string-length (editor-pre
e)) 0))<br>
> (make-editor ( string-remove-last (editor-pre e) )
(string-append<br>
> (string-last(editor-pre e)) (editor-post e)))]<br>
> [ (and (key=? "\b" k) (> (string-length (editor-pre
e)) 0))<br>
> (make-editor (string-remove-last (editor-pre e)) (editor-post
e))]<br>
> [ (and (key=? "\b" k) (equal? (string-length
(editor-pre e)) 0)) e]<br>
> [ ( or (key=? "\t" k) (key=? "\u007F" k)) e]<br>
> [ ( > (string-length k) 1) e ]<br>
> [else (make-editor (string-append (editor-pre e) k)
(editor-post e))]<br>
> ))<br>
<br>
I'd rewrite that as:<br>
<br>
<font class="Apple-style-span" face="'courier new', monospace">(define
(edit e k)<br>
(let ([pre (editor-pre e)]<br>
[post (editor-post e)]<br>
[size string-length]<br>
[s+ string-append])<br>
(cond<br>
[(and (key=? "right" k) (> (size post) 0)) (make-editor
(s+ pre (string-first post)) (string-rest post))]<br>
[(and (key=? "left" k) (> (size pre) 0)) (make-editor
(string-remove-last pre) (s+ (string-last pre) post))]<br>
[(and (key=? "\b" k) (> (size pre) 0)) (make-editor
(string-remove-last pre) post)]<br>
[(and (key=? "\b" k) (= (size pre) 0)) e]<br>
[(or (key=? "\t" k) (key=? "\u007F" k)) e]<br>
[(> (size k) 1) e]<br>
[else (make-editor (s+
pre k) post)])))<br>
</font>
<div><br>
</div>
</blockquote>
<br>
<br>
Thanks, <br>
<br>
I see how it works but the htdp2e book let is in a later chapter
then I study now.<br>
<br>
Roelof<br>
<br>
</body>
</html>