For socket repl: request redirectable *err* var

8 views
Skip to first unread message

Stephen C. Gilardi

unread,
Sep 28, 2008, 1:28:11 PM9/28/08
to Clojure
For a socket repl, I'd like to have error output sent across the wire as well as normal output. Clojure currently provides vars (*in* and *out*) that allow a thread to redirect input and output. I suggest a new var *err* which allows redirecting error output as well.

I can mostly do this without a change to Clojure by using my own alternative to Repl.java, but there are several instances in Clojure where System.err is accessed directly. If those were made indirect through a new *err*, one could reliably redirect all of *in*, *out*, and *err*.

Here's the *err* definition I suggest for RT.java:

final static public Var ERR =
Var.intern(CLOJURE_NS, Symbol.create("*err*"),
          new PrintWriter(new OutputStreamWriter(System.err, UTF8), true));

(A PrintWriter with auto-flush.)

I think PrintWriter is a good choice because Throwable offers a method to dump stack traces to a PrintWriter.

--Steve

Colin Walters

unread,
Sep 28, 2008, 3:56:24 PM9/28/08
to Clojure
On Sep 28, 1:28 pm, "Stephen C. Gilardi" <squee...@mac.com> wrote:

> final static public Var ERR =
>                 Var.intern(CLOJURE_NS, Symbol.create("*err*"),
>                            new PrintWriter(new OutputStreamWriter(System.err, UTF8),  
> true));

Is it right to put UTF8 there? For one of my Python programs I went
to a fair bit of work to support both Chinese Windows and ISO-8859-*
Linux for output streams. The latter might be largely ignorable, the
former probably less so.

.Bill Smith

unread,
Sep 28, 2008, 4:24:38 PM9/28/08
to Clojure
Presumably you want to use whatever encoding OUT (or whatever it's
called) uses.

Bill

Stephen C. Gilardi

unread,
Sep 28, 2008, 4:45:56 PM9/28/08
to clo...@googlegroups.com
Some time ago there was discussion about making UTF-8 the default encoding for Clojure I/O and that's now implemented. It's only a default though. The code I proposed would establish the root binding for the *err* var. Within any thread (including the main thread), it could be bound to something else temporarily using clojure/bind or set to something else until changed again using the set! special form.

--Steve

Thorsen Eric

unread,
Sep 29, 2008, 9:24:31 AM9/29/08
to clo...@googlegroups.com
I would love to see this change as well.

Eric

Craig McDaniel

unread,
Sep 30, 2008, 12:25:45 AM9/30/08
to Clojure
Yes, I'd like to see *err* added too. I did my own *err* for a custom
REPL and was surprised it wasn't already part of the environment just
like *out*.

On Sep 29, 9:24 am, Thorsen Eric <ethor...@thortech-solutions.com>
wrote:

Stephen C. Gilardi

unread,
Oct 6, 2008, 8:37:09 PM10/6/08
to clo...@googlegroups.com
Rich,

Would you accept a patch to implement this?

--Steve

Rich Hickey

unread,
Oct 6, 2008, 8:42:26 PM10/6/08
to Clojure


On Oct 6, 8:37 pm, "Stephen C. Gilardi" <squee...@mac.com> wrote:
> Rich,
>
> Would you accept a patch to implement this?
>

Sure - thanks.

Rich

Stephen C. Gilardi

unread,
Oct 6, 2008, 11:36:34 PM10/6/08
to clo...@googlegroups.com
It's either attached to this message or uploaded to the group as:

redirectable-stderr.patch

Thanks,

--Steve

redirectable-err.patch

Rich Hickey

unread,
Oct 8, 2008, 7:42:19 AM10/8/08
to Clojure
Patch applied - thanks!

Rich
Reply all
Reply to author
Forward
0 new messages