[racket] on-key question

 From: Roelof Wobben (r.wobben at home.nl) Date: Thu Mar 15 04:03:42 EDT 2012 Previous message: [racket] on-key question Next message: [racket] on-key question Messages sorted by: [date] [thread] [subject] [author]

```Op 14-3-2012 18:40, Matthias Felleisen schreef:
>
> Here is one way to see what John means:
>
> 1. Experiment with strings and how they represent key strokes in the interactions area of DrRacket:
>
>> (string-length "\t")
> 1
>> (key=? "\t" "\t")
> #t
>> (key=? "\t" "a")
> #f
>
> 2. Define a key-handler function
This is what I made :

; AllKeys String -> AllKeys
; add ke to w, the state of the world
(define (key-handler w ke)
(cond
[ (key=? ke "\t") w]
[ (key=? ke "\r") w]
[ (key=? ke " ") w]
[ (key=? ke "\b") w]
[ (>( string-lenght ke) 1) w
[else (string-append w ke)]))

3. Also explore whether it does the right thing in the interactions area:

>> (key-handler "hello" "\t")
> "hello"
>> (key-handler "hello" "a")
> "helloa"

It does work as expected.

>
> [the above are 'live' experiments, copied and pasted here]
>
>
> On Mar 14, 2012, at 1:32 PM, John Clements wrote:
>
>> On Mar 14, 2012, at 9:05 AM, Roelof Wobben wrote:
>>
>>> As far as I can see I have three different things.
>>>
>>> 1) Input is a character.    Append it to the world.
>>> 2) Input is a  like this one /t . Do nothing.
>>> 3) Input is a  double or more string like right. Do nothing.
>>>
>>> I have to figure out how i can distinct the 1 and 2 from each other.  They both have lenght 1.
>> I'm a bit confused by this message, but I'm going to go out on a limb and suggest that both this question and your prior one will be self-answered if you write down test cases for your situations 1, 2, and 3 above.
>>
>> John Clements
>>
>> ____________________
>>   Racket Users list:
>>   http://lists.racket-lang.org/users
>

```

 Posted on the users mailing list. Previous message: [racket] on-key question Next message: [racket] on-key question Messages sorted by: [date] [thread] [subject] [author]