Incorrect hash when conj-ing onto the value returned by filter/remove etc
Description
Environment
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
Activity
David Nolen
December 30, 2015 at 10:57 AM
Thomas Heller
December 28, 2015 at 11:04 PM
Appears to be type related, I added the type
for reference:
(let [log (fn [xs]
(prn (hash xs) (count xs) (type xs))
xs)]
(-> []
(conj 1)
(conj 2)
log
(->> (remove #{1}))
log
(->> (remove #{2}))
log
(conj 3)
log
(conj 4)
log
(conj 5)
log))
Clojure:
156247261 2 clojure.lang.PersistentVector
829981563 1 clojure.lang.LazySeq
-2017569654 0 clojure.lang.LazySeq
-1154116787 1 clojure.lang.PersistentList
-733651870 2 clojure.lang.PersistentList
1036804101 3 clojure.lang.PersistentList
ClojureScript:
1185709346 2 cljs.core/PersistentVector
-1917711765 1 cljs.core/LazySeq
-2017569654 0 cljs.core/LazySeq
-1025653387 1 cljs.core/Cons
-1025653387 2 cljs.core/Cons
-1025653387 3 cljs.core/Cons
import
December 28, 2015 at 7:14 PM
Comment made by: augustl
Adding some extra details.
Full project.clj:
(defproject cljs-bug "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "1.7.170"]]
:plugins [[lein-cljsbuild "1.1.2"]]
:main cljs-bug.cli
:profiles {:dev {:cljsbuild {:builds [{:source-paths ["src"]
:compiler {:output-to "target/classes/public/app.js"
:output-dir "target/classes/public/out"
:main "cljs-bug.web"
:asset-path "target/classes/public/out"
:optimizations :none
:recompile-dependents true
:source-map true}}]}}})
Full src/cljs_bug/cli.clj code:
(ns cljs-bug.cli
(:require [cljs-bug.bug :as bug]))
(defn -main [& args]
(bug/demonstrate))
Full src/cljs_bug/web.cljs code:
(ns cljs-bug.web
(:require [cljs-bug.bug :as bug]))
(enable-console-print!)
(bug/demonstrate)
Completed
Details
Details
Created December 28, 2015 at 7:12 PM
Updated December 30, 2015 at 10:57 AM
Resolved December 30, 2015 at 10:57 AM
The following code produces the correct result in Clojure but incorrect results in ClojureScript:
(let [log (fn [xs] (prn (hash xs) (count xs)) xs)] (-> [] (conj 1) (conj 2) log (->> (remove #{1})) log (->> (remove #{2})) log (conj 3) log (conj 4) log (conj 5) log))
Clojure produces the following output:
156247261 2 829981563 1 -2017569654 0 -1154116787 1 -733651870 2 1036804101 3
ClojureScript produces the following output:
1185709346 2 -1917711765 1 -2017569654 0 -1025653387 1 -1025653387 2 -1025653387 3
I expect the hash code to change as I conj items onto the list. Instead, the hash code stays the same even though we can se that the result of "count" changes.
At the time of writing, I host a leiningen project on my github user that contains the exact setup and a README for how I run the code:
https://github.com/augustl/cljs-issue-filter-conj-hashcode