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

Do not use hash-map constructor in destructuring to avoid multiple key check.

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Trivial
    • Resolution: Completed
    • Affects versions: Release 1.2
    • Fix versions: Release 1.5
    • Labels:
      None
    • Environment:

      Clojure versions 1.2 and above

    • Approval:
      Ok
    • Patch:
      Code and Test

      Description

      What I did:

      (defn number-to-string
        [& {fmt :format locale :locale :or {locale (Locale/getDefault)}}]
        (fn [v]
          (String/format locale fmt (to-array [v]))))
      
      (defn double-to-string
        [& options]
        (apply number-to-string :format "%f" options))
      
      (def us-number (double-to-string :locale Locale/US))
      (def legacy-number (double-to-string :format "% 3.2f"))
      
      (us-number 3.14159)
      (legacy-number 3.14159)
      

      What I expected:

      "3.14159"
      "  3,14"
      

      What I got:

      java.lang.IllegalArgumentException: Duplicate key: :format
      

      Using into or a combination of reduce and assoc instead of hash-map would allow this without breaking things.

      If this is a desired modification, I can provide a patch. (CA is filed.)

        Attachments

          Activity

            People

            • Assignee:
              mbrandmeyer Meikel Brandmeyer
              Reporter:
              mbrandmeyer Meikel Brandmeyer
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: