Olical / aniseed

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

Weird compilation error when trying to wrap `merge` #125

Closed Invertisment closed 2 years ago

Invertisment commented 2 years ago

Is this intended?

When I try to do this (to reverse my order of reduction) then I can't do it:

(defn merge-reverse [a b]
  (a.merge b a))
(comment (merge-reverse {} {:hi :there}))

This message appears:

; eval (current-form): (merge-reverse {} {:hi :there})
; attempt to call field 'merge' (a nil value)

My workaround is to use this (when reducing with merge):

(defn reduce-reverse [f init xs]
  (a.reduce (fn [a b] (f b a)) init xs))
Olical commented 2 years ago

Your inclusion of aniseed.core under the alias a is being overridden by your argument to the function a. So you need to either change your aniseed.core alias or your function argument name. Unlike Clojure etc there is no separate idea of modules, so a require will clash with a variable name. Unlike Clojure where [foo :as bar] will not collide bar/... with an argument name.

Invertisment commented 2 years ago

Ooof. Thanks. I tried to pass this function into reduce and it didn't work either. But yes, I was using that same a name. One letter imports are not a good idea.