Fork me on GitHub
#clojure
<
2019-01-28
>
lilactown05:01:10

anyone know why

(binding [*provided* (merge provided args)]
          (map (bound-fn [x] (walk! x)) children))
works, but
(binding [*provided* (merge provided args)]
          (map walk! children))
loses the *provided* binding?

Lennart Buit05:01:31

Huh, don’t you mean (map #(walk! %) children) in the second case?

lilactown06:01:27

oops, had a typo. I meant (map walk! children)

Lennart Buit06:01:03

Right, I had a case of ‘early morning’ and forgot about passing unary fns directly

Lennart Buit06:01:08

With the chance of sounding stupid: could it be because your map returns a lazy sequence and therefore the binding is lost when it is realized

lilactown06:01:45

:thinking_face: I wouldn’t expect it to, but maybe

rutledgepaulv13:01:38

this is something that happens. Lazy sequences might be realized outside of the scope of the binding. https://cemerick.com/2009/11/03/be-mindful-of-clojures-binding/

lilactown06:01:24

clojure.lang.PersistentVector$ChunkedSeq

lilactown06:01:41

hrmph. I changed it back to (map walk! children) and it works

Lennart Buit07:01:08

haha, sometimes you have those problems

dacopare08:01:10

Is there a way to define a function or variable that belongs to another NS?

(defn another-ns/foo [x] 3)
(defn another-ns/bar 5)
2. Unhandled clojure.lang.Compiler$CompilerException
   Error compiling src/---.clj at (14:1)
   #:clojure.error{:phase :macro-syntax-check,
                   :line 14,
                   :column 1,
                   :source ---
                   :symbol clojure.core/defn}

1. Caused by clojure.lang.ExceptionInfo
   Call to clojure.core/defn did not conform to spec.
   #:clojure.spec.alpha{:problems
                        [{:path [:fn-name],
                          :pred clojure.core/simple-symbol?,
                          :val another-ns/foo,
                          :via
                          [:clojure.core.specs.alpha/defn-args
                           :clojure.core.specs.alpha/defn-args],
                          :in [0]}],
                        :spec
                        #object[clojure.spec.alpha$regex_spec_impl$reify__2509 0x32a67584 "[email protected]"],
                        :value (another-ns/foo [x] 3),
                        :args (another-ns/foo [x] 3)}

dacopare08:01:42

I'm trying to use the clj-ipfs-api (https://github.com/keorn/clj-ipfs-api) but I cannot load any NS that refers to its functions without having an IPFS daemon running. Ideally, those functions would just fail if I tried to call them without the daemon running, but I get exceptions because the vars haven't even been defined. My workaround is to check if the functions have been defined (using resolve) and replace them with a dummy function (that throws if called) if they're missing.

phill10:01:33

in-ns before the def ?

phill10:01:41

but beware that if the proper file for the ns is eventually loaded, the ns won't be strictly new so iirc it won't implicitly refer-clojure.

leena08:01:54

Hi, IntellijIdea and Cursive users, how do you make Idea to recognise HugSQL functions?

souenzzo10:01:14

you can ask in #cursive or #sql channel.

👍 1
crankyadmin10:01:16

Hi, I have a hex string that looks like 01031000BB014727DB00000064009600C823C5 that I need to decode in to something human readable. Whats the best way of going about this? The first three bytes are meaningless but after that I need to read 2 bytes at a time?

souenzzo11:01:57

(->> (.getBytes "01031000BB014727DB00000064009600C823C5")
     (drop 3) ;; The first three bytes are meaningless
     (partition 2) ;; I need to read 2 bytes at a time
     (map (partial byte-array 2)) ;; Turn (1 2) back to byte[]
     (map slurp)) ;; turn byte pair into string again 

souenzzo11:01:25

Using transducers (performatic)

(into []
      (comp (drop 3)                                        ;; The first three bytes are meaningless
            (partition-all 2)                               ;; I need to read 2 bytes at a time
            (map (partial byte-array 2))                    ;; Turn (1 2) back to byte[]
            (map slurp))                                    ;; turn byte pair into string again
      (.getBytes "01031000BB014727DB00000064009600C823C5"))

crankyadmin12:01:05

Nice one! thank you

souenzzo12:01:47

share the final form 🙂

crankyadmin10:01:10

I thought Buffy may have helped out but can't work out how to pass the whole string in.

restenb11:01:59

anybody got a quick and easy way of writing a file sent through a http/POST to file?

restenb11:01:25

to disk, rather

restenb11:01:17

i'm not quite sure what to use, if there's a convenient clojure library for it, or if I should just go straight to FileOutputStream

restenb11:01:59

Ring seems to not be happy about that approach though; java.lang.IllegalArgumentException: No implementation of method: :write-body-to-stream of protocol: #&apos;ring.core.protocols/StreamableResponseBody found for class: java.io.FileOutputStream

dominicm15:01:02

Is there an abstraction where something like take & drop would avoid computation? I'm guessing it would utilize custom versions of take/`drop`, although maybe txors can do this? I'm thinking about computationally heavy pagination.

JanisOlex15:01:44

Hi, can someone confirm or deny, that gen-class generated code can't put java annotations on generated class methods?

JanisOlex15:01:46

No this is how to attach to the methods you are bringing as new, but if you have methods which are, for example, alerady in super class (like abstract method) and then you try to write the function and attach the annotation, it does not work... Or should I also declare methods in the gen-class itself... I think you only do when you define new onews

JanisOlex15:01:26

I have java abstract class, which I try to extend, and there is abstract method "call" in that class, which I try to implement and add the annotation, in bytecode I see the method, but not the annotation

JanisOlex15:01:19

yea according to doc, the clojure will override all the public methods of super class, when extending, but it somehow clears and ignores all the annotations I put on the extendable abstract method

1
JanisOlex15:01:20

I am utterly unable to find exampl exactly for gen-class... and not the methods which are new, but just well... extending abstract class, and dropping annotation on the abstract method implemetnation... I know it's possible for deftype (I think)

j0ni16:01:36

hey people, anyone know where I can find more details about the mechanics behind the error handler function optionally attached to agents? Specifically, is it dispatched in the same thread as the send which was responsible for the failing call, so that IO should be avoided in that case (or send-off used in cases where the error handler has to do IO)? And is the return value from the error used at all?

j0ni16:01:49

Hmm, Clojure Programming suggests it's not handled in the dispatch thread, so IO should be fine 🙂

alexmiller16:01:13

It’s handled in the agent execution thread, not in the thread calling send / send-off. If doing I/O, I would use send-off. The return value is not used.

kazesberger17:01:54

hey, don't know whether I'm in the right place for this: i want to make some improvements to http://4clojure.com but i think it lacks an active maintainer. improvements i think of atm would be • clean up issues/PRs on github • oauth-login (afaik there would already be a PR that needs some love or rewrite, dunno yet) • maybe a small face lift using cljs/reframe? i mainly think of this as an exercise for myself xD but i'd like to accomplish some goals like improvements on "top users"/"follow" page/features (performance-wise) • mabye some browser-editor improvements to name some of the starters

kazesberger17:01:57

so my question is, who i need to contact to become maintainer and how i qualify to become the next warden of http://4clojure.com 🙂

borkdude17:01:27

@klaus.azesberger I don’t know the current maintainer, but I would also be interested in these improvments. I would also like to add better error messages through the use of speculative instrumentation (can be turned on and off). For browser editor improvements CodeMirror + parinfer could be used.

👍 1
kazesberger17:01:02

if @danielwithmusic is right amalloy still has ownership. will look into possibilites to reach him and/or any1 on the contributors list tonight.

Sy Borg21:01:50

isn't there a typo?

(doc clojure.set/rename-keys)
-------------------------
clojure.set/rename-keys
([map kmap])
  Returns the map with the keys in kmap renamed to the vals in kmap

