Fork me on GitHub

Hello Clojurians


Has anyone ever encountered such issue: unable to load a Clojure file into REPL, neither in IntelliJ nor Emacs and Cider. Loading src/playground/core.clj… and keeps on loading forever. 12 hours ago was working flawlessly…


Oooops, I had an infinite recursion 😄 by the way, is tail-recursion a good practice?


Hm… What’s difference between these two expressions? (set [1 2 3]) and #{[1 2 3]} (clojure.set/intersection #{[1 2 3 "Good-Morning"]} #{[2 3 10 11 12 "Good-Morning"]}) (clojure.set/intersection (set [1 2 3 "Good-Morning"]) (set [2 3 10 11 12 "Good-Morning"])) The first returns an empty set, whereas the second does the job properly…


In the first example you have two sets each containing one vector. As the vectors are different the intersection of both is empty. In the second case you create two sets each containing multiple entries. As some entries of these two sets are the same the intersection contains elements as well.


To see the difference you can evaluate (set [1 2 3]) in the REPL. The result is #{1 3 2} and not #{[1 2 3]}


@giga: re: tail-recursion -- often used in clj, but can't be done automatically (because of JVM limitations); you have to use loop/`recur`. Although explicit recursion is a bit less common in clj than in most Lisps, because there are often other ways to accomplish the same thing with operations over a data structure (eg list comprehensions).


@mawis my question was about the difference between (set ) and #{ }. I’ve already got an answer, thank you anyway simple_smile


@eggsyntax: yeah, I meant recur. for example now I’m trying to write a function that will return a binary representation of a number(just for learning purposes). At first I collected 0s and 1s in a list but now I’m trying to use bit-shift-left but doesn’t seem to work. I thought ‘(bit-shift-left 2r0 1)’ should have returned 1…


Huh. I don't think so -- you're taking 0 and shifting it left, which would still be 0.


then what’s the idea of an argument?… oh… forget it, I’ve answered my question… argument means steps.