[plt-scheme] setting variables

From: Grant Rettke (grettke at acm.org)
Date: Mon Jan 25 22:41:35 EST 2010

On Sun, Jan 24, 2010 at 10:14 PM, Avi <n4alpaca at gmail.com> wrote:
> How do I set a variable used in a mathematical function using set!,
> based upon what is put into a text-field (I'm using gui.ss)
>
> example:
> (define (Math x)
>    (+ 1 a d)
>  if user types "H" into text-box 1 than (set! a (+ a 1) and if user
> types "O" into text-box 2 than (set! d (- d 2).

You could put that function inside of a class, where a was a local
variable, and you could set the value was you know it.

You could define math after you know the value of a like this:

(define (Math-maker a)
  (λ (x)
    (+ 1 a x)))

(define Math (Math-maker my-a-value))

You could parameterize the value of a:

http://docs.plt-scheme.org/reference/parameters.html

You could pass in a as an argument every time.


Posted on the users mailing list.