Ken,
> Well for one thing it's printing stuff at macroexpansion time.
I don't think this the issue. I have tried this in Clojure's REPL and
it worked fine
(defmacro run-with-msg [msg & body]
(do
(.write *out* (format "%s..." msg))
(.flush *out*))
`(let [res# ~@body]
(println "done")
res#))
Most likely it is an environment issue - I am using Vimclojure.
On Mar 2, 9:26 am, Ken Wesson <[email protected]> wrote:
> On Wed, Mar 2, 2011 at 8:54 AM, Vitaly Peressada <[email protected]> wrote:
> > I want to have a way to print progress message before and after
> > invoking a function/expression. Came up with this macro
>
> > (defmacro run-with-msg [msg & body]
> > (doto *out*
> > (. write (format "%s..." msg))
> > (. flush))
> > `(let [res# ~@body]
> > (println "done")
> > res#))
>
> > user=> (run-with-msg "Working" (Thread/sleep 2000))
> > Working...done
> > nil
>
> > But msg is not printed by itself. In example above I don't see
> > "Working...". As you can see I tried to print directly to *out*
> > (instead of printf) and explicitly flushing *out* with no avail.
>
> > Any idea what is going on here?
>
> Well for one thing it's printing stuff at macroexpansion time.
>
> Try:
>
> (defmacro run-with-msg [msg & body]
> `(do
> (.write *out* (format "%s..." ~msg))
> (.flush *out*)
> (let [res# ~@body]
> (println "done")
> res#)))
>
> user=> (run-with-msg "Working" (do (Thread/sleep 2000) 42))
> Working...done
> 42
> user=>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
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