Robert Pfeiffer wrote:
> Hello,
>
> Is there a benefit in implementing this as a macro instead of a
> function? The function version would be very simple:
>
> (defn returning [returnval & body]
>    returnval)
>
>
>   

Well no, the forms are evaluated. It's usefull for side effects.

user> (def *bleh* (ref nil))
user> (prog1
        (dosync (ref-set *bleh* 3))
        (println (str "bleh is now " @*bleh*)))
bleh is now 3
3

A function would work :

(defn progz [return-value do-also-fn]
  (do-also-fn)
  return-value)

user> (progz (+ 1 3)
        (fn []
          (prn "hello")
          (prn "i'm evaluated")))
"hello"
"i'm evaluated"
4

But it's not as terse.

Sacha

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to [email protected]
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