Fork me on GitHub

why does this (filter (fn [x] (Character/isUpperCase x)) (char-array "AfSDds")) and not (filter Character/isUpperCase (char-array "ADdasd"))

Ankon Chakraborty06:02:01

This will work fine until you’re trying to compose or trying to use partial


I see, that is a java.lang.Character fn.


Yeah, java methods cannot directly be used as first class functions.


Is the underlying reason Java methods do not implement AFn? Curious to know.


java methods are not first class objects - they are parameterization of the object they are invoked on

👍 1

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)))


Are you writing this as a learning exercise?


Yes, don't use concat like that


Also you don't need a loop binding for y


Nice. Thanks for sharing that.


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.


that make sense. Thank you.


Here is what I am trying. I was trying to concat because the test case expects persistentlist!/subjects/17592186045880


You can do (cons y '(x)) and get '(y x).


Note that the order is reversed. In the end, you reverse again.


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 (
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: 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)}))


tried conversion to a vector, list but the issue persists.


Thanks for response!


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 ?


how can i add sub-selects in honeysql and cross join lateral ?


I was trying!/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

👍 1