On Aug 31, 2008, at 4:34 AM, Frantisek Sodomka wrote:

> To extend this idea little further, lets define "code sections":

I like the idea a lot. I believe the "Aspect oriented programming"  
folks call these kinds of "outside the main flow" items "aspects". I  
think it would be good to have aspects defined in each namespace  
rather than globally.  (One might also argue for "in addition to"  
globally.)

Here's an "aspects.clj" that resolves '+aspects+ at "compile time" in  
the namespace where the function that uses it is defined:

        (ns aspects)

        (defmacro aspect [tag & body]
          (when-let aspects# (ns-resolve *ns* '+aspects+)
            (when (aspects# tag)
              (cons 'do body))))

And a test:


        (ns aspects.test
         (:use aspects))

        (def +aspects+ #{:debug :log0 :log1})

        (defn myfn [x]
          (aspect :debug
                  (printf "debugging info... (x = %s)\n" x))
          (aspect :log0
                  (println "logging info..."))
          (aspect :log1
                  (println "detailed logging info..."))
          (* 2 x))

        (myfn 10)

And a run:

        user=> (require 'aspects.test :reload-all)
        debugging info... (x = 10)
        logging info...
        detailed logging info...
        nil
        user=>

The code is written such that if +aspects+ is not defined in a  
namespace, calls to "aspect" in that namespace generate no code. One  
cool thing this leverages in Clojure is that +aspects+ can be either a  
set (as shown) or a map from keyword to (generalized) boolean.

> Latest addition for libs to boot.clj also has this pattern, when  
> using *loading-verbosely* flag.

That's a little different in that *loading-verbosely* is intended to  
be dynamically bound at runtime rather than baked in at compile time.  
I recall Rich suggesting recently that he prefers to see the * prefix  
and suffix on symbols that are intended to be dynamically bound. Here  
I'm suggesting that a + prefix and suffix be used for compile-time  
constants. I've seen precedent for in Common Lisp.

> Any comments welcome, Frantisek

I think this is a fine idea that deserves some more discussion and  
would make a good addition to clojure-contrib. Are you signed up to  
contribute there yet?

--Steve


--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to