4 ms·
Writing a Lisp transpiler is a great exercise, and becomes more involved but more also educational as the source and target language become more and more distan
by siraben 6y ago
Writing a Lisp transpiler is a great exercise, and becomes more involved but more also educational as the source and target language become more and more distant. Here's my Scheme to JS transpiler that supports higher order functions, variadic lambdas, set! and recursion.[0] The function that performs the conversion is https://github.com/siraben/lisp-to-js/blob/0251892e55d1a88f9046242a4081d9c48cb949ad/src/Translation.hs#L158 https://github.com/siraben/lisp-to-js/blob/0251892e55d1a88f9...
- Lisp -> JS is quite easy, good practice for AST representation and working with trees
- Lisp -> C is more challenging, you'll need to perform
closure conversion and generate C structures to hold the environment, see[1] as an example for another functional language
[0] https://github.com/siraben/lisp-to-js https://github.com/siraben/lisp-to-js
[1] https://github.com/jozefg/pcf/blob/master/explanation.md https://github.com/jozefg/pcf/blob/master/explanation.md