[plt-scheme] Re: Text-contents to a function variable

From: David Van Horn (dvanhorn at ccs.neu.edu)
Date: Wed Jan 13 10:00:00 EST 2010

On 1/13/10 9:51 AM, Avi wrote:
> I'm sorry for being vague. What I want to do is take a letter that is
> typed into a text-field in a GUI (the letter has a pre-defined number)
> and plug the letter into a function.
> H is typed into a text field ->  H=1 (pre-defined as 1) ->  plug 1 into
> a function

What do you mean by "pre-defined"?  Do you mean you wrote a function 
that converts letters to numbers?  Something like this:

;; 1String -> Number
(define (letter->number ltr)
   (cond [(string=? ltr "h") 1]
         [(string=? ltr "q") 7]
         [else 5]))

In that case you would just apply the letter-to-number function to a 
letter, then apply the number-consuming function you want to the result. 
  So if you want to plug 1 into the add1 function, you'd do (add1 
(letter->number "h")).


Posted on the users mailing list.