Can we achieve homoiconicity in Unison?

Viewed 53

At first glance, it seems like Unison may be homoiconic due to the fact that "code is data", at least in the sense that Unison code are stored as cryptographic hashes in a durable fashion. However, directly working with cryptographic hashes doesn't seem very practical, perhaps no more than directly working with compiled bytecode for the JVM. So maybe it is best to break this down into two parts:

  1. Is Unison currently homoiconic?
  2. Could Unison be homoiconic, with additional code-generation and AST manipulation features?
1 Answers

On 1, I'd say no. When Unison is eventually self-hosted, then sure, the compiler data structures could be made available as a library.

However, since Unison builtins to convert any Unison value or code to a well defined serialized form, you can write a library that parses that form into some Unison data structures that represent that code. That is actually what the in progress Unison JIT compiler does. And the library that Dan developed for this will be something people could use for other purposes (like I could imagine using it to write plugins that would generate a JSON serializer for arbitrary Unison values, for instance).

Maybe some people would say the existence of said library counts as homoiconicity now. Like it doesn't really matter if the compiler internally represents code as a Unison data structure as long as you have a function for converting code to a Unison data structure.

Aside: I dislike the term homoiconicity. It's a fancy piece of jargon that isn't even particularly well-defined.

Related