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

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

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Trivial
    • Resolution: Declined
    • Affects versions: Release 1.3
    • Fix versions: Backlog
    • 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.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              alex+import import
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: