A Tiny Lispy Transpiler
github.com
github.com
USAGE: waxc [options] code.wax
OPTIONS:
--c path/out.c transpile to c
--java path/out.java transpile to java
--ts path/out.ts transpile to typescript
--py path/out.py transpile to python
--cs path/out.cs transpile to c#
--cpp path/out.cpp transpile to c++
--swift path/out.swift transpile to swift
--lua path/out.lua transpile to lua
--wat path/out.wat transpile to webassembly
--json path/out.json syntax tree to JSON file
--tokens print tokenization
--ast print abstract syntax tree
--silent don't print info
--help print this message
I do think the syntax is a little bit jarring as someone who is used to LISP's omission of keywords like "then" and "do". Also, LISPers usually don't put parens on their own lines.Even the readme says as much: The syntax of wax is inspired by WebAssembly Text Format (wat), hence the name. Though it uses S-expressions reminiscent of the Lisp family, it is actually quite imperative and most resemblant of C in its design. The idea of transpiling to many languages is inspired by Haxe.
This is actual standard Common Lisp and basically the same (minus slightly different syntax) as the quicksort example from the link:
(defun qksort-inplace (a lo hi)
(declare (type integer lo hi)
(type (array float) a))
(if (>= lo hi)
(return-from qksort-inplace))
(let ((pivot (aref a lo))
(left lo)
(right hi))
(declare (type float pivot)
(type integer lo hi))
(loop while (<= left right) do
(loop while (< (aref a left) pivot) do
(setf left (+ left 1)))
(loop while (> (aref a right) pivot) do
(setf right (- right 1)))
(if (<= left right)
(let ((tmp (aref a left)))
(setf (aref a left) (aref A right)
(aref a right) tmp
left (+ left 1)
right (- right 1)))))
(qksort-inplace A lo right)
(qksort-inplace A left hi)))If your language supports that. TCO is not a standard feature of Lisp.
- 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
[1] https://github.com/jozefg/pcf/blob/master/explanation.md
I've had similar idea on my mind since few years, but as for now the only output is a document explaining the goals [1], I'm still in exploration phase, as I want something more abstract, with more advanced language concepts implemented using macros (as in Turnstile+ does with dependent typing [2]).
[1] https://github.com/krcz/zygote [2] https://www.ccs.neu.edu/home/stchang/popl2020/index.html
I’m using and I get that it’s powerful but TS just hits that sweet spot of being immensely useful with out getting too much in the way.
[0] https://haxe.org
As expected, the transpiled code doesn't look great, with lots of unnecessary parentheses. That said, the number of back-ends is very impressive. Good job!
This is a common misconception.
People conflate Lisp and purely functional programming as if Lisps are and were always purely functional, but this isn't historically accurate. Many early Lisps were deeply imperative - to an extreme that would seem crazy to use today - including even dynamic scoping!
>The syntax of wax is inspired by WebAssembly Text Format (wat), hence the name. Though it uses S-expressions reminiscent of the Lisp family, it is actually quite imperative and most resemblant of C in its design. The idea of transpiling to many languages is inspired by Haxe.
Can someone change the title? Just because it uses parens does not mean it's in the lisp family.