Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> I wonder what Clojure programmers do here.

About the same.

    (defn message [text & {:keys [style color]}]
      ...)

    (message "Text" :style :bold :color :red)
Because typing those extra two brackets is apparently too much trouble.


I would just accept the hash, I think a lot of us prefer it to the pseudo keyword args.

    (defn message [text {:keys [style color]}] ...)
    (message "Text" {:style :bold :color :red})
To the person asking, that {:keys [style color]} is destructuring, it's not required, but it's nice, it's equivalent to doing:

    (defn message [text opts]
       (let [style (:style opts)
             color (:color opts)]
          ...))


I can't say I expected it to look like that.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: