Clojure

defn :or form does not warn you if you provide a vector instead of a map

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Trivial Trivial
  • Resolution: Declined
  • Affects Version/s: Release 1.3
  • Fix Version/s: Backlog
  • Component/s: None
  • Labels:
    None
  • Environment:
    Clojure 1.3, Emacs 23, OSX Lion

Description

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.

Activity

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: