3 ms·
>> What about host language access? I'd rather not give up using existing JS and Lua libraries. >Easy: $ npm i leftpad $ LUMEN_HOST=node lumen > (requir
by jarpineh 9y ago
>> What about host language access? I'd rather not give up using existing JS and Lua libraries.
>Easy:
$ npm i leftpad
$ LUMEN_HOST=node lumen
> (require 'leftpad)
function
> ((require 'leftpad) "foo" 10)
"0000000foo"
Huh. It just worked. With rlwrap this feels (at least at the very first try) regular REPL!
>> I can see there's REPL, but is it possible to have dynamic evaluation while running inside web browser?
> Yes, the entire codebase is only 3k lines. You can use browserify, or simply concatenate all the JS files together. Lumen is unopinionated.
Amazing. That sounds very compact to me. I'd imagine today's JS build systems can do optimized builds without too much trouble. Also, by that count it should be an afternoon's read to get it.
> I've done this before, and I'm more than happy to set you up with a copy-pastable solution if you want.
My answer in your other comment.
>> Have you used this inside Nginx's Lua module and/or OpenResty?
> No, but there's no reason it wouldn't work. Here's an example of it working in a WASM Lua implementation: https://news.ycombinator.com/item?id=13900453 https://news.ycombinator.com/item?id=13900453
Ok, must do some testing. I have nothing against Lua, but having a Lisp within Nginx/OpenResty just seems more fun.
>> Why not Python as one target host language? Lists and hashmaps (dictionaries) are pretty prevalent there and I believe continuously developed Lisp dialect is still missing.
> I've spent time on this! It's a difficult problem. In Lua and JS, you can attach keys and values to arrays. In other words, an array can also be a hashmap. Not so in Python -- or rather, not with the standard Python dict() type. And then you run into problems of interoperability and performance: if it's a non-standard type, other libraries run into problems consuming it. This is less true of Python than other languages, though, so I've been trying to find a happy medium.
> There are ways of using solely arrays, but it involves having some sort of Keyword type. A normal lisp has those, and typically they use '(a b :x 42) to create an "array" where the first two elements are "a" and "b" and the key "x" has value 42. You can do something similar for Python, and it's an active area of research for me.
Yeah, I realize there's all sorts of pitfalls. I thought about 3.6 having by default ordered dicts could make things easier. But probably not. Perhaps if I'd do array indexed access in Python with a helper method "transpiled" where necessary. In my own code I could keep from using other, harder to support Pythonisms.
>> Any example apps or sample code anywhere?
> This is Lumen's strength and weakness. Very few people know about Lumen because of a lack of examples and documentation. However, it's incredibly cool and quite mysterious, and I like that it has a very small following. It makes changing the language much easier.
> Here's an extensive example: https://github.com/sctb/motor https://github.com/sctb/motor
> Note that it won't run on the latest Lumen, because dot syntax was recently removed. You'll need to revert to commit `c146de`. But you see how easy it is to morph the language into whatever shape you want, and how powerful it can be.
I'll check it out, thank you. And thank you for this!
- sillysaurus3 9y agoI use rlwrap too. There are a few extra options that are nice, so I wrap it up in a script I call `lwrap`: https://gist.github.com/anonymous/c1a0c9d54bc647179fa32c08e7d20698 https://gist.github.com/anonymous/c1a0c9d54bc647179fa32c08e7... Then I invoke it like `lwrap lumen`. I use multi-line mode pretty often, and I have this in my ~/.inputrc file: "\e\C-m": rlwrap-call-editor # ALT-RET So at Lumen's prompt, I usually type () followed by Alt-Return, which drops me into MacVim and I edit from there. If you're a vimmer or an emacs user, I can set you up with some basic tooling to make things easier.