lantiga / ki

lisp + mori, sweet.js
ki-lang.org
MIT License
478 stars 28 forks source link

Ki as a library? #28

Open girvo opened 8 years ago

girvo commented 8 years ago

One of the things I'd love to work out how to do is load ki as a library in Node, specifically to write a Webpack loader for easier development workflows. Any ideas where to start with that, as lib/ki_run.js seems to have a lot of code involved

lantiga commented 8 years ago

Sounds great, a webpack workflow would be a very nice addition to ki. You should look into how the live editor on ki-lang.org does it. Specifically, take a look at main.js and ki.js.

girvo commented 8 years ago

I've nearly got it working, but got distracted porting wisp over to webpack (see here). I'll have another crack today!

Also, out of curiosity, how does ki go with importing macros? It's a pretty big missing feature in wisp; would be awesome if it was in ki, but I'm well aware how difficult it is to add considering it needs to work with the JS runtime at the end of the day!

lantiga commented 8 years ago

ki macros are a thin layer on top of sweet.js macros - they are not real lisp-style macros. Take a look at the ki macro entry in the API as well as the react example.

ki is essentially sweet.js macros all the way down, so it was easier to define macros this way, although they are way less powerful than lisp macros.

The way it works (both in ki_run and in ki.js which you can use as a lib) is that the compiler detects if a file contains the ki macro statement and will just embed them as a rule in the _sexpr macro (in ki.sjs), replacing /*__macros__*/. It's really naive, we could do a lot better, especially since sweet.js has recently introduced (a primitive form of) modules.