Problems 83 - 87 The Editor!

Editor Problem 

  • 83 - render editor 
  • 84 - edit & all the related functions (left arrow, right arrow, backspace, delete, add a character)
  • 85 - run from a single string
  • 86 - do not allow the text to go off the scene
  • 87 - an alternate representation of an editor

For problems 83 - 86 use the following definitions and examples.

(define-struct editor [pre post])
; An Editor is a structure:
;      (make-editor String String)

(define both (make-editor "big"  "dog"))
(define pre-only (make-editor "big"  ""))
(define post-only (make-editor ""  "dog"))
(define neither (make-editor ""  ""))


83  Create a render function.  There are two functions that will help you with this problem; text and beside
(text "big" 20 "blue")  creates an image the word big that is 20 pixels tall
(beside (square 20 "solid" "red")(circle 10 "outline" "green")(triangle 20 "solid" "purple")) -> red square green circle and purple triangle  

Your final result, after placing the image on a scene, should look like this: the words big dog

84  The best approach is to create and test several functions:
left arrow, right arrow, backspace, delete (uni-code "\u007F"), and add-character using the 4 editor test cases: both, pre-only, post-only, and neither 
When that is done you can write an edit function that takes in the world state (an editor) and a key event (ke)

(define (editor an-ed ke)
      [(string=? ke "left") (left-arrow an-ed)]
       ...  ))

85  The easiest function to write.  (run "lakewood")  calls the big-bang with an editor, where the pre part is "lakewood" and the post is empty.

86  This code (possibly a function) guards against letting an added character push characters off of the scene.
Consider the following, where there is little room left: the words bigger dog
If we were to type a "w" then the following would happen biggerwdo
and the "g" is off of the screen.  Do not allow this to happen!
However, there is enough for two letter "i"s to be typed. biggeriidog

87   Consider another way to represent an editor
    • (make-editor "big" "dog")  -> (make-ed  "bigdog" 3)
    • (make-editor "big"  "") -> (make-ed "big" 3)
    • (make-editor ""  "dog") -> (make-ed  "dog" 0)
    • (make-editor ""  "")  -> (make-ed "" 0)
  • Create a new editor program that uses this structure definition


Website by SchoolMessenger Presence. © 2018 West Corporation. All rights reserved.