[racket] any remarks

From: Roelof Wobben (r.wobben at home.nl)
Date: Thu Apr 19 16:21:51 EDT 2012

Op 19-4-2012 22:08, namekuseijin schreef:
> On Thu, Apr 19, 2012 at 11:04 AM, Roelof Wobben <r.wobben at home.nl 
> <mailto:r.wobben at home.nl>> wrote:
> > (define (edit e k)
> >  (cond
> >     [  (and(key=? "right" k) (> (string-length (editor-post e)) 0))
> > (make-editor(string-append (editor-pre e) (string-first (editor-post 
> e) ))
> > (string-rest (editor-post e) ))]
> >     [  (and(key=? "left" k) (> (string-length (editor-pre e)) 0))
> > (make-editor ( string-remove-last (editor-pre e) ) (string-append
> > (string-last(editor-pre e))  (editor-post e)))]
> >     [  (and (key=? "\b" k) (> (string-length (editor-pre e)) 0))
> > (make-editor (string-remove-last (editor-pre e)) (editor-post e))]
> >     [  (and  (key=? "\b" k) (equal? (string-length  (editor-pre e)) 
> 0)) e]
> >     [  ( or (key=? "\t" k) (key=? "\u007F" k)) e]
> >     [  ( > (string-length k) 1) e ]
> >     [else (make-editor (string-append (editor-pre e) k) (editor-post 
> e))]
> >     ))
>
> I'd rewrite that as:
>
> (define (edit e k)
>  (let ([pre (editor-pre e)]
>        [post (editor-post e)]
>        [size string-length]
>        [s+   string-append])
>    (cond
>      [(and (key=? "right" k) (> (size post) 0)) (make-editor (s+ pre 
> (string-first post)) (string-rest post))]
>      [(and (key=? "left" k)  (> (size pre)  0)) (make-editor 
> (string-remove-last pre) (s+ (string-last pre)  post))]
>      [(and (key=? "\b" k)    (> (size pre)  0)) (make-editor 
> (string-remove-last pre) post)]
>      [(and (key=? "\b" k)    (= (size pre)  0)) e]
>      [(or  (key=? "\t" k) (key=? "\u007F" k))   e]
>      [(> (size k) 1)                            e]
>      [else                                      (make-editor (s+ pre 
> k) post)])))
>


Thanks,

I see how it works but the htdp2e book let is in a later chapter then I 
study now.

Roelof

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120419/21ea6494/attachment.html>

Posted on the users mailing list.