Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by

cljs.core.Var implements IWithMeta, which differs from vars in Clojure which do not have immutable metadata. with-meta shouldn't be supported on vars, only alter-meta! should.

Unlike Clojure, ClojureScript doesn't use dynamic dispatch for alter-meta!. The implementation of cljs.core/alter-meta! will happily mutate the metadata of any object with a "meta" field, even if it's not a ref/var/whatever identity. This means that if you want to have metadata on your custom type, you have to have a "meta" field, rather than implement methods for getting/changing metadata. That's not too ideal, but doesn't present an immediate problem for me.

The reason I care about IWithMeta is that I need to distinguish metadata handling between values and reference types. Ideally, there would be an IAlterMeta protocol as well, but (and (satisfies? IMeta x) (not (satisfies? IWithMeta x))) suffices. On the JVM, the same can be done with IMeta and IObj.

2 Answers

0 votes
by

Comment made by: mfikes

Unit test failure:

ERROR in (test-1248) (core-advanced-test.js:64:417) Uncaught exception, not in assertion. expected: nil actual: #object[Error Error: No protocol method IWithMeta.-with-meta defined for type object: #'cljs.core/first]

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-2398 (reported by bbloom)
...