On Mon, Jan 24, 2011 at 8:42 PM, Nick Brown <nwbr...@gmail.com> wrote: > Ugly? Aww, I thought the ^ metadata looked kinda cute... > > It is a bit awkward that defn- exists and not def-, but it seems defs > are not going to be as common as defns (though I'll admit I haven't > written or read enough complex idiomatic Clojure code to know for > sure). And if you really want to be consistent you would probably > also want defmulti-, defmacro-, defstruct-, defprotocol-, etc. And > I'll have to stop using tiny fonts to read Clojure code so I can tell > if something is private or not. > > If we really wanted to make it easy to write private functions, > variables, etc, I would personally prefer a macro like (private) for > which all forms inside would be made private. Like > (private > (def my-private-foo (...)) > (defn my-private-bar [] (...))) > > Not only does that seem more clear, it would encourage the private > stuff to be separate from public stuff.
First stab at it: (defmacro private [& forms] (apply list 'do (map (fn [form] (cond (not (coll? form)) form (or (vector? form) (map? form) (set? form)) form (< (count form) 2) form :else (let [[d n & r] form] (cond (not (symbol? d)) form (not (symbol? n)) form (not (.startsWith (str d) "def")) form :else (apply list d (vary-meta n assoc :private true) r))))) forms))) It seems to work. It just outputs all the enclosed forms in a "do", except for those that start (defsomething somesymbol ...), where it vary-metas a :private true onto somesymbol. So, the form must start with two symbols and the first symbol must start with "def". -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en