Re: [racket] display problem

2012-04-13 Thread Roelof Wobben

Op 13-4-2012 20:53, Stephen Bloch schreef:

On Apr 13, 2012, at 1:49 PM, Roelof Wobben wrote:


I still have to write testcases but it's looking good.

That's a bad sign: you should be writing test cases BEFORE writing the function 
:-)


(define verwerker (make-editor "aaa" ""))


; Editor ->  Image
; Function which displays the struct on the screen into a image.
(define (render verwerker)

Again, you've got a function parameter and a global variable with the same 
name.  This will cause confusion; I recommend renaming one of them.



Oke
But how does Racket then now that for example current is the same as 
verwerker ?
In my opinoin I try to read in the "aaa" and "bbb" which I mentioned 
when I did the make-editor.


Roelof


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-13 Thread Roelof Wobben

Op 13-4-2012 19:31, Stephen Bloch schreef:

On Apr 12, 2012, at 8:18 AM, Roelof Wobben wrote:


Why do you need "overlay"?  I would think you could do this just with "beside" 
(unless you wanted to fine-tune the formatting).


Only beside. But how can I then take care that the text are displayed into the 
empty-scene.  I think you need overlay or something for that.

Oh, right: if you want to put the text in a particular place in the empty 
scene, you need overlay or place-image or something.

If you don't care WHERE the text appears in the animation window, you can just 
return the image of the text, and not worry about overlay or place-image.


Stephen Bloch
[email protected]




oke,

I found I think the answer.
I still have to write testcases but it's looking good.

Here is what I have :

(define cursor (rectangle 2 20 "solid" "red"))
(define textcolor "black")
(define textfont 11)

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


; 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 ))


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-13 Thread Stephen Bloch

On Apr 12, 2012, at 8:18 AM, Roelof Wobben wrote:

>> Why do you need "overlay"?  I would think you could do this just with 
>> "beside" (unless you wanted to fine-tune the formatting).
>> 
> 
> Only beside. But how can I then take care that the text are displayed into 
> the empty-scene.  I think you need overlay or something for that.

Oh, right: if you want to put the text in a particular place in the empty 
scene, you need overlay or place-image or something.

If you don't care WHERE the text appears in the animation window, you can just 
return the image of the text, and not worry about overlay or place-image.


Stephen Bloch
[email protected]



  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-13 Thread Stephen Bloch

On Apr 13, 2012, at 11:33 AM, Roelof Wobben wrote:

