user1311390
user1311390

Reputation:

Baffling ClojureScript Error

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?

Upvotes: 5

Views: 1593

Answers (3)

Kris Jenkins
Kris Jenkins

Reputation: 4210

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!

Upvotes: 20

Korny
Korny

Reputation: 2028

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".)

Upvotes: 0

amalloy
amalloy

Reputation: 91907

(def sprintf format) seems easier.

Upvotes: 1

Related Questions