Uploaded image for project: 'core.cache'
  1. CCACHE-29

Is IPersistentCollection definition of cons correct?

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Completed
    • Labels:
      None

      Description

      Here's the definition of `cons` for caches:

      clojure.lang.IPersistentCollection
      (cons _# elem#
      (clojure.core/cons ~base-field elem#))

      This seems wrong to me. Note first that the arguments to `clojure.core/cons` are in the wrong order. As a result, the result of (for example) conj is incorrect. Consider this:

      user=> (def starts-with-a (cache/fifo-cache-factory {:a 1} :threshold 3))

      #'user/starts-with-a
      user=> starts-with-a
      {:a 1}
      user=> (conj starts-with-a [:c 3])
      ({:a 1} :c 3)

      Even if the argument order was correct, the result would still be a sequence rather than the type of the base field. I think you want something more like

      clojure.lang.IPersistentCollection
      (cons this# elem#
      (apply assoc this# elem#))

      After all, this particular collection is an IPersistentMap, so its `conj` and `into` behavior should be the same as other objects for which `map?` is true.

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: