Fork me on GitHub
#conjure
<
2020-05-29
>
martinklepsch23:05:43

I’m seeing an odd issue where I’m not sure if it’s a fennel or a Conjure thing: In vim open this in a file and run forms 1 by 1

(local bindings [])  ; making this global fixes it
(tset bindings :a 1) ; ERROR: unknown global in strict mode: bindings
In a `fennel` REPL it works with local too.

martinklepsch02:05:03

fennel.dofile("init.fnl", { allowedGlobals = false })
might be related to loading it like this

Olical11:05:34

I think it's because each fennel eval like this (not in a repl) gets an entirely new context, I don't think I can feed into a repl but I can have a dig! The solution I'd suggest is to use Aniseeds def macros. It's documented in Aniseeds help and Conjure's fennel + aniseed client. Basically I've implemented a clojure like module system but you have to buy in with def, defn, def-, defn-, defonce etc. I could implement fennel over a stdio repl as a separate client which would allow you to use local and fn in vanilla fennel BUT it would mean no file based namespace contexts to switch between. It's like copying and pasting forms into a repl.

Olical11:05:29

I'll have a look to see if I can get a best of both worlds type thing. I just wanted to provide proper namespaces since fennel doesn't have them. If I add a plain stdio fennel client (which could be run outside of Neovim Lua) then you can use local no problem, it'll just have no context switching as you change buffers. It's all one big REPL environment then. aniseed introduces the concept of files and modules, it just doesn't work with the plain Lua locals.

martinklepsch11:05:26

I see! I’ll take a closer look at Aniseed then. I’m currently writing Fennel to drive Hammerspoon (a Mac automation app) but it tricky to get a REPL to work https://github.com/Hammerspoon/hammerspoon/issues/2377

Olical11:05:55

Ah okay! So aniseed is mainly my solution to vim plugins with fennel, so the choices I made definitely help with building these sorts of apps. You would almost definitely benefit from booting up a regular fennel repl over a luajit or lua binary runtime installed on your machine. Conjure + Aniseed runs it inside Neovim which is a little less free (but so damn good for plugins) So if I implement a fennel over stdio client that lets you configure the startup command for the REPL you'd probably have a much better time. It'd work like the Janet one does in a way. So swapping files means nothing to fennel but you can just eval your whole file whenever you want. It's like a regular repl with nice vim interaction at that point.

martinklepsch11:05:14

Yeah that sounds like what I want.

Olical11:05:25

Would having a regular fennel stdio process booted by a custom command be enough for you then? It's something I was planning to do at some point anyway

Olical11:05:43

Fennel + Aniseed is a specialisation of Fennel. It makes life easier as long as it fits your tradeoffs.

martinklepsch11:05:50

An Aniseed question: in the README it shows syntax like module and defn — where is that coming from?

Olical11:05:04

That's magically added via macros that are auto defined

Olical11:05:09

You have them already ☺️

martinklepsch11:05:03

I see! I love that stuff but I’m also a little worried about the impact it has on portability, e.g. running this code inside a non-vim process

martinklepsch11:05:43

> Would having a regular fennel stdio process booted by a custom command be enough for you then? It’s something I was planning to do at some point anyway I’m not quite sure yet, the hammerspoon hs.ipc API is a little unclear to me still but I haven’t looked at it very much

Olical11:05:08

Of course, that's a valid concern. But bear in mind aniseed isn't tied to nvim, you can compile aniseed flavoured fennel from anywhere

Olical11:05:27

So the module macros translate to vanilla Lua modules

Olical11:05:10

Defn is just fn and local with some extra stuff to ensure it's exported properly

martinklepsch11:05:36

With hs I can get a Lua REPL into the hammerspoon env it seems

Olical11:05:02

Ah interesting

Olical11:05:15

So maybe compiling fennel to Lua then firing that at something else would be good

martinklepsch11:05:57

$ hs -c 'require("fennel")'
table: 0x60000185f8c0
$ hs -c 'require("fennelview")'
function: 0x600002ebf570
this works!

martinklepsch11:05:06

But I’m not sure how to translate that into a “connection” that I could use from conjure :thinking_face:

martinklepsch11:05:47

I guess it’d need to 1. take form from eval binding like eb 2. compile to lua 3. pipe into hs -c 4. print result as output

martinklepsch11:05:40

There doesn’t seem a noticeable distinction between print output and a return value:

$ hs -c 'print("abc") return "asd"'
abc
asd
This is probably fine (?)

Olical11:05:21

Yeah, so the output is a common problem with things that aren't nREPL like etc

Olical11:05:35

The Janet client has this issue but it's really not that big of a deal

Olical11:05:38

It's still workable

Olical11:05:01

And you're right, you'd need an option to be like "do you send fennel directly, or do you compile it to Lua then send it"

Olical11:05:07

Which could be a great option to have!

Olical11:05:29

So a direct "run fennel in this repl" and another step you can add in for compile then run as Lua.

Olical11:05:11

Hmmmm. Maybe the current aniseed one can do this. Is just need to swap from eval to compile and then give you an option for where the Lua should be evaluated instead of inside Neovim :thinking_face:

Olical11:05:31

Then you can just ignore the fennel macros if you wanna

martinklepsch11:05:27

> So a direct “run fennel in this repl” and another step you can add in for compile then run as Lua. With your nvim-local-fennel I guess it would even be possible to set up a little hook to compile the .lua files when saving a buffer

martinklepsch11:05:45

I think this would be really awesome, there’s already a bunch of people that use Fennel to drive Hammerspoon, just one example being https://github.com/agzam/spacehammer

martinklepsch11:05:49

Maybe we can also just start something like janet’s netrepl inside hammerspoon? :thinking_face:

martinklepsch11:05:19

I guess jeejah might be just what we need? https://gitlab.com/technomancy/jeejah

martinklepsch12:05:57

I have an nREPL server running inside hammerspoon!

Olical12:05:38

Ooo! Interesting! For Lua? Or fennel?

Olical12:05:29

I could abstract some of the Clojure nREPL stuff out and reuse it for fennel in that case!

martinklepsch12:05:20

For Fennel using jeejah above

martinklepsch12:05:42

I’m now trying to get shevek to work to test this but not having much luck https://git.sr.ht/~technomancy/shevek/tree/master/README.md

Olical12:05:33

Neat! Well I could definitely implement a fennel nREPL client!

martinklepsch12:05:53

That could be good, yeah! Do you by any chance have an idea how one is meant to run shevek? https://git.sr.ht/~technomancy/shevek/tree/master/README.md

martinklepsch12:05:33

Also asked in #fennel but thought maybe you have a quick idea 😄 If you’re enjoying your Saturday doing other things than sitting in front of a computer then please don’t worry about it all 🙂

Olical13:05:57

I'm afraid not, is it just an nREPL client?

Olical13:05:08

I'm currently doing a puzzle with my partner 😄

Olical13:05:33

Alongside fennel over nREPL I'm considering a generic nREPL client as well as a generic stdio one

martinklepsch13:05:11

Yeah that sounds reasonable. Enjoy the puzzling! 🙂