[racket] struct change question.

From: Roelof Wobben (r.wobben at home.nl)
Date: Sat Apr 14 05:16:31 EDT 2012


I have this struct :

(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"))

; Editor -> Image
; Function which displays the struct on the screen into a image.
(define (render verwerker)
;; verwerker  editor
;; (editor-pre verwerker) string
;; (editor-post verwerker) string
;; cursor  fixed image
;; workspace fixed image
(place-image (beside (text(editor-pre verwerker) textfont textcolor) 
cursor (text(editor-post verwerker) textfont textcolor ))25 10 workspace ))

Now im trying to make a edit function so you can change the displayed text.

So I thought I could use something like this :

; Editor(e)  Keyevent (k) -> Editor
; Change the Editor according to the keyevent
(define (edit e k)
   [ (key=? k "left") (string-append (editor-pre e) (substring 
(editor-post e) 1 1))))

But now I get a message on my display function that it's expecting a 
Editor but given "aaa"

My question is now How can i change the "aaa" and "bbb" part and still 
returning a Editor?
Do I need to use make-editor all the time ?


Posted on the users mailing list.