noisesmith21:01:21

if kmap is {:a :b} it renames keys of kmap (:a) to vals of kmap (:b)

noisesmith21:01:44

it's awkward, but correct

noisesmith21:01:53

"if a key in m is also a key in kmap, it is replaced by the corresponding val in kmap" is a potentially clearer way to say that(?)

Sy Borg21:01:29

I would expect "Returns the map with the keys in map renamed to the vals in kmap"

noisesmith21:01:42

no, because keys that aren't in kmap are not touched

futuro21:01:01

I think the tricky issue is tying the keys from map and the keys from kmap together, and what happens when they match.

futuro21:01:44

I like your definition above @noisesmith more than the docstring, which tripped me up when I was first figuring out how to use it.

Sy Borg21:01:26

examples from https://clojuredocs.org/clojure.set/rename-keys prove that my understanding is correct, but I'm confused by description

nwjsmith21:01:42

@sy_borg You’re correct, that appears to be a typo

nwjsmith21:01:00

Oh shoot, no sorry

nwjsmith21:01:03

That’s not a typo

nwjsmith21:01:51

haha, it took me a couple of reads to understand the docstring

futuro21:01:41

Running that top example in a clj repl doesn't replicate that behavior.

futuro21:01:03

user=> (set/rename-keys {:a 1} {:a :new-a :b :new-b})
{:new-a 1}

noisesmith21:01:04

you are missing the :b key in the input map

futuro21:01:47

Sorry, the behavior I was pointing out was that keys in kmap that aren't in map result in no behavior; there was an example on clojuredocs that showed an old behavior where the returned map would contain :new-b nil as a k/v pair.

futuro21:01:00

That being said, upon rereading this thread I'm not sure if anyone was confused about that.

dpsutton21:01:18

also in the examples that was a bug in clojure 1.1 and fixed in 1.2.1 ti thought i read

futuro21:01:04

Yep! I just like to verify those statements myself...

futuro21:01:33

(too much time working front-line support, perhaps...)

Sy Borg21:01:05

btw, where's clojure.data/diff?

noisesmith21:01:20

it comes with clojure

dpsutton21:01:52

(require '[clojure.data :as diff])

Sy Borg21:01:53

doc returns nil to me

noisesmith21:01:14

did you require its namespace?

Sy Borg21:01:28

Execution error (FileNotFoundException) at user/eval1484 (form-init8507139964286056300.clj:1).
Could not locate diff__init.class, diff.clj or diff.cljc on classpath.
sorry, I'm noob

Sy Borg21:01:36

thx Dan, it worked

👍 1
Sy Borg21:01:40

oh, just noticed I'm in the wrong channel

datran23:01:16

in postgres, column names can't have hyphens (unless you escape them). I'm using hugsql and I'd like to create some middleware to convert snake_case keys to kebab-case for every query, has anybody done this already?

Eccentric J23:01:31

There’s an exploit in Slack that allows you to change permissions and post as random user ids from the client side. Occasionally a troll comes in and uses it to post as random people and start something.

3
restenb23:01:19

that's a pretty serious exploit

Eccentric J23:01:39

Yes, yes it is. They disclosed the issue but apparently refuse to fix it.

currentoor23:01:56

@noprompt the admins have disabled that, the troll was using a well known exploit in slack

currentoor23:01:09

slack is very aware of it, and has not fixed it

noprompt23:01:21

This is the same exploit described previously?

noprompt23:01:47

I wonder what the rationale is for not fixing it.

currentoor23:01:02

:man-shrugging:

seancorfield23:01:06

Stop discussing this here. Go to #community-development for that discussion please.

manutter5123:01:19

#clojurescript has also been hit

seancorfield23:01:04

Thanks. I'll join there and clean up.

Eccentric J23:01:46

Oops sorry 😓

seancorfield23:01:36

Do not engage the trolls. Do not discuss it in regular channels. It just makes the noise worse.