Olical / aniseed

Neovim configuration and plugins in Fennel (Lisp compiled to Lua)
https://discord.gg/wXAMr8F
The Unlicense
606 stars 28 forks source link

Unable to define multi-arity function #133

Closed jimmyhogoboom closed 1 year ago

jimmyhogoboom commented 1 year ago

I'm trying to evaluate this form:

(defn greeter
  ([] (greeter "Hello" "world"))
  ([target] (greeter "Hello" target))
  ([opener target] (println (str opener ", " target))))

The online REPL has no problem evaluating this. But Aniseed is returning an error, "expected parameters table": https://github.com/Olical/aniseed/blob/a7445c340fb7a0529f3c413eb99d3f8d29f50ba2/lua/aniseed/deps/fennel.lua#L1028

Olical commented 1 year ago

Hey. So is this in Clojure, I guess it is? And if so what keys are you using to evaluate / where is your cursor at the time? There should be no issues with evaluating this form, I can evaluate it just fine. I'd recommend er to evaluate the root form if you're not using that already?

What does the log print when you evaluate this? It should log a snippet of code that it sent to the REPL, it would be great to see that, it'll tell me if something is being extracted wrong.

Do you have tree sitter installed and set up for Clojure? If so, have you updated it recently?

On Fri, 20 Jan 2023 at 17:08, Jimmy Hogoboom @.***> wrote:

I'm trying to evaluate this form:

(defn greeter ([] (greeter "Hello" "world")) ([target] (greeter "Hello" target)) ([opener target] (println (str opener ", " target))))

The online REPL has no problem evaluating this. But Aniseed is returning an error, "expected parameters table": https://github.com/Olical/aniseed/blob/a7445c340fb7a0529f3c413eb99d3f8d29f50ba2/lua/aniseed/deps/fennel.lua#L1028

— Reply to this email directly, view it on GitHub https://github.com/Olical/aniseed/issues/133, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACM6XJLKWXXVJGLUOFOSE3WTLA7ZANCNFSM6AAAAAAUBX5KHA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

jimmyhogoboom commented 1 year ago

Hi, thanks for the quick response!

Yes, I'm attempting to write Clojure.

I have tried <leader>er, along with visually highlighting the whole form and using <leader>E, and using <leader>Ea( while the cursor is on the first open paren.

Here's what the log prints when I ran <leader>er while the cursor is on the first 'd' of defn:

; --------------------------------------------------------------------------------
; eval (root-form): (defn greeter ([] (greeter "Hello" "wo...
; Compile error in unknown:1:?
;   expected parameters table
; 
; (defn greeter
; * Try adding function parameters as a list of identifiers in brackets.

I did just make sure treesitter is installed, and I tried running :TSInstall clojure, which seems to complete successfully, but I still get the same result, even after restarting nvim.

Olical commented 1 year ago

That looks to me like the wrong filetype, Conjure thinks you're in a Fennel buffer for some reason, not a Clojure buffer. Try :set filetype=clojure then eval again.

On Fri, 20 Jan 2023 at 17:25, Jimmy Hogoboom @.***> wrote:

Hi, thanks for the quick response!

I have tried er, along with visually highlighting the whole form and using E, and using Ea( while the cursor is on the first open paren.

Here's what the log prints when I ran er while the cursor is on the first 'd' of defn:

; -------------------------------------------------------------------------------- ; eval (root-form): (defn greeter ([] (greeter "Hello" "wo... ; Compile error in unknown:1:? ; expected parameters table ; ; (defn greeter ; * Try adding function parameters as a list of identifiers in brackets.

I did just make sure treesitter is installed, and I tried running :TSInstall clojure, which seems to complete successfully, but I still get the same result.

— Reply to this email directly, view it on GitHub https://github.com/Olical/aniseed/issues/133#issuecomment-1398708628, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACM6XOUM2ULXFIXC7ALGFDWTLC7BANCNFSM6AAAAAAUBX5KHA . You are receiving this because you commented.Message ID: @.***>

jimmyhogoboom commented 1 year ago

Oh woof, ok this is more confusing than I thought, and I have misinformed you.

I am in a fnl file, so I guess I was wrong before, I'm writing Fennel, not Clojure? (Sorry, still new to this and not sure of the difference).

Unfortunately, when I try :set filetype=clojure or try this form in a .clj file, I get the erorr No nREPL port file found even after :TSInstall clojure. I think this is because I don't have Clojure installed on my system? I was hoping to learn just using Aniseed and Fennel in nvim.

Olical commented 1 year ago

Ah okay then! Well the bad news is Fennel / Lua / Aniseed module system doesn't support multi arity functions :(

The defn macro is my addition through macros if you weren't aware, Fennel has no concept of defn. It also has no concept of multi arity functions as far as I'm aware. However, Lua functions may accept multiple arguments that are optional. If your function takes 3 args and the user gives it 1, the other two arguments will be nil.

So detecting nil args is the way to handle multiple arity in Lua.

On Fri, 20 Jan 2023 at 17:38, Jimmy Hogoboom @.***> wrote:

Oh woof, ok this is more confusing than I thought, and I have misinformed you.

I am in a fnl file, so I guess I was wrong before, I'm writing Fennel, not Clojure? (Sorry, still new to this and not sure of the difference).

Unfortunately, when I try :set filetype=clojure or try this form in a .clj file, I get the erorr No nREPL port file found even after :TSInstall clojure. I think this is because I don't have Clojure installed on my system? I was hoping to learn just using Aniseed and Fennel in nvim.

— Reply to this email directly, view it on GitHub https://github.com/Olical/aniseed/issues/133#issuecomment-1398727280, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACM6XLUOCA6RVBUH33TQHDWTLEQJANCNFSM6AAAAAAUBX5KHA . You are receiving this because you commented.Message ID: @.***>

jimmyhogoboom commented 1 year ago

Aha! Well that clears it up quite conclusively! Thank you so much for your time helping me understand this! It's good to know I don't have some kind of uniquely broken environment 😅