Clojure

Add optional not-found argument when invoking vectors or sets as functions

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Release 1.5
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code
  • Approval:
    Triaged

Description

Maps, keywords, and symbols when used as operators allow optional second arguments for 'default-not-found' values is if to 'get'.

({:a 1} :b 'b) => b

However sets don't support this behavior (though they do with 'get') and vectors don't allow the optional default-not-found in their pseudo 'nth' semantics.

user=> (#{:a  :b} :b 'notfound)
ArityException Wrong number of args (2) passed to: PersistentHashSet  clojure.lang.AFn.throwArity (AFn.java:437)

Activity

Alex Miller made changes -
Field Original Value New Value
Description Maps, keywords, and symbols when used as operators allow optional second arguments for 'default-not-found' values is if to 'get'.

E.g.

({:a 1} :b 'b) => b

However sets don't support this behavior (though they do with 'get') and vectors don't allow the optional default-not-found in their pseudo 'nth' semantics.

E.g.

user=> (#{:a :b} :b 'notfound)

ArityException Wrong number of args (2) passed to: PersistentHashSet clojure.lang.AFn.throwArity (AFn.java:437)


Ideally, from a user standpoint, they would be consistent in this regard.
Maps, keywords, and symbols when used as operators allow optional second arguments for 'default-not-found' values is if to 'get'.

{code}
({:a 1} :b 'b) => b
{code}

However sets don't support this behavior (though they do with 'get') and vectors don't allow the optional default-not-found in their pseudo 'nth' semantics.

{code}
user=> (#{:a :b} :b 'notfound)
ArityException Wrong number of args (2) passed to: PersistentHashSet clojure.lang.AFn.throwArity (AFn.java:437)
{code}
Summary Make vector and sets as operators consistent with maps, keywords, and symbols, allowing optional second arguments Add optional not-found argument when invoking vectors or sets as functions
Hide
Pepijn de Vos added a comment -

I fixed the problem with Dirk at the Amsterdam Clojurians Hackathon.

Show
Pepijn de Vos added a comment - I fixed the problem with Dirk at the Amsterdam Clojurians Hackathon.
Pepijn de Vos made changes -
Alex Miller made changes -
Approval Triaged [ 10120 ]
Pepijn de Vos made changes -
Patch Code [ 10001 ]
Hide
Bozhidar Batsov added a comment -

Guess you can add a couple of unit tests as well.

Show
Bozhidar Batsov added a comment - Guess you can add a couple of unit tests as well.

People

Vote (2)
Watch (1)

Dates

  • Created:
    Updated: