Scope of Variables in Inform 7
Published on November 5, 2019
Debuggery
Some fields hidden!
- visibility: ['public']
- author: {'uid': ['/'], 'name': ['Maxwell Joslyn'], 'note': ['I am a human bean']}
- url: ['/2019/11/05/tf', '/ideas/inform-variable-scope']
- type: ['entry']
Consider this snippet of Inform 7 code:
To improve the mood of (character - an animal): if the mood of character is less than friendly, now the mood of the character is the mood after the mood of the character.
I am not sure whether or not the statement "the mood after the mood of the character" wraps around. That is to say, I am not sure whether the above code would "improve" the character's mood from the best one possible to the worst. I would hope it doesn't do that, but I'll have to investigate.
The if
statement above can be translated into pseudo-Clojure as follows:
(let [current-mood (:mood character)] (if (< current-mood friendly) (assoc :mood character (succ current-mood)))) ;;assuming the moods have an interface sort of like Haskell Enum typeclass ;; 'set KEY in MAP to VAL' is spelled `assoc` in Clojure