Clojure icon indicating copy to clipboard operation
Clojure copied to clipboard

Unreadable forms should be wrapped in #<...>

Open brandonbloom opened this issue 11 years ago • 2 comments

Right now, if I evaluate something that returns a function, the little result just shows "fn". You can't tell if it's a symbol or whatever. Seems like functions are special cased to render that way, since *ns* shows a normal toString representation for a namespace. Ideally, there would be a way to see the string representation of the function, since Clojure goes to the trouble to make sure names are in there when possible, but minimally, it should print as #<fn> so it's visually distinct and known unreadable.

brandonbloom avatar Jan 10 '14 21:01 brandonbloom

Agree that we should have a toggle source command that looks up the current symbol and displays a widget - similar to the toggle-doc command. I don't have a strong opinion on fn vs #<fn>.

cldwalker avatar Oct 22 '14 22:10 cldwalker

just for the record in case someone wants to work on this. Here are the relevant line:

(defn clean-serialize [res & [opts]]
  (binding [*print-length* (or (:print-length opts) *print-length* 1000)]
    (cond
     (fn? res) 'fn
     (var? res) (if-not (:allow-var? opts)
                  res
                  (str res)
                  )
     (nil? res) "nil"
     (false? res) "false"
     (and (instance? clojure.lang.Atom res)
          (:result opts)) (str "atom[" @res "]")
     (instance? clojure.lang.Atom res) (str "atom")
     ;(is-non-clojure? res) (str res)
     (and (string? res) (:verbatim opts)) res
     :else (pr-str res))))

I guess something like (fn? res) (clojure.main/demunge res) should do the job.

carocad avatar May 12 '16 11:05 carocad