Op 6-4-2012 15:23, Stephen Bloch schreef:
On Apr 6, 2012, at 3:39 AM, Roelof Wobben wrote:
;interp. (make-editorst)means the text in the editor is
;(string-append
<http://docs.racket-lang.org/htdp-langs/beginner.html#%28def._%28lib._htdp-beginner..rkt._lang%29._%28%28lib._lang%2Fhtdp-beginner..rkt%29._string-append%29%29>st)with
the cursor displayed between sand t
So for aaaaaaa| s has the value of aaaaa en t has the value of ""
No, s should be "aaaaaaa" and t should be "".
For aaaa|aaaa s I think s has the value of aaaaa and t has the value
of aaa
No, s should be "aaaa" and t should be "aaaa". The cursor is supposed
to be displayed between s and t.
If I use the length of the first string and I press one time on the
left-key then the new-length could be the old-one - 1. Then I could
use substring to cut that part away.
Sure. Note that you'll need to not only make the new s shorter than
the old s, but also make the new t longer than the old t. And vice
versa when somebody presses on the right-arrow key.
The t part I could say if it's empty substring ( s , (string-lenght
s), 1) and if it's not empty use a string-append.
You could, but that's unnecessarily complicated. string-append works
regardless of whether s or t is empty.
Stephen Bloch
sbl...@adelphi.edu <mailto:sbl...@adelphi.edu>
Hello,
I have finally written the render function.
It's looks like this :
(define workspace (empty-scene 200 20))
(define-struct editor (pre post))
; Editor = (make-editor String String)
; interp. (make-editor s t) means the text in the editor is
; (string-append s t) with the cursor displayed between s and t
; make-editor String String -> Editor
; editor-pre Editor -> String
; editor-post Editor -> String
; editor? Editor Any -> Boolean
; make-struct
(define verwerker (make-editor "aaa" "bbbb"))
;; Image -> Number
;; Function to calculate the width of the editor-pre image
(check-expect (width (make-editor "aaa" "")) 18)
(check-expect (width (make-editor "" "")) 0)
(define (width editor)
(image-width (text (editor-pre verwerker) 11 "black")))
; Editor -> Image
; Function which displays the struct on the screen into a image.
(check-expect (render verwerker) (place-image
(text "aaa" 11 "black")
14 10
(place-image (rectangle 2 20 "solid" "red") (+ (width editor)8) 10
(place-image
(text "bbbb" 11 "black")
(+ (width editor) 22) 10
workspace))))
(check-expect (render (make-editor "" "bbbb")) (place-image
(text "" 11 "black")
14 10
(place-image (rectangle 2 20 "solid" "red") (+ (width editor)8) 10
(place-image
(text "bbbb" 11 "black")
(+ (width editor) 22) 10
workspace))))
(check-expect (render (make-editor "aaa" "")) (place-image
(text "aaa" 11 "black")
14 10
(place-image (rectangle 2 20 "solid" "red") (+ (width editor)8) 10
(place-image
(text "" 11 "black")
(+ (width editor) 22) 10
workspace))))
(define (render verwerker)
(place-image
(text (editor-pre verwerker) 11 "black")
14 10
(place-image (rectangle 2 20 "solid" "red") (+ (width editor)8) 10
(place-image
(text (editor-post verwerker) 11 "black")
(+ (width editor) 22) 10
workspace))))
But I see something strange, Both check-expect of the function width
gives as output 18.
But I expect that on a empty (editor-pre verwerker) gives as output 0.
Am I mistaken or is there something wrong in my functions ?
Roelof
____________________
Racket Users list:
http://lists.racket-lang.org/users