This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-06
Channels
- # aws (11)
- # beginners (51)
- # cider (61)
- # cljsrn (37)
- # clojure (51)
- # clojure-spec (5)
- # clojure-uk (6)
- # clojurescript (35)
- # core-async (29)
- # cursive (3)
- # datomic (4)
- # defnpodcast (3)
- # editors (10)
- # emacs (3)
- # fulcro (2)
- # lein-figwheel (9)
- # leiningen (3)
- # mount (3)
- # off-topic (59)
- # parinfer (6)
- # portkey (4)
- # re-frame (6)
- # shadow-cljs (136)
- # spacemacs (1)
- # specter (1)
- # tools-deps (10)
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?
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.
@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.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?
@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.
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
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.
in Cursive I have all the Paredit hotkeys remapped to my liking, and I can't live without it - specially splice
and slurp
if you can't remember the hotkeys or if they don't make sense to you, remap! 🙂
Yea, cursive with parinfer is my choice too. Learning emacs shortcuts and paredit shortcuts at the same time is a tough task.
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.
When calling clojure from java is it possible to pass functions?
yes, clojure functions are objects implementing IFn
(which is why I tend to get pedantic when people mix up the terms method and function)
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?
hmm. yes. the answer is to import clojure.lang.Keyword
@drewverlee every clojure data type is reified into a concrete java class FWIW
yea, that makes sense.
#(instance clojure.lang.PersistentQueue %)
Ah damn, my plan to use queues won't work.. turns out transit cljs doesn't preserve the #queue
you could write a custom transit handler if you wanted to
just turn it into a list or vector, then a custom reader to drop the list into a queue on the other side
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
@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.
@seancorfield The get-assessor
query is SELECT * FROM assessores WHERE id = :id.
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?
hey clojurians, how do you guys use feature flags in your codes ? doing the usual if form ?
@lum I know nothing about HugSQL but the error sounds like you are not passing the correct arguments to get-assessor
.
Did you see my comment that your INSERT is not working? So there is no "last id of the insertion".
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.
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?
(Nice timing)
Totally forgot that doto
was a thing 🙂
Thanks
@seancorfield I removed the second test of the query refering to get-assessor
. Yes, it seems there's some error in the insertion:
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"
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}))
@sjharms Seems to be working to me. Unless your intent is that it return ({:my-key-to-filter 3})