I found an answer to my question, see below. Suggestions for improvements are welcome!
(defn showeval [form] (let [[f & args] form] (str (clojure.string/trim-newline (with-out-str (clojure.pprint/pprint (map #(if (list? %1) `'~%1 %1) form)))) " => " (or (pr-str (apply (resolve f) args)) "nil")))) (doseq [op '(first next rest)] (doseq [cs '((nil) (() (1 2 3)) ([] [1 2 3]) ({} {:a 1 :b 2 :c 3}) (#{} #{1 2 3}))] (doseq [c cs] (println (showeval `(~op ~c)))))) Prints: (first nil) => nil (first '()) => nil (first '(1 2 3)) => 1 (first []) => nil (first [1 2 3]) => 1 (first {}) => nil (first {:a 1, :b 2, :c 3}) => [:a 1] (first #{}) => nil (first #{1 3 2}) => 1 (next nil) => nil (next '()) => nil (next '(1 2 3)) => (2 3) (next []) => nil (next [1 2 3]) => (2 3) (next {}) => nil (next {:a 1, :b 2, :c 3}) => ([:b 2] [:c 3]) (next #{}) => nil (next #{1 3 2}) => (3 2) (rest nil) => () (rest '()) => () (rest '(1 2 3)) => (2 3) (rest []) => () (rest [1 2 3]) => (2 3) (rest {}) => () (rest {:a 1, :b 2, :c 3}) => ([:b 2] [:c 3]) (rest #{}) => () (rest #{1 3 2}) => (3 2) Le jeudi 13 novembre 2014 13:35:25 UTC+1, Sébastien Bocq a écrit : > > Hi, > > I would like to display the results of applying first, next, rest to > different collections. In the end, I'd like to create an org table with the > forms and their result. > > I began simply with this: > > (doseq [op '(first next rest)] > (doseq [cs '((nil) > ('() '(1 2 3)) > ([] [1 2 3]) > ({} {:a 1 :b 2 :c 3}) > (#{} #{1 2 3}))] > (doseq [c cs] > (println (showeval `(~op ~c)))))) > > To print: > > (first nil) => nil > (first '()) => nil > (first '(1 2 3)) => 1 > ... > > Question: how would you implement showeval? > > Thanks, > Sébastien > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.