Uploaded image for project: 'Clojure'
  1. CLJ-1103

Make conj assoc dissoc and transient versions handle args similarly

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects versions: Release 1.6, Release 1.5, Release 1.4
    • Fix versions: None
    • Approval:
      Triaged
    • Patch:
      Code and Test

      Description

      Examples that work as expected:

      Clojure 1.7.0-master-SNAPSHOT
      user=> (dissoc {})
      {}
      user=> (disj #{})
      #{}
      user=> (conj {})
      {}
      user=> (conj [])
      []
      

      Examples that do not work as desired, but are changed by the proposed patch:

      user=> (assoc {})
      ArityException Wrong number of args (1) passed to: core/assoc  clojure.lang.AFn.throwArity (AFn.java:429)
      user=> (assoc! (transient {}))
      ArityException Wrong number of args (1) passed to: core/assoc!  clojure.lang.AFn.throwArity (AFn.java:429)
      user=> (dissoc! (transient {}))
      ArityException Wrong number of args (1) passed to: core/dissoc!  clojure.lang.AFn.throwArity (AFn.java:429)
      
      ;; patch enables conj! with multiple arguments, like conj
      user=> (conj! (transient []) 1 2 3)
      ArityException Wrong number of args (4) passed to: core/conj!  clojure.lang.AFn.throwArity (AFn.java:429)
      
      ;; patch would give error for missing value for last key to assoc!, not silently use nil for last value
      user=> (assoc! (transient {}) 1 2 3)
      #object[clojure.lang.PersistentArrayMap$TransientArrayMap 0x2e7569b8 "clojure.lang.PersistentArrayMap$TransientArrayMap@2e7569b8"]
      

      I looked through the rest of the code for similar cases, and found that there were some other differences between them in how different numbers of arguments were handled, such as:

      + conj handles an arbitrary number of arguments, but conj! does not.
      + assoc checks for a final key with no value specified ( CLJ-1052 Closed ), but assoc! did not.

      History/discussion: A discussion came up in the Clojure Google group about conj giving an error when taking only a coll as an argument, as opposed to disj which works for this case:

      https://groups.google.com/forum/?fromgroups=#!topic/clojure/Z9mFxsTYTqQ

      Screened by: Alex Miller

        Attachments

        1. clj-1103-10.patch
          8 kB
        2. clj-1103-7.diff
          8 kB
        3. clj-1103-8.patch
          12 kB
        4. clj-1103-9.patch
          7 kB

          Activity

            People

            • Assignee:
              alexmiller Alex Miller
              Reporter:
              jafingerhut Andy Fingerhut
            • Votes:
              9 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: