Fork me on GitHub
#clojure
<
2023-11-14
>
Daniel Ben Itzhak07:11:05

Hey community , Anyone familiar on how to do multi insert using HugSQL with an array of maps? From the documentation couldn’t find if there is a way to do the insertion with control over which value goes where Thank you 🙏

straux07:11:09

Hi, you can have a look here : https://www.hugsql.org/hugsql-in-detail/parameter-types/sql-tuple-list-parameters You have to deal with tuples, but it s easy to convert a map into it.

Daniel Ben Itzhak07:11:59

Thx, the problem with tuples is making sure all the values are in the same order

straux07:11:14

if you have an array of map you can do something like (map (juxt :id1 :id2) [{:id1 1 :id2 2} {:id1 3 :id2 4}])

🔥 2
Daniel Ben Itzhak07:11:54

Didn’t know about this, thx!

practicalli-johnny08:11:08

There is also a #C3EATG7EV channel that may provide additional help

👍 1
souenzzo10:11:51

What is the correct predicate to know if x supports with-meta ? coll? seems to work, but not sure about edge cases

Ed10:11:46

I think I would probably try

(instance? clojure.lang.IMeta [])
  (instance? clojure.lang.IMeta "")

souenzzo13:11:34

there is no pred in clojure.core?!

Alex Miller (Clojure team)13:11:42

and IObj is what you want (IMeta is for metadata read, IObj is for metadata update)

Alex Miller (Clojure team)13:11:42

the main ones are really colls and symbols though

markaddleman15:11:16

It seems that ChatGPT and I have similar fantasies

markaddleman15:11:24

(from ChatGPT): In Clojure, you can determine the arity of a function (i.e., the number of arguments it takes) by using the arity function from the clojure.reflect namespace. This function allows you to reflect on the function and get information about its arities. Here’s a basic example of how you can use it: 1. First, you need to require the clojure.reflect namespace:

clojure
   (require '[clojure.reflect :as reflect])
   
2. Then, you can use the reflect/arity function on any function to get its arity. For instance:
clojure
   (reflect/arity +) ; For the built-in `+` function
   
This will return a set of integers, each representing the arity of one of the function’s overloads. Remember that Clojure functions can have multiple arities (i.e., different versions of the function with different numbers of parameters), so the arity function returns a set of all possible arities. If you’re working with a custom function, you can do the same:
clojure
(defn my-func
  ([a] a)
  ([a b] (+ a b)))

(reflect/arity my-func)
This should return #{1 2}, indicating that my-func has two arities: one that takes 1 argument and another that takes 2 arguments.

Samuel Ludwig15:11:27

I also had ChatGPT hallucinate a clojure.lang.Utils/footprint function for determining the estimated size a data-structure would take up in memory yesterday :^), less than reliable~

markaddleman15:11:06

I did admire how confident it was, though!

Samuel Ludwig15:11:40

would be a nice world : D, I was mildly confused when evaling that fn was met only with DNE errors, and then I realized I'd been had 404

2
lukasz16:11:02

I started feeding Clojure documentation to a custom GPT using the new Assistants feature from OpenAI, I wonder at what point it will stop hallucinating (so far it hasn’t but I started with the API docs, not guides from http://Clojure.org ) - I’ll try it out later today :thinking_face:

roklenarcic23:11:00

When I use expression in macro (meta &form) I get something like {:line 9, :column 5} sometimes, but other times I get nil (especially when macro uses another macro). Why is that?

Noah Bogart23:11:45

List literals get position metadata, other forms do not

hiredman23:11:53

that metadata is attached to forms the reader produces, and it is wait the compiler uses to annotate generated byte code with line numbers so the line numbers show up in stacktraces

hiredman23:11:13

if a form is not produced by the reader it is unlikely to have it

hiredman23:11:27

and it is just normal metadata