在《使用 Clojure 进行 Web 开发》一书中说,代码
(defn registration-page []
(layout/common
(form-to [:post "/register"]
(label "id" "screen name")
(text-field "id")
[:br]
(label "pass" "password")
(password-field "pass")
[:br]
(label "pass1" "retype password")
(password-field "pass1")
[:br]
(submit-button "create account"))))
可以使用辅助函数重写如下:
(defn control [field name text]
(list (on-error name format-error)
(label name text)
(field name)
[:br]))
(defn registration-page []
(layout/common
(form-to [:post "/register"]
(control text-field :id "screen name")
(control password-field :pass "Password")
(control password-field :pass1 "Retype Password")
(submit-button "Create Account"))))
我的问题是:在替代代码中,为什么参数名称的值不是字符串?例如,为什么是 (control text-field :id "screen name"),而不是 (control text-field "id" "screen name") ?