[racket] display problem

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Fri Apr 6 13:38:02 EDT 2012

>
> Oke,
> Back to the beginning.
>
> In the text is noted.
> (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
>
>
> So for aaaaaaa| s has the value of aaaaa en t has the value of ""
> For aaaa|aaaa s  I think s has the value of aaaaa and t has the value of aaa


Yes, much better.  Be a bit more specific.  Rather than say that
something has the value aaaaa, it's a bit better to be consistent
about what things are strings by putting quotes "aaaaa".


To push the pedagogic point: understanding the data definitions is one
of the first steps of the design recipe.

    http://www.ccs.neu.edu/home/matthias/HtDP2e/htdp2e-part1.html#(part._designstructs)

One you understand the point of why the data is structured in this
peculiar way, the problem should be a lot easier to solve.


I believe that your initial confusion was because you originally
thought the "pre" and "post" were only the single character before and
after the cursor.  Hopefully, that's cleared up now.



> I have a idea.
> 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.
> 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.
>
> Am I on the right track ?

Yes, that looks like what I'd do too.


Good luck!


Posted on the users mailing list.