The empty map literal is read as a different map each time

Description

As reported here (https://groups.google.com/forum/?hl=en#!topic/clojure-dev/n83hlRFsfHg), the empty map literal is read as a different map each time.

user=> (identical? (read-string "{}") (read-string "{}")) false

Making the reader return the same empty map when it reads an empty map is expected to improve some memory efficiency, and also lead to consistency with the way other collection literals are read in.

user=> (identical? (read-string "()") (read-string "()")) true user=> (identical? (read-string "[]") (read-string "[]")) true user=> (identical? (read-string "#{}") (read-string "#{}")) true

Cause: LispReader calls RT.map() with an empty array when it reads an empty map, and RT.map() in turn makes a new map unless its argument given is null.

Approach: make RT.map() return the same empty map when the argument is an empty array as well, not only when null

Patch: 0002-make-the-reader-return-the-same-empty-map-when-it-re.patch

Screened by: Alex Miller

Environment

None

Attachments

2
  • 01 Mar 2014, 08:47 AM
  • 01 Mar 2014, 06:02 AM

Activity

Show:

Shogo Ohta March 1, 2014 at 8:59 AM

Sorry, the patch 0001-make-the-reader-return-the-same-empty-map-when-it-re.patch didn't work.

The updated patch 0002-make-the-reader-return-the-same-empty-map-when-it-re.patch works, but I'm afraid it'd be beyond the scope of this ticket since it modifies RT.map() behavior a bit.

Completed

Details

Assignee

Reporter

Approval

Ok

Patch

Code

Priority

Affects versions

Fix versions

Created March 1, 2014 at 6:02 AM
Updated September 14, 2018 at 10:21 PM
Resolved September 14, 2018 at 10:21 PM

Flag notifications