This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-22
Channels
- # beginners (43)
- # bristol-clojurians (2)
- # calva (11)
- # cider (10)
- # clj-kondo (3)
- # clojars (19)
- # clojure (93)
- # clojure-france (44)
- # clojure-nl (10)
- # clojure-uk (15)
- # clojuredesign-podcast (1)
- # clr (6)
- # core-typed (102)
- # data-science (1)
- # datomic (11)
- # docker (4)
- # emacs (12)
- # fulcro (27)
- # graalvm (6)
- # joker (1)
- # leiningen (4)
- # lumo (20)
- # nrepl (3)
- # off-topic (63)
- # parinfer (4)
- # reagent (40)
- # remote-jobs (2)
- # shadow-cljs (18)
- # spacemacs (7)
- # tree-sitter (7)
- # yada (3)
why does this (filter (fn [x] (Character/isUpperCase x)) (char-array "AfSDds"))
and not (filter Character/isUpperCase (char-array "ADdasd"))
This will work fine until you’re trying to compose or trying to use partial
Yeah, java methods cannot directly be used as first class functions.
java methods are not first class objects - they are parameterization of the object they are invoked on
so there's no mechanism to provide them as an argument to something else
in other words - not only do they not implement AFn, there's no "it" to attach AFn to
That makes sense. Java functions are not objects so it's impossible to implement AFn for them, Did I interpret that right?
almost - "function" is not the java term, this becomes tricky after iirc java 1.7 where there's a Function
interface! which is kind of like a first class function, specialized for data streaming
I think it's safest to not use the word function in reference to java unless you are talking about those
clojure functions are java objects that implement IFn (and via that AFn)
Is there a better way to write this?
(defn my-range
[x y]
(loop [x x
y y
acc '()]
(if (<= x y)
(recur (inc x) y (concat acc (list x)))
acc)))
conj
onto a vector that is initially the empty vector []
would be a more efficient approach there, and idiomatic for Clojure. Note that since y
never changes throughout the loop, you can leave it out of the list of loop
bindings, and thus also the recur
call. The value of y
is usable inside the loop, since it is defined in the surrounding scope of the loop
expression.
Here is what I am trying. I was trying to concat because the test case expects persistentlist https://clojurecademy.com/course#!/subjects/17592186045880
And if this is for practice as a learning exercise, cool, but if not, then there is a range
function included with Clojure that has been optimized like crazy for any range of integers.
hey guys, HugSQL issue here - I’m trying to provide a list of values dynamically to query and I encounter SQL Type Inference
issue.
Can't infer the SQL type to use for an instance of clojure.lang.LazySeq. Use setObject() with an explicit Types value to specify the type to use.
Execution error (PSQLException) at org.postgresql.jdbc.PgPreparedStatement/setObject (PgPreparedStatement.java:962).
Any pointers are thoroughly welcome.This is the PG JDBC driver not knowing how to deal with a LazySeq parameter. Every parameter’s Clojure/Java data type should have a corresponding PG JDBC driver data type in order to be parameterized by the JDBC driver. You might be passing in a value that is not what you’ve intended. Do you have an example of the code causing this?
HugSQL can work with a list of values with the Value List parameter: https://www.hugsql.org/#param-value-list Is this what you’re trying to do?
I’m passing a list of event_id
to a query:
(def events (sql/get-events db (:events params)))
(def tickets (sql/get-tickets db {:events (map :event_id events)}))
How are you using the list in the SQL? Are you using a built-in HugSQL parameter type like Value List, where you’ve specified the parameter as :v*:events
?
hi everyone
how can i add sub-selects in honeysql and cross join lateral ?
I was trying https://clojurecademy.com/course#!/subjects/17592186045888
(= (apply str (compress "Leeeeeerrroyyy")) "Leroy")
that is the test case.
My brain was thinking to use set or hash-map, here is what SegFaultAX wrote. #(map first (partition-by identity %))
This is brilliant; for other beginners out there checkout https://gist.github.com/SegFaultAX/3607101
when i have a java object which .toString()
throws a NPE, the repl throws an NPE as well when it tries to print it — the printed literal doesn’t seem to contain the toString value normally, so why it is called?
Can you make this more concrete by showing some code? Having trouble following it.
Is toString throwing a NPE?