str of an empty list is not "()"

Description

The str of an empty list is surprisingly not "()". This is inconsistent with the result for the empty map {} or empty vector (). It would be convenient if `(str ())` returned "()". The work-around is to use `pr-str`, which is arguably the "correct" thing to do. However, there doesn't seem to be any reason that Clojure couldn't return "()".

Patch: clj-1653-3.patch

Screened by: Alex Miller

Environment

None

Attachments

3

Activity

Show:

Alex Miller October 9, 2015 at 3:13 PM

Updated -3 patch to apply to master, no semantic changes, attribution retained.

Alex Miller April 29, 2015 at 8:17 PM

Added -2 patch just to fix trailing whitespace warnings, identical otherwise.

Michael Blume February 2, 2015 at 11:59 PM

This really makes empty list seem like a special case.

Steve Miner February 2, 2015 at 11:09 PM

I agree in principle that pr-str is the right thing to use. I will counter the Slippery Slope argument by invoking the Principle of Least Astonishment. My argument for the proposed patch is that () is a common value and the current behavior is inconsistent with similar empty values, {} and []. I think it would be convenient and useful, especially for beginners, to fix just this one case of the empty list. On the other hand, it's a minor issue so I won't push it.

Nicola Mometto February 2, 2015 at 10:03 PM

Not sure how this is different from

pr-str works fine on both () and (range 10) btw.

Completed

Details

Assignee

Reporter

Approval

Ok

Patch

Code and Test

Priority

Affects versions

Fix versions

Created February 2, 2015 at 9:30 PM
Updated October 13, 2015 at 3:37 AM
Resolved October 13, 2015 at 3:37 AM