Welcome! Please see the About page for a little more info on how this works.

0 votes
in Macros by

I think it would be useful to add a macro which redirects the standard output to *err*:

(with-err-out [& body]
  `(binding [*out* *err*]
     ~@body))

1 Answer

+3 votes
by

A counterpoint: (with-err-out (do-stuff)) is hardly shorter or more readable than (binding [*out* *err*] (do-stuff)).

by
I agree the macro doesn't do much - e.g. `with-out-str` does a little more than that, but it certainly helps and I don't think it makes things more complicated.
by
IMO it does since name proliferation results in extra cognitive load. Sometimes it's justified, but I wouldn't say so in this case. I'd even argue that things like `if-not` and `when-not` are not really needed.
by
Ah, misread that you were talking about `with-out-str` this time. That function *is* justified at the very least because it deals with interop. Apart from that, I'd say it's a much, much more frequently used thing than redirecting stdout to stderr.
by
I get the point, but still, I think there are situations where you might need it. When I want to do some quick debugging, writing the macro name is much easier than binding with the binding vector. It saves some time.

P.S.: I have linked this question on slack, I would like to discuss it a little more with other people, I think this is a thing on which everyone could have a different opinion.
by
In my experience, wanting to capture stderr by redirecting *err* to *out* has been more common than the other way around, but with binding being available I've never felt the need for a macro, so I agree with Eugene here that this is not needed.
by
I agree, the macro would require me to look at the source code to understand what was happening, while just using the binding form directly takes no more room and is transparent about what it does.
by
Agree.




P.S.: I cannot send messages shorter than 12 chars lol
...