> I have problems with place-image/align.
> 
> I have this : 
> 
> ; Editor -> Image
> ; Function which displays the struct on the screen into a image.
> (define (render verwerker)

Don't you also have a global variable named verwerker?  I find that having a 
function parameter with the same name as a global variable leads to a lot of 
confusion (students tend to think they're the same thing).

>   (place-image/align (beside (text(editor-pre verwerker) 11 "black") cursor 
> (text(editor-post verwerker) 11 "black")) 0 0 left center workspace ))
> 
> But now I get a message that left is out of context. 
> 
> But where do I put it then ?

Have you written an inventory of available expressions in your function?
I would start with

(define-struct editor [pre post])

(define verwerker )
(define cursor )
(define workspace )
...
(define (render current)
  ; current an editor
  ; (editor-pre current)a string
  ; (editor-post current)   a string
  ; verwerker a fixed editor (i.e. it's the same 
every time "render" is called)
  ; (editor-pre verwerker)a fixed string
  ; (editor-post verwerker)  a fixed string
  ; cursora fixed image
  ; workspacea fixed image
  ; "black", "left", "right", "center"   fixed strings
  ; 11   a fixed number
  
  )

Now that we've done this, we can see why you got that error message: the 
variable name left isn't in the inventory.  The literal string "left" is in the 
inventory, but that's not what you said.

Writing down explicitly which of your inventory items are "fixed", i.e. the 
same every time "render" is called, will also help you figure out why it's 
sometimes producing wrong answers.
If EVERYTHING you use in the function body is "fixed", then the result will 
also be "fixed", i.e. you'll get the same answer every time -- almost certainly 
not what you want.  However, there may well be SOME things that you want to be 
the same every time, such as the color "black", the background scene workspace, 
the font size 11, etc.


Stephen Bloch
[email protected]



  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-13 Thread Roelof Wobben

Op 12-4-2012 18:30, Roelof Wobben schreef:

Op 12-4-2012 18:03, Nick Shelley schreef:
Only beside. But how can I then take care that the text are 
displayed into the empty-scene.  I think you need overlay or 
something for that.


Every image function returns an image, so you can use beside to 
create an image of your text with the cursor in the right spot, and 
then place that image in your empty scene however you want (you used 
place-image, which would work, but I would suggest place-image/align).


In general, I would suggest (as HtDP does) that you experiment with 
each piece of the image in the interactions pane, and then experiment 
with composing them until you get what you want. For instance, use 
the interactions pane to try to get the text and cursor together 
using different image functions until you like what you get, then do 
the same with composing that result and the background.




I have problems with place-image/align.

I have this :

; Editor -> Image
; Function which displays the struct on the screen into a image.
(define (render verwerker)
  (place-image/align (beside (text(editor-pre verwerker) 11 "black") 
cursor (text(editor-post verwerker) 11 "black")) 0 0 left center 
workspace ))


But now I get a message that left is out of context.

But where do I put it then ?

Roelof


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-12 Thread Roelof Wobben

Op 12-4-2012 18:03, Nick Shelley schreef:
Only beside. But how can I then take care that the text are 
displayed into the empty-scene.  I think you need overlay or something 
for that.


Every image function returns an image, so you can use beside to create 
an image of your text with the cursor in the right spot, and then 
place that image in your empty scene however you want (you used 
place-image, which would work, but I would suggest place-image/align).


In general, I would suggest (as HtDP does) that you experiment with 
each piece of the image in the interactions pane, and then experiment 
with composing them until you get what you want. For instance, use the 
interactions pane to try to get the text and cursor together using 
different image functions until you like what you get, then do the 
same with composing that result and the background.


On Thu, Apr 12, 2012 at 6:18 AM, Roelof Wobben > wrote:


Op 12-4-2012 14:00, Stephen Bloch schreef:

On Apr 11, 2012, at 12:03 PM, Roelof Wobben wrote:

I changed the contract to Editor ->  Number.
When I change the make-editor function the value changed.
So I think the check-expect is wrong but I have no clue
how to change it.

No, the check-expect is fine; the definition is wrong.  As I
recall (I don't have it in front of me), it doesn't actually
use its parameter.


The function is this :


(define (width editor)
 (image-width (text (editor-pre verwerker) 11 "black")))

As I understand your remark it doesn't use editor.  So I have to
rewrite it so it uses the parameter editor-pre verwerker ??

Roelof


I find the way with overlay and beside more the hard way.

Why do you need "overlay"?  I would think you could do this
just with "beside" (unless you wanted to fine-tune the
formatting).


Only beside. But how can I then take care that the text are
displayed into the empty-scene.  I think you need overlay or
something for that.


Stephen Bloch
[email protected] 




 Racket Users list:
http://lists.racket-lang.org/users




Oke,

Then back to the drawing table.

Roelof


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-12 Thread Nick Shelley
Only beside. But how can I then take care that the text are
displayed into the empty-scene.  I think you need overlay or something for
that.

Every image function returns an image, so you can use beside to create an
image of your text with the cursor in the right spot, and then place that
image in your empty scene however you want (you used place-image, which
would work, but I would suggest place-image/align).

In general, I would suggest (as HtDP does) that you experiment with each
piece of the image in the interactions pane, and then experiment with
composing them until you get what you want. For instance, use the
interactions pane to try to get the text and cursor together using
different image functions until you like what you get, then do the same
with composing that result and the background.

On Thu, Apr 12, 2012 at 6:18 AM, Roelof Wobben  wrote:

> Op 12-4-2012 14:00, Stephen Bloch schreef:
>
>> On Apr 11, 2012, at 12:03 PM, Roelof Wobben wrote:
>>
>>  I changed the contract to Editor ->  Number.
>>> When I change the make-editor function the value changed.
>>> So I think the check-expect is wrong but I have no clue how to change it.
>>>
>> No, the check-expect is fine; the definition is wrong.  As I recall (I
>> don't have it in front of me), it doesn't actually use its parameter.
>>
>
> The function is this :
>
>
> (define (width editor)
>  (image-width (text (editor-pre verwerker) 11 "black")))
>
> As I understand your remark it doesn't use editor.  So I have to rewrite
> it so it uses the parameter editor-pre verwerker ??
>
> Roelof
>
>
>>  I find the way with overlay and beside more the hard way.
>>>
>> Why do you need "overlay"?  I would think you could do this just with
>> "beside" (unless you wanted to fine-tune the formatting).
>>
>>
> Only beside. But how can I then take care that the text are displayed into
> the empty-scene.  I think you need overlay or something for that.
>
>
>  Stephen Bloch
>> [email protected]
>>
>>
>>
> 
>  Racket Users list:
>  http://lists.racket-lang.org/**users 
>

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-12 Thread Roelof Wobben

Op 12-4-2012 14:00, Stephen Bloch schreef:

On Apr 11, 2012, at 12:03 PM, Roelof Wobben wrote:


I changed the contract to Editor ->  Number.
When I change the make-editor function the value changed.
So I think the check-expect is wrong but I have no clue how to change it.

No, the check-expect is fine; the definition is wrong.  As I recall (I don't 
have it in front of me), it doesn't actually use its parameter.


The function is this :

(define (width editor)
  (image-width (text (editor-pre verwerker) 11 "black")))

As I understand your remark it doesn't use editor.  So I have to rewrite 
it so it uses the parameter editor-pre verwerker ??


Roelof




I find the way with overlay and beside more the hard way.

Why do you need "overlay"?  I would think you could do this just with "beside" 
(unless you wanted to fine-tune the formatting).



Only beside. But how can I then take care that the text are displayed 
into the empty-scene.  I think you need overlay or something for that.




Stephen Bloch
[email protected]





 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-11 Thread Roelof Wobben

Op 11-4-2012 18:03, Roelof Wobben schreef:

Op 11-4-2012 15:10, Stephen Bloch schreef:

On Apr 11, 2012, at 7:39 AM, Roelof Wobben  wrote:

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 ?
Yes, there's something wrong with your width function.  It's nothing 
subtle or complicated; you can figure it out just by looking at the 
two-line definition of that function.


In addition, the contract of the function is wrong: you say it takes 
in an image, but your test cases give it an editor instead.


More broadly, you're doing the whole problem the hard way.  Why do 
you need to know the width of anything?  I would do this whole 
problem without an image-width, without arithmetic, without a 
place-image, using the functions in the 2htdp/image library.



Stephen Bloch
[email protected]


Oke,

I changed the contract to Editor -> Number.
When I change the make-editor function the value changed.
So I think the check-expect is wrong but I have no clue how to change it.

I find the way with overlay and beside more the hard way. I have 
puzzled a lot of time with it without success and this solution cost 
me a half a hour.


Roelof



Nobody who can give me a tip what's wrong with the function.

Roelof


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-11 Thread Roelof Wobben

Op 11-4-2012 15:10, Stephen Bloch schreef:

On Apr 11, 2012, at 7:39 AM, Roelof Wobben  wrote:


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 ?

Yes, there's something wrong with your width function.  It's nothing subtle or 
complicated; you can figure it out just by looking at the two-line definition 
of that function.

In addition, the contract of the function is wrong: you say it takes in an 
image, but your test cases give it an editor instead.

More broadly, you're doing the whole problem the hard way.  Why do you need to 
know the width of anything?  I would do this whole problem without an 
image-width, without arithmetic, without a place-image, using the functions in 
the 2htdp/image library.


Stephen Bloch
[email protected]


Oke,

I changed the contract to Editor -> Number.
When I change the make-editor function the value changed.
So I think the check-expect is wrong but I have no clue how to change it.

I find the way with overlay and beside more the hard way. I have puzzled 
a lot of time with it without success and this solution cost me a half a 
hour.


Roelof


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-11 Thread Stephen Bloch
On Apr 11, 2012, at 7:39 AM, Roelof Wobben  wrote:

> 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 ?

Yes, there's something wrong with your width function.  It's nothing subtle or 
complicated; you can figure it out just by looking at the two-line definition 
of that function.

In addition, the contract of the function is wrong: you say it takes in an 
image, but your test cases give it an editor instead.

More broadly, you're doing the whole problem the hard way.  Why do you need to 
know the width of anything?  I would do this whole problem without an 
image-width, without arithmetic, without a place-image, using the functions in 
the 2htdp/image library.


Stephen Bloch
[email protected]

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-11 Thread Roelof Wobben

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 
st)with 
the cursor displayed between sand t




So for aaa| s has the value of a en t has the value of ""


No, s should be "aaa" and t should be "".

For | s  I think s has the value of a and t has the value 
of aaa


No, s should be "" and t should be "".  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
[email protected] 



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


;; 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 "" 11 "black")
 (+ (width editor) 22) 10
 workspace
(check-expect (render (make-editor "" "")) (place-image
   (text "" 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
(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


Re: [racket] display problem

2012-04-06 Thread Danny Yoo
On Fri, Apr 6, 2012 at 1:38 PM, Danny Yoo  wrote:
>>
>> 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 a| s has the value of a en t has the value of ""
>> For a|aaa s  I think s has the value of a and t has the value of aaa
>
>
> Yes, much better.  Be a bit more specific.  Rather than say that
> something has the value a, it's a bit better to be consistent
> about what things are strings by putting quotes "a".


But to be clear, by examples of data, use code rather than prose: it will help.


When you say:

 So for a| s has the value of a and t has the value of ""

this is still a bit too informal in the place where you should be formal.



Rather:

So for a|,   (make-editor "a" "")

and for a|aaa, (make-editor "a" "aaa")

It's ok to use informal prose, which might use your own notation.  But
follow it up with the notation used in the programming language.


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-06 Thread Danny Yoo
>
> 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 aaa| s has the value of a en t has the value of ""
> For | s  I think s has the value of a and t has the value of aaa


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


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!


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-06 Thread Roelof Wobben

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 
st)with 
the cursor displayed between sand t




So for aaa| s has the value of a en t has the value of ""


No, s should be "aaa" and t should be "".

For | s  I think s has the value of a and t has the value 
of aaa


No, s should be "" and t should be "".  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
[email protected] 



Thanks,

I now know I have a idea which could work.

Roelof

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-06 Thread Roelof Wobben

Op 6-4-2012 9:20, Danny Yoo schreef:



On Friday, April 6, 2012, Roelof Wobben wrote:

Op 5-4-2012 20:29, Danny Yoo schreef:

I start with this :

a|


Concretely, what does the editor world value look like at this
point?
You're representing the state somewhat ambiguously.  Can you
represent
the above in terms of (make-editor ... ...)?



Yes, (make-editor  aaa  """)


This can't be, as make-editor can only take two strings.  The 
structure definition of make editor is:


(define-struct editor (pre post))

Where both pre and post are both strings.

now someone press 3 times the left key.
So I have  aa/aaa


rep has he value of a
s has the value of a
t has also the value of a.



You make the same conceptual mistake here.  This representation does 
not fit the shape of the structure definition.



Go back and make sure you understand the data definition.  If you have 
questions about it, please feel free to ask.



Oke,
Back to the beginning.

In the text is noted.
(define-struct 
editor(prepost)) 


;Editor= (make-editorStringString)
;interp. (make-editorst)means the text in the editor is
;(string-append 
st)with 
the cursor displayed between sand t




So for aaa| s has the value of a en t has the value of ""
For | s  I think s has the value of a and t has the value of aaa

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 ?

Roelof


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-06 Thread Roelof Wobben

Op 5-4-2012 20:28, Stephen Bloch schreef:

On Apr 5, 2012, at 1:39 PM, Roelof Wobben wrote:


Op 5-4-2012 19:28, Danny Yoo schreef:

Can you get the position where the cursor should start by
taking the image for the left side text, and take its width?


...
I start with this :

a|

now someone press 3 times the left key.
So I have  aa/aaa
How can I know where the cursor is now.
Or can I do  width - 3 times 11 ?

You could do that, but it's not guaranteed to give you the right answer, 
because not all characters in a font are necessarily the same width.  How about 
(as Danny suggested) making an image of the left side text, and taking its 
width?


Stephen Bloch
[email protected]




I can do that as starting point when I have this situation aaa|
But how can i make a image if it's like this : aaa|aaa
I could use substring but then I have to know which letter I have to cut.
And whith this world I cannot know that.

Roelof


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-05 Thread Danny Yoo
> I start with this :
>
> a|


Concretely, what does the editor world value look like at this point?
You're representing the state somewhat ambiguously.  Can you represent
the above in terms of (make-editor ... ...)?




> now someone press 3 times the left key.
> So I have  aa/aaa


Similarly, what does the world value look like at this point?


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-05 Thread Stephen Bloch

On Apr 5, 2012, at 1:39 PM, Roelof Wobben wrote:

> Op 5-4-2012 19:28, Danny Yoo schreef:
>> Can you get the position where the cursor should start by
>> taking the image for the left side text, and take its width?
>> 
> ...
> I start with this :
> 
> a|
> 
> now someone press 3 times the left key.
> So I have  aa/aaa
> How can I know where the cursor is now.
> Or can I do  width - 3 times 11 ?

You could do that, but it's not guaranteed to give you the right answer, 
because not all characters in a font are necessarily the same width.  How about 
(as Danny suggested) making an image of the left side text, and taking its 
width?


Stephen Bloch
[email protected]



  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-05 Thread Nick Shelley
You should look into the composing image functions available. The beside
function should make it so you don't need to calculate exactly where the
cursor should be displayed.

On Thu, Apr 5, 2012 at 11:39 AM, Roelof Wobben  wrote:

> Op 5-4-2012 19:28, Danny Yoo schreef:
>
>  http://www.ccs.neu.edu/home/**matthias/HtDP2e/htdp2e-part1.**
 html#(part._edit1)

 We need more context because there's not enough information in the
 question to tell what you're trying to do yet.


 Good luck!

>>> Yes, I mean that exercise.
>>>
>> Ah.  Ok.  Can you get the position where the cursor should start by
>> taking the image for the left side text, and take its width?
>>
>>
> Yes, I could.
>
> Where I see a problem is here :
>
> I start with this :
>
> a|
>
> now someone press 3 times the left key.
> So I have  aa/aaa
> How can I know where the cursor is now.
> Or can I do  width - 3 times 11 ?
>
> Roelof
>
>
>
>
> 
>  Racket Users list:
>  http://lists.racket-lang.org/**users 
>

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-05 Thread Roelof Wobben

Op 5-4-2012 19:28, Danny Yoo schreef:

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

We need more context because there's not enough information in the
question to tell what you're trying to do yet.


Good luck!

Yes, I mean that exercise.

Ah.  Ok.  Can you get the position where the cursor should start by
taking the image for the left side text, and take its width?



Yes, I could.

Where I see a problem is here :

I start with this :

a|

now someone press 3 times the left key.
So I have  aa/aaa
How can I know where the cursor is now.
Or can I do  width - 3 times 11 ?

Roelof




 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-05 Thread Danny Yoo
>> http://www.ccs.neu.edu/home/matthias/HtDP2e/htdp2e-part1.html#(part._edit1)
>>
>> We need more context because there's not enough information in the
>> question to tell what you're trying to do yet.
>>
>>
>> Good luck!
>
> Yes, I mean that exercise.

Ah.  Ok.  Can you get the position where the cursor should start by
taking the image for the left side text, and take its width?

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-05 Thread Roelof Wobben

Op 5-4-2012 18:53, Danny Yoo schreef:

I have a struct which contains text and the place of a cursor.
The place are 2 strings which contains the character on the left and on the
right of the cursor.

Now I have to display this.
But I wonder how I can set the cursor on the right place when I can't know
the numbers where between the cursor is placed.
I know that the characters are 11 pixels.


I think we need more information, as I'm still a little confused.  Can
you give a few examples of the struct values you are using?  It's a
bit unclear from the prose alone what these values look like.


By "cursor", can you be more specific?  Do you mean a cursor on a
racket/gui text% instance?  Do you mean a cursor that refers to the
"graphical editor" example in HtDP 2ed?

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

We need more context because there's not enough information in the
question to tell what you're trying to do yet.


Good luck!



Yes, I mean that exercise.

Roelof


 Racket Users list:
 http://lists.racket-lang.org/users


Re: [racket] display problem

2012-04-05 Thread Danny Yoo
> I have a struct which contains text and the place of a cursor.
> The place are 2 strings which contains the character on the left and on the
> right of the cursor.
>
> Now I have to display this.
> But I wonder how I can set the cursor on the right place when I can't know
> the numbers where between the cursor is placed.
> I know that the characters are 11 pixels.


I think we need more information, as I'm still a little confused.  Can
you give a few examples of the struct values you are using?  It's a
bit unclear from the prose alone what these values look like.


By "cursor", can you be more specific?  Do you mean a cursor on a
racket/gui text% instance?  Do you mean a cursor that refers to the
"graphical editor" example in HtDP 2ed?

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

We need more context because there's not enough information in the
question to tell what you're trying to do yet.


Good luck!

  Racket Users list:
  http://lists.racket-lang.org/users