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

+1 vote
in ClojureScript by

It seems instances of MetaFn have a problem with high arity invocations.

(def foo ^:foo (fn [& args]) )

(foo 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
;; => nil

(foo 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
;;=> Execution error (Error) at (<cljs repl>:1). 1 is not ISeqable

(foo 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
;;=> Execution error (Error) at (<cljs repl>:1). Invalid arity: 22

This shows up in Ornament when people have many children in a Hiccup component https://github.com/lambdaisland/ornament/issues/4

1 Answer

0 votes
by

FYI, functions are not something that are stated as supporting metadata so you are in a somewhat undefined area. For reference:

It is true that some function implementations support metadata for some purposes, but I don't think it's something you should generally expect to work everywhere necessarily.

Vars also (obviously) support metadata and you could have placed it there in the example above which would have been fine.

I guess my point is that if the lib in question relies on putting metadata on functions, that seems questionable to me (unless it's an IFn impl made by the library).

by
Thanks, that's good to know. It's interesting then that clojurescript has a `MetaFn` and an explicit check for functions in `meta`.

As a workaround this seems to work:

```
 (def xxx (specify! (fn [& args] (count args)) cljs.core/IMeta (-meta [_] {:foo "bar"})))
```
...