3 ms·
The Clojure community tends to be in favor of using core data structures and functions to compose, simple, reusable things, instead of using syntactic abstracti
by apgwoz 16y ago
The Clojure community tends to be in favor of using core data structures and functions to compose, simple, reusable things, instead of using syntactic abstraction because it's there (like some people encourage). Clojure code uses macros, but most of the time it's to tie stuff together into a prettier, more convenient interface--sometimes to remove repetitive code of course.
So, why not use macros all the time? Not because they're hard to understand--you can always expand them to see what they do (or ask the original author to document it), but because they are hard to compose, and reuse. Sure, they can be used in special case a, b and c, but give me a higher order operators, and suddenly I can compose an opus.
- rincewind 16y agoDoes this port to an imaginary arc-on-clojure framework look more readable to you? (arc/with-page-renderer (fn [content & options] (hiccup/html [:body content])) (arc/defop "/said" [request] (arc/aform :form [ [:input {:name "foo"}] [:input {:type "submit"}] ] :handler (fn [form-result] (arc/onlink :text "click here" :handler (fn [_] (str "you said: " (:foo form-result))))))))
- swah 16y agoI was writing functions like this (Clojure): (defn set-password [{"login" login "password" password}] ...) Ok, Clojure de-structuring syntax already makes things pretty terse: the function receives and de-structures a map. But for functions with many args it was looking repetitive, so I wrote defn* which lets me write the same as: (defn* set-password [login password] ...) So, do you think this is a fair use of macros? It has the disadvantage of hiding the fact that the function actually receives a map, of course (but I'm a solo programmer here, trying to save keystrokes).