Re: new in duck-streams: with-out-writer / with-in-reader

2009-03-28 Thread Dex Wood

Do you think it would be useful to add the ability to append to a
file?

On Mar 28, 9:36 pm, Stuart Sierra  wrote:
> Following a discussion from a few days ago, I've added two new macros
> to clojure.contrib.duck-streams:
>
> (defmacro with-out-writer
>   "Opens a writer on f, binds it to *out*, and evalutes body."
>   [f & body]
>   `(with-open [stream# (writer ~f)]
>      (binding [*out* stream#]
>       �...@body)))
>
> (defmacro with-in-reader
>   "Opens a PushbackReader on f, binds it to *in*, and evaluates body."
>   [f & body]
>   `(with-open [stream# (PushbackReader. (reader ~f))]
>      (binding [*in* stream#]
>       �...@body)))
>
> -Stuart Sierra
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: new in duck-streams: with-out-writer / with-in-reader

2009-03-28 Thread Parth



On Mar 29, 7:36 am, Stuart Sierra  wrote:
> Following a discussion from a few days ago, I've added two new macros
> to clojure.contrib.duck-streams:
>
> (defmacro with-out-writer
>   "Opens a writer on f, binds it to *out*, and evalutes body."
>   [f & body]
>   `(with-open [stream# (writer ~f)]
>      (binding [*out* stream#]
>       �...@body)))
>
> (defmacro with-in-reader
>   "Opens a PushbackReader on f, binds it to *in*, and evaluates body."
>   [f & body]
>   `(with-open [stream# (PushbackReader. (reader ~f))]
>      (binding [*in* stream#]
>       �...@body)))
>
> -Stuart Sierra

This is very useful. Thank you :)

--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



new in duck-streams: with-out-writer / with-in-reader

2009-03-28 Thread Stuart Sierra

Following a discussion from a few days ago, I've added two new macros
to clojure.contrib.duck-streams:

(defmacro with-out-writer
  "Opens a writer on f, binds it to *out*, and evalutes body."
  [f & body]
  `(with-open [stream# (writer ~f)]
 (binding [*out* stream#]
   ~...@body)))

(defmacro with-in-reader
  "Opens a PushbackReader on f, binds it to *in*, and evaluates body."
  [f & body]
  `(with-open [stream# (PushbackReader. (reader ~f))]
 (binding [*in* stream#]
   ~...@body)))


-Stuart Sierra
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---