@conao3 has joined the channel
user> (require '[clj-yaml.core :as yaml])
user> (yaml/generate-string {:arglists '([] [x])})
"arglists:\n- []\n- - !!clojure.lang.Symbol {}\n"
generate-string for symbol, it outputs !!clojure.lang.Symbol {}.
I want that it just outputs as a string. Can I achieve this?Would this work for you?
(require '[clj-yaml.core :as yaml]
'[clojure.walk :as walk])
(defn prep [form]
(walk/prewalk (fn [item] (if (symbol? item)
(str item)
item))
form))
(-> {:arglists '([] [x])} prep yaml/generate-string)
;; => "arglists:\n- []\n- [x]\n"wow! walk/prework is great, thanks!
https://github.com/clj-commons/clj-yaml/blob/master/doc/01-user-guide.adoc#unknown-tags
your solution is great for workaround, but I maybe request like this unknown tags arg.
My assumption would be an API like this
(yaml/generate-string {:arglists '([] [x])} {:dumper-options :serialize-tag {clojure.lang.Symbol str}})Ya, I guess we could consider supporting something like that... clj-yaml is a light wrapper over SnakeYAML, and SnakeYAML has a Representer that (I think) allows for the concept you are suggesting.
But... to play the devil's advocate, why not just pre-convert? Isn't that simpler?
honestly, my sexp is loaded from another source.
(defn fetch-index []
(slurp ""))
(def index (read-string (fetch-index)))
;; index
;; => {:namespaces
;; ({:doc "Fundamental library of the Clojure language",
;; :name "clojure.core",
;; :wiki-url "",
;; :source-url
;; ""})
;; :vars
;; ({:raw-source-url
;; "",
;; :added "1.2",
;; :name "*",
;; :file "src/clj/clojure/core.clj",
;; :source-url
;; "",
;; :line 1010,
;; :var-type "function",
;; :arglists ([] [x] [x y] [x y & more]),
;; :doc
;; "Returns the product of nums. (*) returns 1. Does not auto-promote\nlongs, will throw on overflow. See also: *'",
;; :namespace "clojure.core",
;; :wiki-url
;; ""})}
:arglists is comes from this.
I wanted to generate yaml from this sexp.
Therefore, being able to specify serialization of the data rather than transforming it suited my intuition.
Also, it would perform better if I could customize the functions used during serialization, rather than having to walk through all the leaves and change them before serializing.Ok, thanks for your rationale. If you feel this feature would be helpful to you and others please feel free to https://github.com/clj-commons/clj-yaml/issues.
OK, I will. And thank you for being so helpful to your library. Thanks again!
Thanks for dropping by, if you have more questions, drop by again! Clj-yaml was adopted by clj-commons... I am just a humble co-foster-parent of a library useful to the Clojure community.
Note there is also #clj-yaml for clj-yaml specific questions.
Thanks for sharing your channel, I'm new to clojurian-slack and am lost with so many channels lol.
Welcome aboard! I expect you'll find the Clojure community as wonderful, helpful, and friendly as I do!
FYI: issue opened: https://github.com/clj-commons/clj-yaml/issues/133