Fork me on GitHub
#beginners
<
2016-05-07
>
giga12:05:42

Hello Clojurians

giga12:05:15

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…

giga12:05:44

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

giga14:05:55

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…

mawis14:05:30

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.

mawis14:05:58

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]}

eggsyntax17:05:19

@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).

giga17:05:25

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

giga17:05:48

@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…

eggsyntax18:05:20

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

giga18:05:23

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