yaml

conao3 2024-08-25T14:20:12.113249Z

@conao3 has joined the channel

conao3 2024-08-25T14:25:47.578249Z

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?

lread 2024-08-25T15:06:55.983199Z

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"

conao3 2024-08-25T15:17:12.471509Z

wow! walk/prework is great, thanks!

conao3 2024-08-25T15:21:08.144649Z

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}})

lread 2024-08-25T15:49:02.974519Z

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?

conao3 2024-08-25T15:55:41.784409Z

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.

lread 2024-08-25T16:12:13.793489Z

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.

👍 1
conao3 2024-08-25T16:15:37.376299Z

OK, I will. And thank you for being so helpful to your library. Thanks again!

lread 2024-08-25T16:29:42.012539Z

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.

👍 1
lread 2024-08-25T16:30:27.463449Z

Note there is also #clj-yaml for clj-yaml specific questions.

conao3 2024-08-25T16:35:15.305539Z

Thanks for sharing your channel, I'm new to clojurian-slack and am lost with so many channels lol.

lread 2024-08-25T16:43:57.818809Z

Welcome aboard! I expect you'll find the Clojure community as wonderful, helpful, and friendly as I do!

🎉 1
conao3 2024-08-26T12:18:48.423299Z

FYI: issue opened: https://github.com/clj-commons/clj-yaml/issues/133

👍 1