Bug? Adding meta data to a function changes the function type which seems to break with-meta contract

17 views
Skip to first unread message

Maxim Bazhenov

unread,
Oct 28, 2019, 1:26:48 PM10/28/19
to ClojureScript
Hello,

I'm working on a clojurescript project which uses XState javascript library. XState is a state chart and final state machine library which I'm trying to adopt to work alongside re-frame. I define state chart transition actions using clojurescript and pass them to javascript world. Recently I've stumbled over a situation that I can't pass a function from clojurescript to XState/javascript if the function have metadata attached. Javascript code can't invoke such a function, because it's not a javascript funciton anymore, but a clojurescript entity implementing IFn protocol. The reason is that the result of
(with-meta (fn [x]...))
doesn't return a function which external javascript code can call, but an object of cljs.core/MetaFn type, which I think is against (with-meta) contract.

with-meta documentation says:
cljs.core/with-meta
 [o meta]
  Returns an object of the same type and value as obj, with
  map m as its metadata.

So I expect the object of the same type, such that
(= (type #()) (type (with-meta #() {:a :b})))
holds, as well as
(= true (instance? js/Function (with-meta #() {:a :b})))

So the question is, have I found a bug?

Reply all
Reply to author
Forward
0 new messages