Groovy has a safe navigation operator. Yes, this probably enables Law  
of Demeter violations, but it is darn useful when you are dealing with  
existing Java APIs that required lots.of.dotted.notation.

I would like to have this in Clojure. Anybody else like it?

(defmacro ?.
   "like .. but drops out on null object"
   ([x form]
      `(. ~x ~form))
   ([x form & more]
      `(if-let x# (. ~x ~form) (.? x# [EMAIL PROTECTED]))))

BTW, my use case was (?. someClass getProtectionDomain getCodeSource  
getLocation). This needs to drop out for null whenever someClass comes  
from a ClassLoader that cannot report its location.

Stuart

P.S. A cooler name than "save navigation operator" would be welcome,  
and I am not wedded to the Groovy syntax. I initially misremembered it  
as ".?" which I think I may like better.

--~--~---------~--~----~------------~-------~--~----~
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