Advent of Code, Day 14

Another straightforward one. Here, I’ve used the “closure object trick”. Reindeer are stored as a hash of reindeer hashes, keyed by name. Each of these hashes is created by the addreindeer function, which creates a closure. The hash contains code elements, which access data in this closure. This data is effectively private to the hash. Other elements of the hash contain data, which the code in the hash can access via the this variable, also stored in the closure, which references the hash itself. Thus, we have private members, methods, and we could have inheritance if we ever wrote code to take the hash and change some of its members. There’s also some moderately clever list processing and functional stuff.

Angort is good for this sort of thing.

Copyright © Found
Jim Finnis' personal blog

Built on Notes Blog Core
Powered by WordPress