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

From: Stephen Bloch (sbloch at adelphi.edu)
Date: Wed Jan 13 10:56:55 EST 2010

On Jan 13, 2010, at 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

Aha: we were being confused by "the letter has a pre-defined number".  I think what you actually mean is that you've defined a Scheme variable named H to have the value 1, and when the user types the letter "H" into a text field, you want to use the value 1.  And I presume you would want it to work for other variables too, e.g. if you had a Scheme variable named AGE with the value 30, and the user typed "AGE" into the text field, you would use the value 30.  Right?

Before discussing how to do this, let's clarify the problem.  What should happen if the user types in " H" or "H " (that is, H with a space before or after it)?  What should happen if the user types in "h"?  What should happen if the user types in "x" (where there is no Scheme variable named x or anything like it)?  What should happen if the user types in "27"?

Here are some trickier questions.  What should happen if a variable named x is defined after the code is written, but before the user types "x" into the text field?  What should happen if the GUI program in which all this is happening has a parameter or a local variable named x, and the user types "x" into the text field?




Stephen Bloch
sbloch at adelphi.edu





Posted on the users mailing list.