So today I stumbled accross an interesting article on HN which goes into great detail about the limitation of equality in most languages. The author mentions:
I don’t know of any programming language which even attempts to do anything beyond reference equality for functions. But it’s easy to come up with examples where it would be useful! (An optimizer which removes duplicate code, e.g.) You’re on your own if you need this…
As it just so happened I’d written about this the week before!
Clojure is homoiconic (code is data) and it has great equality semantics which makes it relatively trivial to write these kind of tools.
This example could be expanded with some heuristics to use semantic equality rather than syntactic equality. Even to automatically refactor the code. Or as a macro to automatically optimize code at compile time. ![]()
That being said I’m not sure how useful this is as code duplication hasn’t been common in my experience with Clojure. Still pretty fun so I thought I’d share. ![]()