This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-21
Channels
- # announcements (2)
- # asami (8)
- # aws (4)
- # beginners (32)
- # calva (12)
- # cider (72)
- # clj-kondo (16)
- # clojure (11)
- # clojure-germany (2)
- # clojure-italy (4)
- # clojure-serbia (2)
- # clojurescript (26)
- # data-oriented-programming (8)
- # datomic (9)
- # deps-new (17)
- # eastwood (4)
- # emacs (20)
- # fulcro (18)
- # funcool (1)
- # graalvm (8)
- # leiningen (12)
- # lsp (34)
- # malli (25)
- # meander (4)
- # membrane (4)
- # off-topic (153)
- # practicalli (1)
- # releases (2)
- # remote-jobs (3)
- # rewrite-clj (77)
- # ring (5)
- # shadow-cljs (108)
- # spacemacs (12)
- # tools-deps (9)
- # vscode (11)
- # xtdb (4)
Hey guys, i've been trying to understand ring-clojure lib. I was reading the through the examples and ran into the form parameters one. (defn page [name] (str "<html><body>" (if name (str "Nice to meet you, " name "!") (str "<form>" "Name: <input name='name' type='text'>" "<input type='submit'>" "</form>" "</body></html>")))) (defn handler [{{name "name"} :params}] (-> (response (page name)) (content-type "text/html"))) (def app (-> handler wrap-params)) (run-jetty app {:port 8080}) Im guessing this is mostly a clojure itself question opposed to a ring one, but I dont really know what [{{name "name"} :params}] is doing. Could anyone explain? Thanks in advance!!
@U015CTPB4HZ that's associative destructuring, which you can read about here https://clojure.org/guides/destructuring
in this case you're having a map passed in, which will have a value under the :params
key, which itself will be a map with a value under the "name"
key, which is being bound to name
Thank you, ill read into it some more.