<< Back to previous view

[CLJ-848] defn :or form does not warn you if you provide a vector instead of a map Created: 06/Oct/11  Updated: 26/Jul/13  Resolved: 25/Oct/11

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: Release 1.3
Fix Version/s: Backlog

Type: Enhancement Priority: Trivial
Reporter: Dave Barker Assignee: Unassigned
Resolution: Declined Votes: 0
Labels: None

Clojure 1.3, Emacs 23, OSX Lion


I had a problem defining a function today, I passed :or a vector instead of a map - everything seemed to work fine but later on I got a really puzzling "Null pointer exception".

raek helped me debug the problem and suggested opening this ticket. I think it would be useful if an exception was thrown on the :or line unless it's given a map.

Here are some examples

(defn broken-example [{:keys [i processor]
:or [processor identity]}]
(processor i))

(defn working-example [{:keys [i processor]
:or {processor identity}}]
(processor i))

(working-example {:i 1})
=> 1
(broken-example {:i 1})
=> Null pointer exception

Cheers, Dave.

Comment by Dave Barker [ 06/Oct/11 6:51 AM ]

Apologies, I meant to tag this as a minor issue instead of a major one!

Comment by Stuart Halloway [ 07/Oct/11 9:39 AM ]

Since vectors are associative, maybe using vectors for :or should just work?

(let [{noun 0
       verb 1
       obj 2
       :or [:n :v :o]}
      [:code :is]] obj)
Comment by Stuart Halloway [ 25/Oct/11 6:04 PM ]

Closing this until someone wants to make a principled argument for what should happen (see my previous comment)

Generated at Thu Jan 18 02:18:16 CST 2018 using JIRA 4.4#649-r158309.