ki icon indicating copy to clipboard operation
ki copied to clipboard

Ki as a library?

Open girvo opened this issue 9 years ago • 3 comments

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

girvo avatar Oct 23 '15 04:10 girvo

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.

lantiga avatar Oct 23 '15 13:10 lantiga

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!

girvo avatar Oct 26 '15 02:10 girvo

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.

lantiga avatar Oct 26 '15 07:10 lantiga