An algorithm for converting code from S-expressions to A-normal form is given at http://matt.might.net/articles/a-normalization/
The author has made the unusual choice of writing the algorithm in continuation passing style. (That is, it's not that the intermediate code is represented in CPS at any stage, but that the handwritten code to do the conversion, is written in CPS.)
It makes sense insofar as I can see how it works, and the continuation represents the body of each generated let
, but it is intuitively surprising that CPS should be the clearest way for humans to write code.
Is this actually the clearest form of ANF conversion algorithm, or is there a known better way that doesn't use CPS?