Reputation: 1431
Say there are two variables: x
and y
. Let x
be a function of y
, e.g. set x 2 * y
.
If future lines of the code alter the value of y
, the value of x
does not seem to automatically update, without me specifying again: set x 2 * y
.
Is it possible to create a variable as a function of other variables, which automatically updates without having to set it again?
Upvotes: 1
Views: 403
Reputation: 12580
Instead of using variables for this, you should define a reporter:
to-report x
report 2 * y
end
though, for the sake of those reading your code and for your future self looking back at your code, use more descriptive variable names than x
and y
:)
Upvotes: 2