5

Code

(defn sprintf [& args]
  (with-out-str
    (apply printf args)
    *out*))

Error

(Chrome)

Uncaught TypeError: Cannot read property 'cljs$lang$maxFixedArity' of undefined 

Question:

What am I doing wrong?

0

3 Answers 3

20

The error:

Uncaught TypeError: Cannot read property 'cljs$lang$maxFixedArity' of undefined

...perhaps history's most baffling error message, actually means:

You're calling apply on a function that doesn't exist (or hasn't been required).

Rock on, future Googlers!

Sign up to request clarification or add additional context in comments.

3 Comments

There should be more than upvotes available for people who answer with the full explanation long after an answer is accepted because you know people will arrive here from Google searches. You just likely saved me a bunch of time.
Any thoughts on how to fix this @kris-jenkins? I'm actually using Meteor + ClojureScript, but maybe your thoughts will help. At this point I have an empty Meteor project and am getting this error.
@JohnAllen You need to find which function it was expecting to be able to call. The two ways I do that are, checking the stack trace (if you have source maps enabled you should be able to find the caller); and a clean rebuild (which will often trigger a compiler warning).
1

(def sprintf format) seems easier.

3 Comments

Today I understand how Alexander the Great would have attacked Clojure code.
@amalloy Even though you've provided a good workaround, is there a way to fix the original problem, other than this workaround? Thanks.
Nope. I have no clojurescript experience; all I can tell from the provided code is that somewhere he's calling undefined as if it were a function.
0

I don't get the error you saw, I get an error "No *print-fn* fn set for evaluation environment".

If you dig through the source at https://github.com/clojure/clojurescript/blob/master/src/cljs/cljs/core.cljs you'll find this message in the docs for *print-fn* :

"Each runtime environment provides a diffenent way to print output. Whatever function *print-fn* is bound to will be passed any Strings which should be printed."

So I suggest you play around with *print-fn* - or as @amalloy suggested, just use 'format' directly.

(incidentally if you look at https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure it indicates "*out* is currently not implemented".)

1 Comment

this is because you didn't set *print-fn*, not because of an error in the posted code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.