Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Keeping a variable constantly up-to-date

Name: Anonymous 2010-07-13 21:04

I'm certain this is a stupid question, [SPOILER]/prog/[SPOILER], but how does one keep a variable updated without doing it manually?

Example of what I'm looking for, preferably in pythong:

x = 10
y = x*2

x += 5

y == x*2
...
True


I could make a simple function to make sure var2 is always proportional to var1, but when I get to dozens or hundreds of variables, it gets to be a pain in the anus.

Name: Anonymous 2010-07-14 6:04

>>20
I'd just completely forgotten the existence of lambda for one-line functions.
That is not what lambda is for, regardless of what Guido will tell you.
>>21
3. (global or local) symbol macro
To be honest, I never liked these, although for something like OPs problem it may be fine. R6RS added a convenient form for doing them too, that I hadn't noticed until yesterday
(define-syntax y (identifier-syntax (* 2 x)))
Of course, this macro would always refer to the x in the scope which the it is bound, but I think that is the behaviour OP would want.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List