top | item 25554756

A Tiny Lispy Transpiler

110 points| oumua_don17 | 5 years ago |github.com | reply

24 comments

order
[+] skulk|5 years ago|reply
Here is the usage, which shows how many backends this supports (pretty impressive IMO).

    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.
[+] konjin|5 years ago|reply
This isn't a Lisp, this is a paren based serialization of the syntax tree of an Algol like language.

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.

[+] siraben|5 years ago|reply
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/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

[1] https://github.com/jozefg/pcf/blob/master/explanation.md

[+] jdmoreira|5 years ago|reply
This is very interesting as the base level AST for a multi-step transpiler. Just pile transformations on top and grow your own language that transpiles to "everything".
[+] boxmonster|5 years ago|reply
I'm so astonished at the output of Lingdong that I find myself doubting that this is one person and may be a collective. I'm not making theories, I'm merely expressing my admiration of these works and these abilities.

https://lingdong.works/

[+] krcz|5 years ago|reply
Very interesting project! That is the first attempt I've seen at something I call "idiomatic code translation" - transpiling with result not only to be executed, but to be read and naturally included in existing codebases.

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

[+] eyelidlessness|5 years ago|reply
I was just ruminating with a friend the other day how much I want a typed lisp with Clojure syntax and semantics, and TypeScript’s type system. This checks one of those boxes almost entirely (syntax), and it makes me wonder if it could be wrapped or retrofitted to provide the rest. Probably not the type system without significant work. Still, cool project nonetheless!
[+] mssundaram|5 years ago|reply
As a tangent, Typescript's type system has become really powerful, expressive and quite pleasant to work with.
[+] tluyben2|5 years ago|reply
Backend language support wise, it makes me think of Haxe [0]; would be easy to add a Haxe backend for Wax. Definitely Wax is a lot simpler to add backends for and all Haxe targets are garbage collected so might be an interesting experiment.

[0] https://haxe.org

[+] 1f60c|5 years ago|reply
Online playground: https://waxc.netlify.app/

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!

[+] ngcc_hk|5 years ago|reply
Is this the first time to lisp related but non-functional language. Shock to see it does not support functional style.
[+] chrisseaton|5 years ago|reply
> Is this the first time to lisp related but non-functional language

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!

[+] twism|5 years ago|reply
closing parenthesis on a new line
[+] konjin|5 years ago|reply
From the Readme:

>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.