Settings

Theme

Show HN: Dak – a Lisp-like language that transpiles to JavaScript

daklang.com

94 points by daakus 3 years ago · 23 comments · 1 min read

Reader

Hi HN, author here. Happy to answer any questions.

I had an itch to make a lisp like language that was a thin layer on top JavaScript. Something that could leverage the thriving ecosystem that exists around JavaScript. It's brittle, hot off the oven.

Besides being a fan of parenthesis, I think macros fill in a gap that the JavaScript ecosystem today fills in with one-off compilers, bundler plugins and such. Macros can't do everything, but for example I think they have the potential to enable things like JSX, Solid and Svelte style libraries.

Take the tour to get a feel for what it can do and play with the live code in your browser!

orestis 3 years ago

Interesting, in the CLJS space we recently got two new libraries in this space:

https://github.com/squint-cljs/squint Which is a thin layer on top of JS

https://github.com/squint-cljs/cherry Which is closer to CLJS semantics and data structures but compiles to .mjs files without any advanced optimizations etc.

  • daakusOP 3 years ago

    I'm a huge fan of Clojure and have had a lot of fun building things with it. CLJS on the other hand has felt heavy to me, from a browser performance and dev tooling perspective. Clojure startup time always affected me more so with CLJS projects. I hope these two projects alter the landscape for the better!

    Besides those aspects, Dak is different than these two specifically in that it tries to provide something closer to a minimal 1-to-1 language feature mapping to JavaScript as the base, with a goal of having essentially no runtime.

    The clean room implementation has downsides - Squint and Cherry can reuse Clojure tooling like clj-kondo etc, which Dak cannot. On the other hand Dak is small, the transpiler is under 2k lines as I write this. It can run on virtually any modern JavaScript runtime (all browsers, node, deno, bun etc).

hackrnusr 3 years ago

Looks interesting. I hope to start using an s-expression based version of javascript after I get more familiar with the latter.

Maybe you also want to consider comparing Dak to other attempts in this direction in order to help generate more interest in your work:

https://github.com/anko/eslisp/blob/master/doc/comparison-to...

  • daakusOP 3 years ago

    Thanks for the feedback. I'll add some notes comparing it with other attempts like you suggested.

rileyphone 3 years ago

I'm enjoying reading your transpiler[0], especially how well you use generator functions. Currently I'm building a similar language in a more opinionated object-oriented style, yet I still find yours inspiring.

0. https://github.com/daaku/dak/blob/main/packages/transpiler/s...

  • daakusOP 3 years ago

    Thanks!

    My fear taking this path is around performance. I've not done any profiling yet, and I'm hoping I don't regret taking this path when I get around to it.

dunham 3 years ago

Nice work. A few years ago, I made something similar out of lumen[0] by tweaking the reader to support clojure style literals. I used hyperapp[1] as a lightweight library for react/elm style applications with a hiccup-like syntax. The code ended up looking like

    (h 'div { class: 'main }
       (h 'div {} ....
Where h is the raw function for hyperapp, not a macro.

I'd intended to develop my own mini-lisp with the same syntax, but got sidetracked by other projects. Maybe someday I'll get back to it. (Currently, I'm deep in the weeds trying to learn how to write a dependent typed language that compiles to javascript.)

[0]: https://github.com/sctb/lumen [1]: https://github.com/jorgebucaran/hyperapp

  • daakusOP 3 years ago

    Nice! My goal in Dak is to reach a point where macros can allow transforming hiccup like syntax to hyperapp or React like function calls, or original hiccup style optimized string concat, or lit-html style template string generation. I know I could use all these for different use cases.

inglor 3 years ago

Maybe dumb question since I only have experience with a few lisps (Common Lisp, clojure and scheme) but why is this “lisp like” and not a “proper” lisp?

It looks like a lisp for me with its “code is data” (homoiconic) bit and s expressions.

  • shaftoe444 3 years ago

    Describing stuff as Lisp-like is a good way to sidestep arguments about "proper" Lisp.

    What even is a proper Lisp? http://steve-yegge.blogspot.com/2006/04/lisp-is-not-acceptab...

    • inawarminister 3 years ago

      Huh it's orthogonal but basically Clojure is an attempt to answer all those four problems, right? Bypassing the which LISP problem by canonical implementation on top of host VMs (of which there are JVM, CLR, JS, Dart and BEAM), bypassing the spec, bypassing the whole object-oriented problem by impure functional approach, and having a BDFL on the top.

      Anyway, back to the main point, thank you for the article. I'll try to play around with Dak later today and see if I can use it to do something fun. Play is better to learn something after all.

    • User23 3 years ago

      I've enjoyed defending the claim that Perl5 is a Lisp, just instead of being a Lisp-1 or Lisp-2 it's a Lisp-5ish.

    • aidenn0 3 years ago

      Indeed Kent Pitman is on the record[1] as saying that Scheme is not "a Lisp"

      1: https://groups.google.com/g/comp.lang.lisp/c/Bj8Hx6mZEYI/m/6...

daliwali 3 years ago

Really reminds me of Parenscript[0], which is a subset of Common Lisp that transpiles to JS with no runtime. It's basically a thin skin around JS and it feels more like writing JS with a Lisp syntax.

What I feel is missing from Parenscript is runtime macro-expansion, hard to do without using JS to build the AST.

[0] https://parenscript.common-lisp.dev/

  • daakusOP 3 years ago

    Ah, I remember seeing this a long time ago. It seemed like something CL fans would enjoy, but to me it felt verbose. I guess this is my Clojure preference showing.

    Regarding runtime macro-expansion - since Dak is written in JavaScript, it comes for free.

cellularmitosis 3 years ago

Neat. So in a single sentence, you could say "As Janet is to Clojure, Dak is to ClojureScript".

fuzzythinker 3 years ago

Hmm, name is a bit too close to another language - darklang

phist_mcgee 3 years ago

In Australian slang, to da(c)k someone is to pull their pants down to humiliate them.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection