This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-03
Channels
- # aws (1)
- # beginners (5)
- # boot (46)
- # cider (6)
- # cljs-dev (421)
- # cljsrn (74)
- # clojure (77)
- # clojure-greece (1)
- # clojure-italy (7)
- # clojure-russia (12)
- # clojure-serbia (42)
- # clojure-sg (1)
- # clojure-spec (10)
- # clojure-uk (38)
- # clojurescript (40)
- # core-async (14)
- # data-science (1)
- # datomic (18)
- # emacs (2)
- # events (1)
- # garden (4)
- # gorilla (4)
- # graphql (5)
- # hoplon (69)
- # luminus (1)
- # lumo (1)
- # off-topic (31)
- # om (31)
- # om-next (2)
- # overtone (3)
- # pedestal (1)
- # precept (4)
- # re-frame (23)
- # reagent (2)
- # remote-jobs (1)
- # ring-swagger (23)
- # rum (7)
- # spacemacs (7)
- # sql (4)
- # unrepl (9)
- # untangled (5)
- # vim (11)
- # yada (5)
I am trying to test a java.sql.SQLException
handler which unwraps the exceptions like below. However I'm not sure how I would throw this exception in a test.
(-> e
(.getNextException)
(.getMessage)
(.startsWith "ERROR: duplicate key value"))
current mock (`.getNextException` returns nil on this):
(throw (SQLException. "ERROR: duplicate key value"))
(answered in #sql — use setNextException()
http://docs.oracle.com/javase/8/docs/api/java/sql/SQLException.html#setNextException-java.sql.SQLException- )
Hey, clojurians. I’m using yesql
in my project to query postgres database. Some tables has boolean columns ending with question mark. How to properly use queries like this with yesql:
select name, email from user_accounts where "activated?" = true;
Seems yesql
thinks that question mark is param placeholder and fires error.armed: you may be interested in my fork https://github.com/tatut/jeesql
@U11SJ6Q0K wow, thanks. I’ll definitely look at your lib.
If you are feeling particularly adventurous, you can try https://github.com/tatut/specql
@armed Could you try that same query directly with java.jdbc
just to eliminate whether the problem is yesql
or something else?
I've never seen a database with ?
in column names... I didn't even think it was legal.
OK, well, that confirms a bug in yesql
so you should create a GitHub issue.
Ah, right, I heard that folks are switching to HugSQL. BTW, there's a #sql channel that's probably best for Qs like this.
We use HoneySQL for complex queries and raw java.jdbc
for most stuff.
Singapore Clojure Meetup tomorrow night, welcome to join. https://www.meetup.com/Singapore-Clojure-Meetup/events/240601551/
@melindazheng event invitations are always appreciated. But it would probably be better to limit them to one channel (#events seens best)
Anyone dabbled with Java 1.8's Nashorn (js runtime)? I’m a bit puzzled as to how it evaluates JS object literals:
(-> (javax.script.ScriptEngineManager.)
(.getEngineByName "nashorn")
(.eval "new Object({foo: 42})"))
=> {"foo" 42}
versus
(-> (javax.script.ScriptEngineManager.)
(.getEngineByName "nashorn")
(.eval "{foo: 42}"))
=> 42
Oh, this works (wrapping the exp with parens):
(-> (javax.script.ScriptEngineManager.)
(.getEngineByName "nashorn")
(.eval "({foo: 42})"))
=> {"foo" 42}
Hello everyone, is there any book/online resource about functional architectural patterns? Something like Patterns of Enterprise Application Architecture by Martin Fowler but from a functional point of view...
Rich Hickey's Talks can be considered as source of some patterns I think
any spectacular clojure alternative to https://github.com/Raynes/conch?
Hi clojurians! I'm trying to pattern-match a hashmap, but this is what I get:
(m/match [{:arst false}]
[{:qwfp #"stuff.*"}] 1
[{:arst false}] 2)
ClassCastException clojure.lang.Keyword cannot be cast to java.lang.CharSequence clojure.core/re-matcher (core.clj:4775)
What's going on here?@vandr0iy Looks like that error message indicates a problem with the regex
@potetm [org.clojure/core.match "0.3.0-alpha4"]
, with (:require [clojure.core.match :as m][clojure.core.match.regex])
in my ns
@baritonehands (re-matches #"stuff.*" "stuff123")
works, so no regex issues as well
macroexpanding the above yields:
(try
(clojure.core/cond
(clojure.core/instance? clojure.lang.ILookup x)
(try
(clojure.core/let
[x_qwfp__6982
(if
(clojure.core/instance? clojure.lang.ILookup x)
(clojure.core/get x :qwfp :clojure.core.match/not-found)
(clojure.core.match/val-at* x :qwfp :clojure.core.match/not-found))]
(clojure.core/cond
(clojure.core/re-matches #"stuff.*" x_qwfp__6982)
1
:else
(throw clojure.core.match/backtrack)))
(catch
Exception
e__6002__auto__
(if
(clojure.core/identical? e__6002__auto__ clojure.core.match/backtrack)
(do
(try
(clojure.core/let
[x_arst__6983
(if
(clojure.core/instance? clojure.lang.ILookup x)
(clojure.core/get x :arst :clojure.core.match/not-found)
(clojure.core.match/val-at* x :arst :clojure.core.match/not-found))]
(clojure.core/cond
(clojure.core/= x_arst__6983 false)
2
:else
(throw clojure.core.match/backtrack)))
(catch
Exception
e__6002__auto__
(if
(clojure.core/identical? e__6002__auto__ clojure.core.match/backtrack)
(do (throw clojure.core.match/backtrack))
(throw e__6002__auto__)))))
(throw e__6002__auto__))))
:else
(throw clojure.core.match/backtrack))
(catch
Exception
e__6002__auto__
(if
(clojure.core/identical? e__6002__auto__ clojure.core.match/backtrack)
(do
(throw
(java.lang.IllegalArgumentException.
(clojure.core/str "No matching clause: " x))))
(throw e__6002__auto__))))
Anyways it looks like it's probably calling re-matches
with :clojure.core.match/not-found
.
is there a formatter for clojure code that I can adapt progressively without converting the whole codebase at one? I tried parinfer for Atom, but it is too intrusive for me
cljfmt
is a good plugin and unlike editor based options every collaborator can easily have the same rules
Is there an obvious way to write the following without repeating x
? (if (some-pred? x) y x)
Meaning if x
is ok, just use it, otherwise use the alternative y
it could be written like
(or (somefn x) y)
, but inside somefn there definitely would be repetitions of x or % argumentyou have three values you care about, x,
y
, and (some-pred? x)
, so you will need those three elements. if x is truthy, you could write the pred to return x or false and use (or (some-pred? x) y)
, though that means custom predicates.
Doesn't work if you need pred to succeed on x being false / nil though
I think (if (foo? x) y x)
is readable and repeating one name, once as a parameter to the predicate, isn’t bad
@mbertheau You can do that with a macro if you so desire. Something like this:
(defmacro pass-or-alternative [pred-expr value-expr alternative-expr]
`(let [value# ~value-expr]
(if (~pred-expr value#)
value#
~alternative-expr)))
you don't need a macro, just (fn [pred x y] (if (pred x) x y)
, then you'd just use it like (my-fn pred x y)
if y has side effects the macro version is better
it wanted a replacement for if
i read it more as “how can I avoid re-typing ‘x’” rather than “how can I replace a call to ‘if’ while keeping the characteristics of ‘if’”
I think you need to quote the to-be-expanded form.
(macroexpand '(private-macro foo))
Interesting. :thinking_face:
Have you tried ns-resolve
ing the private macro? Not sure whether that would work, but maybe.
Wasn't aware of that limitation. Interesting.
@jeff.terrell the problem with resolve or ns-resolve is that the clojure compiler uses metadata on vars to decide if something is a macro, so using the var means it gets treated as a function - but! the fascinating thing is that this is a valid way to expand a macro, as long as you provide placeholders for &form and &env (nil here because I’m lazy and it doesn’t change the output)
=> ((resolve 'when) nil nil true :OK)
(if true (do :OK))
@arohner so yeah, see above, just give workable &env and &form, and call the var instead of macroexpand the macro call and it works
of course with macros that don’t access &env or &form (which is most…) two nils suffice
Very cool! Thanks for the info @noisesmith.