Fork me on GitHub
#beginners
<
2017-01-13
>
madstap00:01:53

@kamillelonek If you're using leiningen it has a feature called checkout dependencies. You make a directory on the project root called "checkouts" and make a symlink inside that points to the library you want to use.

madstap01:01:20

Right, I just saw that that's what you tried already... That's strange, it works on my machine ¯\(ツ)

rubek09:01:20

Nevermind I solved my problem and deleted my messages; reading helps. Hi anyway!

rubek09:01:56

But just a next question: proto-repl doesn’t seem to be able to execute the “hello-world-test” tests from the very first exercism project. ‘lein test’ runs perfectly fine (although it still fails of course :D)

rubek09:01:27

Is there some obvious thing I am missing?

rubek10:01:57

Okay and another question which is very weird… I overloaded the “Hello” function so it looks like this:

(defn hello
  ([] "Hello, World!")
  ([username] (format "Hello, %s!" username)))

rubek10:01:53

Now, lein test runs perfectly, but if I want to evaluate (hello) or (hello “test”), I get a CompilerException java.lang.RuntimeException: Unable to resolve symbol: hello in this context

rubek10:01:22

Arrrgh cleaning namespaces helps 😞 Sorry

rubek10:01:17

It made too much sense, sorry 😞

ejelome10:01:19

^ what is the (format ... for? 🙂

poooogles11:01:44

to format the string?

rubek12:01:13

Yup, it inserts the username into the place where %s is

ejelome12:01:59

this will probably be more lispy 🙂

(defn hello
  ([] "Hello, World!")
  ([username] (str "Hello " username "!")))

ejelome12:01:10

^ you don't have to format it like what we've gotten used to other PLs that need string interpolation, we just trea them as a list (the first one being always a function and the rest as args)

rubek12:01:15

I had tried that first, as that was what I expected, but I failed on myself there, not in the language… 🙂

rubek13:01:05

Now I still fail at moving stuff in between parentesis

rubek13:01:38

But thank you all 🙂

astrashe16:01:32

I'd like to learn how to work with collections and nosql databases, but I'm not sure which db to use. Can anyone suggest one that has a solid clojure library?

verma18:01:47

@astrashe in my last project I used monger + mongodb .. it was an Ok experience.

astrashe18:01:17

Thanks @verma! I just need to pick one and go with it.

astrashe18:01:22

I'll try that.

verma18:01:34

:thumbsup:

jgh18:01:56

How can I convert a lazy sequence into a list?

dominicm18:01:36

a lazy sequence is a list.

jgh18:01:44

ok well datomic is complaining that it isnt

dominicm18:01:02

What are you trying to give it?

dominicm18:01:08

which function? 🙂

jgh18:01:32

:db.fn/retractEntity

jgh18:01:42

I'm basically trying to retract a result of a datomic query

jgh18:01:11

the result seems to come back as a HashSet which I'm able to flatten to a LazySet but retractEntity wants a List or a Map

jgh18:01:26

err LazySeq*

dominicm19:01:07

So you're doing (d/transact ...)?

jgh19:01:37

(d/transact db-con [:db.fn/retractEntity (flatten (into [] result))])

jgh19:01:01

maybe i need to do the flatten an into in the reverse order?

dominicm19:01:13

hold on, let me just double check. I think you're quite close.

dominicm19:01:21

*close, sorry.

jgh19:01:26

haha ok 🙂

dominicm19:01:57

A tip might be to try and evaluate [:db.fn/...] in your editor (not the transact part, just the vector.

dominicm19:01:46

Okay, so two things.

dominicm19:01:45

(d/transact db-con [ [:db.fn/blah] ]) There's two wrappings of lists.

dominicm19:01:32

That's why it was complaining about the transactions not being lists. Because it was expecting everything inside the list, to also be a list. But it was instead getting :db.fn/retractEntity. Hence "not a list"

dominicm19:01:31

Yeah. There's a trick to reading stack traces, don't worry. You'll get the hang of it 🙂

dominicm19:01:47

Were you able to evaluate the vector like I suggested?

jgh19:01:17

im using atom so i would have to fire up the repl which is almost slower than just trying it in code heh

jgh19:01:29

so building now, i'll let you know 😉

dominicm19:01:42

Odd. I tend to have a REPL running the whole time I'm developing. You might want to look into that.

dominicm19:01:49

It's quicker than building.

dominicm19:01:59

I just re-run the function in the REPL.

jgh19:01:28

oh i just mean i dont have the repl running, i should just keep it running like you're saying - that would be faster

jgh19:01:37

ok so progress, now im getting

:cause :db.error/invalid-lookup-ref Invalid list form: [17592186045443, 17592186045427, 17592186045446, 17592186045431, 17592186045449, 17592186045434, 17592186045452, 17592186045437, 17592186045440]

dominicm19:01:09

This would be much easier to demonstrate if you could test this in the REPL. I'll give you the answer this time 🙂.

jgh19:01:29

ill get the repl going

dominicm19:01:53

So, the result of of (flatten (into [] result)) will be something like (1 2 :foo :bar). So the transaction you're creating is [:db/retractEntity (1 2 :foo :bar)] but I think you actually want [:db/retractEntity 1 2 :foo :bar ]

jgh19:01:28

i have a lot to learn about clojure lol

dominicm19:01:48

The REPL helps a lot, because you can visualize what you're creating.

dominicm19:01:13

I think what you want to do to get your transaction is this (into [:db/retractEntity] result)

dominicm19:01:08

https://www.youtube.com/watch?v=FihU5JxmnBg @jgh this helped me a lot with debugging this sort of stuff

jgh19:01:43

so something like (flatten (into [:db/retractEntity] result)) or no flatten at all?

jgh19:01:03

ill take a look at that video

dominicm19:01:50

Depends on how result looks 🙂 Test it in your REPL 🙂

jgh19:01:10

k will do!

dominicm19:01:56

Let me know how it goes

jgh19:01:31

ok i think i see what im doing wrong - retractEntity should do 1 id at a time, so I think what I need is more like [[:db.fn/retractEntity first-id] [:db.fn/RetractEntity second-id]] or something along those lines

jgh19:01:18

so i suppose in that case my question becomes how could i apply a field to each element of a sequence then

jgh20:01:15

ok so im able to almost get there with something like (into [] (interleave (repeat :test) [1 2 3])) which gives me [:test 1 :test 2 :test 3] but i need to get it into the form [[:test 1] [:test 2] [:test 3]]

schmee21:01:41

jgh (into [] (map vector (repeat :test) [1 2 3]))

dominicm21:01:58

@jgh maybe you want to use map here?

dominicm21:01:38

If I have a list like [1 2 3] I want to transform each element via (fn [x] [:db.fn/retractEntity x])

jgh22:01:31

@schmee that looks like it'll do it

schmee22:01:45

(mapv vector (repeat :test) [1 2 3]) is better still

jgh23:01:58

(d/transact db-con (mapv vector (repeat :db.fn/retractEntity) (into [] (flatten result)))

jgh23:01:14

successfully retracts all results of the query

jgh23:01:19

thanks guys