jzon icon indicating copy to clipboard operation
jzon copied to clipboard

Add with-writer-to-string

Open kilianmh opened this issue 2 years ago • 3 comments

I think it would be nice to have the macro with-writer-to-string (similar to the one in com.inuoe.jzon-tests) included and exported from com.inuoe.jzon. The same is probably also the case for a with-writer-to-string* macro.

Or is there a specific reason why you didn't include it @Zulu-Inuoe ?

kilianmh avatar Aug 28 '23 22:08 kilianmh

No specific reason, but I don't think it's super valuable to add since it'd only save people 1 line of code and have us have to support a new interface In the tests I define that macro because I am repeatedly calling the writer fns with a fresh writer, but in a normal use-case, people will likely have 1 or 2 calls to with-writer in which case they can simply

(with-output-to-string (s)
  (jzon:with-writer (writer :stream s)
    ...))

I'll leave this open in case anyone feels strongly about it.

Zulu-Inuoe avatar Aug 29 '23 22:08 Zulu-Inuoe

Somebody brought up today that with-writer could take :stream nil to mean "return a string", which I like better than this since it means one less function, and nil doesn't mean anything else there anyways

Zulu-Inuoe avatar May 07 '24 13:05 Zulu-Inuoe

+1

boogsbunny avatar May 07 '24 14:05 boogsbunny