Fork me on GitHub
#clojure
<
2019-11-20
>
p4ulcristian14:11:22

Hello guys. I just recently started to use clojurewerkz.machine-head.client and I was wondering how can I connect to aws with this cool library. How can I manage connecting the ssl certificates? Can you give me any starting points? Much appreciated 🙂

jrwdunham22:11:18

Random thing I discovered today: associative destructuring works on just about any type but throws an exception with integers (`java.lang.Long`). Anyone here have any insight on why this might be?:

jrwdunham22:11:20

(let [{:keys [a] :as b} {:a 2}] [a b])
;; [2 {:a 2}]
(let [{:keys [a] :as b} "bob"] [a b])
;; [nil "bob"]
(let [{:keys [a] :as b} []] [a b])
;; [nil []]
(let [{:keys [a] :as b} \x] [a b])
;; [nil \x]
(let [{:keys [a] :as b} 1] [a b])
;; Syntax error (UnsupportedOperationException) compiling at (REPL:1:1).
;; Can't type hint a primitive local
;; user=> 

Alex Miller (Clojure team)22:11:49

I think you're well into "don't do that"

😄 8
kenny22:11:07

That error message is bad. Don't think I've ever accidentally tried to destructure a number like that.

jrwdunham22:11:54

@alexmiller haha, I guess so. I'm destructuring the return value of next.jdbc/execute! so I guess I'm being too paranoid: the return value of that function should never be an int anyway actually that's not quite correct, but I digress... the "don't do that" advice is well taken

vemv22:11:16

Can eventually grep it myself, but anyone knows how :post is implemented? I would imagine that if a :post is present, the defn inner body is rewritten so that its return value passes by the :post predicates before the defn returns e.g. (defn foo [x] {:post [x]} 42) -> (defn foo [x] (let [ret-val 42] (assert ret-val) ret-val)) ;; demonstrates a 'rewrite-based' implementation

Cameron22:11:46

I'm looking at the source right now and I think its implemented right here

post (:post conds)                       
                       body (if post
                              `((let [~'% ~(if (< 1 (count body)) 
                                            `(do ~@body) 
                                            (first body))]
                                 ~@(map (fn* [c] `(assert ~c)) post)
                                 ~'%))
                              body)
                       body (if pre
                              (concat (map (fn* [c] `(assert ~c)) pre) 
                                      body)
                              body)

Cameron22:11:01

specifically

body (if post
                              `((let [~'% ~(if (< 1 (count body)) 
                                            `(do ~@body) 
                                            (first body))]
                                 ~@(map (fn* [c] `(assert ~c)) post)
                                 ~'%))
                              body)

vemv23:11:30

ace, thank you!

Cameron22:11:14

and indeed it looks like what you say

Cameron22:11:25

although I wanna double check to be absolutely sure

✌️ 4