Clojure

Make conj assoc dissoc and transient versions handle args similarly

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Release 1.4, Release 1.5, Release 1.6
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • 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)

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), 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

Activity

Andy Fingerhut made changes -
Field Original Value New Value
Summary Make conj assoc dissoc and transient versions handle 1-arg case Make conj assoc dissoc and transient versions handle args similarly
Andy Fingerhut made changes -
Attachment clj-1103-make-conj-assoc-dissoc-handle-args-similarly-v1.txt [ 11663 ]
Andy Fingerhut made changes -
Patch Code and Test [ 10002 ]
Andy Fingerhut made changes -
Attachment clj-1103-2.diff [ 12459 ]
Andy Fingerhut made changes -
Attachment clj-1103-3.diff [ 12481 ]
Andy Fingerhut made changes -
Attachment clj-1103-2.diff [ 12459 ]
Andy Fingerhut made changes -
Attachment clj-1103-make-conj-assoc-dissoc-handle-args-similarly-v1.txt [ 11663 ]
Andy Fingerhut made changes -
Attachment clj-1103-4.diff [ 12791 ]
Andy Fingerhut made changes -
Attachment clj-1103-3.diff [ 12481 ]
Andy Fingerhut made changes -
Description 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

I looked through the rest of the code for similar cases, and found that conj! assoc assoc! and disj! also had the same property, and 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), but assoc! did not.
Examples that work as expected:
{code}
user=> (dissoc {})
{}
user=> (disj #{})
#{}
{code}

Examples that do not work as desired, but are changed by the proposed patch:
{code}
user=> (assoc {})
ArityException Wrong number of args (1) passed to: core/assoc clojure.lang.AFn.throwArity (AFn.java:429)
user=> (conj {})
ArityException Wrong number of args (1) passed to: core/conj clojure.lang.AFn.throwArity (AFn.java:429)
{code}

I looked through the rest of the code for similar cases, and found that conj! assoc assoc! and disj! also had the same undesirable property of throwing an exception for no args after the collection, and 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), 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
Affects Version/s Release 1.6 [ 10157 ]
Andy Fingerhut made changes -
Description Examples that work as expected:
{code}
user=> (dissoc {})
{}
user=> (disj #{})
#{}
{code}

Examples that do not work as desired, but are changed by the proposed patch:
{code}
user=> (assoc {})
ArityException Wrong number of args (1) passed to: core/assoc clojure.lang.AFn.throwArity (AFn.java:429)
user=> (conj {})
ArityException Wrong number of args (1) passed to: core/conj clojure.lang.AFn.throwArity (AFn.java:429)
{code}

I looked through the rest of the code for similar cases, and found that conj! assoc assoc! and disj! also had the same undesirable property of throwing an exception for no args after the collection, and 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), 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
Examples that work as expected:
{code}
user=> (dissoc {})
{}
user=> (disj #{})
#{}
{code}

Examples that do not work as desired, but are changed by the proposed patch:
{code}
user=> (assoc {})
ArityException Wrong number of args (1) passed to: core/assoc clojure.lang.AFn.throwArity (AFn.java:429)
user=> (conj {})
ArityException Wrong number of args (1) passed to: core/conj clojure.lang.AFn.throwArity (AFn.java:429)
{code}

I looked through the rest of the code for similar cases, and found that conj! assoc! and disj! also had the same undesirable property of throwing an exception for no args after the collection, and 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), 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
Andy Fingerhut made changes -
Description Examples that work as expected:
{code}
user=> (dissoc {})
{}
user=> (disj #{})
#{}
{code}

Examples that do not work as desired, but are changed by the proposed patch:
{code}
user=> (assoc {})
ArityException Wrong number of args (1) passed to: core/assoc clojure.lang.AFn.throwArity (AFn.java:429)
user=> (conj {})
ArityException Wrong number of args (1) passed to: core/conj clojure.lang.AFn.throwArity (AFn.java:429)
{code}

I looked through the rest of the code for similar cases, and found that conj! assoc! and disj! also had the same undesirable property of throwing an exception for no args after the collection, and 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), 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
Examples that work as expected:
{code}
Clojure 1.7.0-master-SNAPSHOT
user=> (dissoc {})
{}
user=> (disj #{})
#{}
user=> (conj {})
{}
user=> (conj [])
[]
{code}

Examples that do not work as desired, but are changed by the proposed patch:
{code}
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)
{code}

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), 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
Andy Fingerhut made changes -
Attachment clj-1103-5.diff [ 13202 ]
Andy Fingerhut made changes -
Attachment clj-1103-4.diff [ 12791 ]
Andy Fingerhut made changes -
Attachment clj-1103-6.diff [ 13288 ]
Andy Fingerhut made changes -
Attachment clj-1103-5.diff [ 13202 ]

People

Vote (6)
Watch (3)

Dates

  • Created:
    Updated: