<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Op 6-4-2012 15:23, Stephen Bloch schreef:
<blockquote
cite="mid:E969CA67-B5C3-4783-AC35-3650A6DB035B@adelphi.edu"
type="cite"><br>
<div>
<div>On Apr 6, 2012, at 3:39 AM, Roelof Wobben wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<div bgcolor="#FFFFFF" text="#000000">
<table class="RktBlk" style="position: static; z-index:
auto; " cellspacing="0">
<tbody>
<tr>
<td><span class="RktCmt">;</span><span class="RktCmt"> </span><span
class="RktCmt">interp. </span><span class="RktPn">(</span><span
class="RktSym">make-editor</span><span class="stt">
</span><span class="RktSym">s</span><span
class="stt"> </span><span class="RktSym">t</span><span
class="RktPn">)</span><span class="RktCmt"> means
the text in the editor is</span></td>
</tr>
<tr>
<td><span class="RktCmt">;</span><span class="RktCmt"> </span><span
class="RktPn">(</span><span class="RktSym"><a
moz-do-not-send="true"
href="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"
class="RktValLink" pltdoc="x">string-append</a></span><span
class="stt"> </span><span class="RktSym">s</span><span
class="stt"> </span><span class="RktSym">t</span><span
class="RktPn">)</span><span class="RktCmt"> with
the cursor displayed between </span><span
class="RktSym">s</span><span class="RktCmt"> and </span><span
class="RktSym">t</span></td>
</tr>
</tbody>
</table>
<br>
<br>
So for aaaaaaa| s has the value of aaaaa en t has the value
of ""<br>
</div>
</blockquote>
<div><br>
</div>
No, s should be "aaaaaaa" and t should be "".</div>
<div><br>
</div>
<div>
<blockquote type="cite">
<div bgcolor="#FFFFFF" text="#000000"> For aaaa|aaaa s I
think s has the value of aaaaa and t has the value of aaa<br>
</div>
</blockquote>
<div><br>
</div>
No, s should be "aaaa" and t should be "aaaa". The cursor is
supposed to be displayed between s and t.</div>
<div><br>
<blockquote type="cite">
<div bgcolor="#FFFFFF" text="#000000">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.<br>
</div>
</blockquote>
<div><br>
</div>
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.</div>
<div><br>
<blockquote type="cite">
<div bgcolor="#FFFFFF" text="#000000"> 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.</div>
</blockquote>
<div><br>
</div>
You could, but that's unnecessarily complicated. string-append
works regardless of whether s or t is empty.</div>
<div><br>
</div>
<br>
<div>
<span class="Apple-style-span" style="border-collapse: separate;
color: rgb(0, 0, 0); font-family: Helvetica; font-size:
medium; font-style: normal; font-variant: normal; font-weight:
normal; letter-spacing: normal; line-height: normal; orphans:
2; text-align: auto; text-indent: 0px; text-transform: none;
white-space: normal; widows: 2; word-spacing: 0px;
-webkit-border-horizontal-spacing: 0px;
-webkit-border-vertical-spacing: 0px;
-webkit-text-decorations-in-effect: none;
-webkit-text-size-adjust: auto; -webkit-text-stroke-width:
0px; "><span class="Apple-style-span" style="border-collapse:
separate; color: rgb(0, 0, 0); font-family: Helvetica;
font-size: medium; font-style: normal; font-variant: normal;
font-weight: normal; letter-spacing: normal; line-height:
normal; orphans: 2; text-indent: 0px; text-transform: none;
white-space: normal; widows: 2; word-spacing: 0px;
-webkit-border-horizontal-spacing: 0px;
-webkit-border-vertical-spacing: 0px;
-webkit-text-decorations-in-effect: none;
-webkit-text-size-adjust: auto; -webkit-text-stroke-width:
0px; ">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space;
-webkit-line-break: after-white-space; ">
<div>Stephen Bloch</div>
<div><a moz-do-not-send="true"
href="mailto:sbloch@adelphi.edu">sbloch@adelphi.edu</a></div>
</div>
</span></span>
</div>
<br>
</blockquote>
<br>
Hello, <br>
<br>
I have finally written the render function.<br>
It's looks like this :<br>
<br>
(define workspace (empty-scene 200 20))<br>
<br>
(define-struct editor (pre post))<br>
; Editor = (make-editor String String)<br>
; interp. (make-editor s t) means the text in the editor is<br>
; (string-append s t) with the cursor displayed between s and t<br>
; make-editor String String -> Editor<br>
; editor-pre Editor -> String <br>
; editor-post Editor -> String<br>
; editor? Editor Any -> Boolean <br>
<br>
; make-struct<br>
(define verwerker (make-editor "aaa" "bbbb"))<br>
<br>
<br>
;; Image -> Number <br>
;; Function to calculate the width of the editor-pre image<br>
(check-expect (width (make-editor "aaa" "")) 18)<br>
(check-expect (width (make-editor "" "")) 0) <br>
(define (width editor)<br>
(image-width (text (editor-pre verwerker) 11 "black")))<br>
<br>
; Editor -> Image<br>
; Function which displays the struct on the screen into a image.<br>
(check-expect (render verwerker) (place-image<br>
(text "aaa" 11 "black")<br>
14 10<br>
(place-image (rectangle 2 20 "solid" "red") (+ (width editor)8)
10<br>
(place-image<br>
(text "bbbb" 11 "black")<br>
(+ (width editor) 22) 10<br>
workspace))))<br>
(check-expect (render (make-editor "" "bbbb")) (place-image<br>
(text "" 11 "black")<br>
14 10<br>
(place-image (rectangle 2 20 "solid" "red") (+ (width editor)8)
10<br>
(place-image<br>
(text "bbbb" 11 "black")<br>
(+ (width editor) 22) 10<br>
workspace))))<br>
(check-expect (render (make-editor "aaa" "")) (place-image<br>
(text "aaa" 11 "black")<br>
14 10<br>
(place-image (rectangle 2 20 "solid" "red") (+ (width editor)8)
10<br>
(place-image<br>
(text "" 11 "black")<br>
(+ (width editor) 22) 10<br>
workspace))))<br>
(define (render verwerker)<br>
(place-image<br>
(text (editor-pre verwerker) 11 "black")<br>
14 10<br>
(place-image (rectangle 2 20 "solid" "red") (+ (width editor)8)
10<br>
(place-image<br>
(text (editor-post verwerker) 11 "black")<br>
(+ (width editor) 22) 10<br>
workspace))))<br>
<br>
But I see something strange, Both check-expect of the function width
gives as output 18.<br>
But I expect that on a empty (editor-pre verwerker) gives as output
0.<br>
<br>
Am I mistaken or is there something wrong in my functions ?<br>
<br>
Roelof<br>
<br>
</body>
</html>