Fork me on GitHub
#beginners
<
2018-05-06
>
iyahoo06:05:28

Hi. I read clojure-style-guide(https://github.com/bbatsov/clojure-style-guide#comments) and question why author is recommending to use the #_ rather than ;;. I thought ;; is more understandable for code readers. Would anyone know the reason?

Nikos07:05:51

As far as I can tell, they only recommend #_ over ; "when you need to comment out a particular form". In that case #_ makes sense because it comments out the the whole form, and as shown in the example, formatting doesn't influence it.

👍 4
iyahoo08:05:56

@nikoszp Thank you for telling. I didn’t consider a situation as below.

(+ foo #_(bar x
              (baz y)
              z)
   delta)
In this case #_ is clearly better than ;, also in terms of formatting. Thank you.

Nikos07:05:48

Am I the only only one annoyed by Paredit? I ended up disabling it and I don't seem to have issues balancing my parens without it. Do most Clojure programmers use it?

sveri07:05:46

@nikoszp I was too in the beginning. But soon enough you will hit nasty syntax errors and paredit / parinfer will help to reduce them. What worked for me was to gradually memorize the shortcuts that I use most. Starting with the "surround with parentheses" one.

yen07:05:30

@sveri Slurp C-(, C-) and barf C-{, C-} are immensely useful for me

soulflyer08:05:09

The whole barf/slurp thing annoyed me at first. Now I wouldn't want to be without it and get annoyed if I can't slurp. Got paredit mode enabled pretty much everywhere. I would recommend persisting, it's worth it in the end. Only time I turn it off is if I mess up a cut and paste. Once an unbalanced paren gets in there, paredit doesn't handle getting rid of it very well @nikoszp

👌 8
Nikos09:05:35

Thanks for the input guys! I guess learning the hotkeys is a good idea - I just felt a little overwhelmed with all the other emacs hotkeys.

joelsanchez09:05:48

in Cursive I have all the Paredit hotkeys remapped to my liking, and I can't live without it - specially splice and slurp

joelsanchez09:05:18

if you can't remember the hotkeys or if they don't make sense to you, remap! 🙂

schmee10:05:00

never got into Paredit, but I can’t code Clojure without Parinfer now 😄

sveri11:05:46

Yea, cursive with parinfer is my choice too. Learning emacs shortcuts and paredit shortcuts at the same time is a tough task.

soulflyer13:05:05

I set up some emacs bindings that start with C-c p for paredit commands. Had to define it as a new prefix command, but now I can do C-c p f b for paredit-forward-barf and similar. I actually use the shorter but less memorable keybindings these days, but those long forms are great for casual use.

Drew Verlee14:05:33

When calling clojure from java is it possible to pass functions?

noisesmith14:05:18

yes, clojure functions are objects implementing IFn

noisesmith14:05:22

(which is why I tend to get pedantic when people mix up the terms method and function)

Drew Verlee15:05:16

This might be obvious. But when calling clojure from java what is the caller supposed todo with keywords arguments. As far as i understand, keyword isn’t a “type” in java…. core? I mean, would the compiler even recognize the syntax?

Drew Verlee15:05:27

hmm. yes. the answer is to import clojure.lang.Keyword

bronsa15:05:30

@drewverlee every clojure data type is reified into a concrete java class FWIW

Drew Verlee15:05:31

yea, that makes sense.

bronsa15:05:26

you can use (class <x>) in a clojure repl to get the type of a clojure value <x>

Casey16:05:12

what :kind predicate is appropriate for a PersistentQueue when defining a s/coll-of?

Alex Miller (Clojure team)19:05:42

#(instance clojure.lang.PersistentQueue %)

Casey17:05:12

Oh perfect thanks!

Casey17:05:00

Ah damn, my plan to use queues won't work.. turns out transit cljs doesn't preserve the #queue

Alex Miller (Clojure team)18:05:36

you could write a custom transit handler if you wanted to

Alex Miller (Clojure team)18:05:09

just turn it into a list or vector, then a custom reader to drop the list into a queue on the other side

lum17:05:15

Hi, I'm using luminus, following the book "Web development with Clojure", and when trying to run a test for a db transcation get an error regarding :id which is a AUTO_INCREMENT key in the h2 database. This is similar to what is found as example in the book. Can you please give me a hand on this? https://paste.ofcode.org/mXs9t2VfGsKNaa4WxAdd6D

seancorfield19:05:23

@lum One problem is that the HugSQL adapter is using jdbc/query to try to run save-assessor! which is an INSERT. Your paste.ofcode doesn't show what get-assessor is doing, but it sounds like you have a bug in that query as well.

lum19:05:36

@seancorfield The get-assessor query is SELECT * FROM assessores WHERE id = :id.

lum19:05:41

how can I solve this? Include the :id as the last id of the insertion in the h2 database? If so, would you mind showing how?

tdantas19:05:27

hey clojurians, how do you guys use feature flags in your codes ? doing the usual if form ?

seancorfield20:05:33

@lum I know nothing about HugSQL but the error sounds like you are not passing the correct arguments to get-assessor.

seancorfield20:05:22

Did you see my comment that your INSERT is not working? So there is no "last id of the insertion".

spiralganglion22:05:53

Is there something built-in or more idiomatic I can use instead of (defn snoop [x] (print x) x)? I just want to print a single value, and return that value.

spiralganglion22:05:45

Perhaps, some core function that: takes a value and a function, applies the value to the function (for side effects), and then returns the value?

spiralganglion22:05:32

Totally forgot that doto was a thing 🙂

lum23:05:26

@seancorfield I removed the second test of the query refering to get-assessor. Yes, it seems there's some error in the insertion:

lum23:05:41

SQL: "INSERT INTO assessores\n\t(first_name,\n\tlast_name,\n\temail,\n\tphone,\n\taddress1,\n\taddress2,\n\tpost_code,\n\tpost_code_city,\n\tbirth_date,\n\ttax_number,\n\tto_buy,\n\tto_sell,\n\tto_career,\n\tfirst_message,\n\tis_active)\nVALUES ( ? ,\n\t? ,\n\t? ,\n\t? ,\n\t? ,\n\t? ,\n\t? ,\n\t? ,\n\t? ,\n\t? ,\n\t? ,\n\t? ,\n\t? ,\n\t? ,\n\t? )" SQLState: "90002" errorCode: 90002 originalMessage: "Method is only allowed for a query. Use execute or executeUpdate instead of executeQuery"

lum23:05:06

but tried it in a SQL client connected to the h2 database and it worked.

lum23:05:30

it must be some detail that I can't seem to see.

sjharms23:05:53

I can't seem to make this work, what am I doing wrong?

(filter #(nil? (get % :my-key-to-filter)) '({:a 1} {:b 2}... {:my-key-to-filter 3}))

mfikes23:05:08

@sjharms Seems to be working to me. Unless your intent is that it return ({:my-key-to-filter 3})

mfikes23:05:25

If you want that either replace filter with remove, or on the other hand, replace the predicate with :my-key-to-filter

mfikes23:05:44

And if you want to allow nil values under the key, the predicate could be #(contains? % :my-key-to-filter)

👍 4