When storing a function in a var's metadata, is behaves counterintuitively (at least to me).
Is this a bug or the intended behavior? If the latter, what is the reasoning?
Given the following def
:
(def
^{:fn-in-meta (fn [a b] (+ a b))}
my-var
:value)
In Clojure things work as expected, one can get the function out of the metadata and it is still a regular function:
; clj
(-> #'my-var
meta
:fn-in-meta)
;; => #function[myns/fn--27244]
; clj
(-> #'my-var
meta
:fn-in-meta
type)
;; => myns$fn__27244
In clojurescript however, doing the same seems to result in some semi-compiled state that looks similar to a macroexpansion.
; cljs
(-> #'my-var
meta
:fn-in-meta)
;; => (fn [a b] (+ a b))
; cljs
(-> #'my-var
meta
:fn-in-meta
type)
;; => cljs.core/List
Finally, note that adding metadata to another object, such as a vector behaves normally in noth languages.
; cljs
(->> {:fn-in-meta (fn [a b] (+ a b))}
(with-meta [])
meta
:fn-in-meta
type)
;; => #object[Function]
; clj
(->> {:fn-in-meta (fn [a b] (+ a b))}
(with-meta [])
meta
:fn-in-meta
type)
;; => myns$eval27282$fn__27283