Hacker News new | past | comments | ask | show | jobs | submit login

I think the real win with a technique like this is that, if you store the bindings in a place that is globally accessible, it is open to extension.

For example, if a JSON library author implemented an encode(object) function using a dispatch table holding a set of object-type/JSON-encoding-function pairs, a client could extend the encode function by registering additional object-type/JSON-encoding-function pairs in the dispatch table.

Edit:

Furthermore, I believe this is how clojure protocols work - when a new type participates in a protocol, the type-specific function implementation gets added to a dispatch table keyed on the datatype's java Class. Then, anytime you invoke the function, the class of the first argument is identified and the corresponding type-specific function is pulled out of the dispatch table based on the class.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: