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 5:11

If you used lisp, you have a few options:
1. function
Can't set to it, but if you define a setf function, you can make it act like an accessor.
2. accessor (like setters/getters in other
Needs an object to work with.
3. (global or local) symbol macro
Looks like a normal variable/symbol, but in reality it will expand to a form which will either be a function call, place form (setf) or some object accessor (which are implemented using generic functions and place forms).

In most other languages, you'll have to settle with accessors and normal functions or methods.

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