Fork me on GitHub
#clojure
<
2017-07-17
>
qqq02:07:51

is there a way to get the emacs repl to display reagent/hiccup/react/dom/svg elements ? so I want to write sexps that return hiccup, then have emacs, instead of displaying the raw clojure data, to render it and display it

qqq02:07:00

if I had this, it'd give me most of ipython in eamcs

donyorm02:07:50

So I'm thinking about writing a clojure desktop app. Does https://github.com/halgari/fn-fx seem relatively stable and usable?

qqq03:07:47

why is there no websocket option there?

qqq03:07:56

how do I specify a websocket (which, iirc, jetty9 supports)

plins04:07:44

can anyone recommend me an async http client based on core.async?

kurt-o-sys04:07:36

config: nomad, aero, environ, cprop, ... who uses which library and why? (it's always nice to have some kind of experience reports before deciding)

kurt-o-sys04:07:48

@plins why should it be based on core async?

seancorfield05:07:53

@kurt-o-sys We wrote our own. We haven't gotten around to open sourcing it yet tho'. It's partly inspired by outpace/config but does some specific stuff we needed, and it's Component-based. This is a good article comparing some of the config libraries: http://realworldclojure.com/application-configuration/

seancorfield05:07:51

Hmm, actually now I re-read that article, I suspect Sonian's carica is more likely the inspiration for what we ended up with.

danielcompton06:07:31

@kurt-o-sys we use aero, I like it's philosophy of centralising as much config as possible, and just separating out sensitive config

donyorm07:07:57

Does clojure have any sort of plugin loading library? I'd like to create an application which loads plugins, but I haven't seen anything around.

mpenet08:07:10

@kurt-o-sys aero here too, it's just edn + some data readers. nothing too fancy, but quite powerfull. And you can extend it if you need it to do something it can't. It's quite lightweight.

qqq08:07:47

{:keys [in out] :or {in chan out chan}}
I am familiar with {:keys [...]} . What does the :or mean?

bronsa08:07:19

if value is not present, use default

the2bears08:07:20

@qqq those are alternate values if not found

bronsa08:07:48

note that it checks using contains? not nil/false

qqq08:07:16

ah, it's [in (if (contains? args :in) (:in args) chan))]

bronsa08:07:39

semantically yes

qqq08:07:00

great; thanks!

kurt-o-sys08:07:37

@danielcompton @mpenet ok... I've been using cprop before. I might try aero for a change. @dm3 any reason why you don't use one of the clojure config libs?

dm309:07:50

no, I just like that config format

dm309:07:41

well documented, does everything I want

dm309:07:59

question: In Clojurescript it seems that the &env passed to macros contains the def vars as well as locals. How do I get the same in Clojure?

h.elmougy14:07:22

I need to filter this out by matching the inner vector for example this [[:x [3 2]] [:y [1 1]] [:z [3 2]] [:i [3 1]] should be [[:x [3 2]] [:y [1 1]] [:z [3 2]]]

h.elmougy14:07:11

[:i [3 1]] will be removed because the first element of the inner vector appeared before with a different value of the last element

mbjarland14:07:59

is there a clojure naming convention preference for a function which returns a predicate? Assumption here is that some extra data is required to create the predicate and we need a separate function taking that extra data and returning the predicate function

mpenet14:07:31

I think foo-fnis quite common

mpenet14:07:11

at least in clj.core

mjo324_5614:07:10

did anyone try to call an external program with clojure with timeout? none of the examples (conch), (clojure.contrib.shell-out with java.util.concurrent.TimeUni) did work... stuff runs forever

mjo324_5614:07:43

i mean a seperate process

mjo324_5614:07:13

like call a windows exe and kill it after 10 seconds if it still runs

mpenet14:07:23

I think you need to do the bookeeping yourself and call destroy on the Process instance if not completed

mpenet15:07:35

(let [x (.exec (Runtime/getRuntime) "htop")]
  (try
    (Thread/sleep 10)
    (.exitValue x) ;; check value possibly
    (catch java.lang.IllegalThreadStateException e
      (.destroy x))))

mpenet15:07:50

something a bit like that

mjo324_5615:07:05

@mpenet you've seen a good working code example i can copy paste?

mjo324_5615:07:57

this example will not wait 10 secs if the procs dies before?

mpenet15:07:29

it's not a complete example, but you should be able to take it from here

mjo324_5615:07:39

how about getting stdout, stderr from this example?

mjo324_5615:07:31

the problem wit conch was that stdot/err was flushed at the end, which would never happen when process was destroyed earlier

mjo324_5615:07:33

should it be possible to do stuff like (let [x (.exec (Runtime/getRuntime) "htop > mylogfile")] with mentioed example?

noisesmith16:07:17

I don’t think any of the process stuff uses sh, and > is sh syntax, so you need to wrap up your call into a string passed to /bin/sh to make that work

noisesmith16:07:49

or you can create the redirection using the file handles Process gives you if you want to do it the hard/portable way, of course

martinklepsch15:07:36

I have a seq like [:a :b :c] and want to get a lazy seq like [:a :b :c :a :b :c :a :b ....] — any suggestions?

schmee15:07:07

@martinklepsch (cycle [:a :b :c])

martinklepsch15:07:31

@schmee thanks, that’s what I missed! 🙂

aron15:07:16

Hello. I'm looking at https://dev.clojure.org/display/community/Maven+Settings+and+Repositories and wondering about SNAPSHOT releases. In the example, is 1.1.0-SNAPSHOT before or after the 1.1.0 release? In other words, is it supposed to be a pre-release snapshot or a post-release patch?

conan16:07:00

1.1.0-SNAPSHOT means "the version that will eventually be released as 1.1.0"

conan16:07:23

i.e., *-SNAPSHOT comes before *

conan16:07:16

under the hood, every time you lein install a snapshot version, a timestamped artifact is added to your maven repo, and the SNAPSHOT name just points to the latest of these

conan16:07:12

if you use the lein-release plugin then when you're ready to release it, you run lein release and it'll transition your 1.1.0-SNAPSHOT to 1.1.0, commit, tag and deploy that to your maven repo, and then bump the version to 1.1.1-SNAPSHOT, so you're ready to start working on the future 1.1.1 release.

alice21:07:47

Hate to interrupt, but I'm having trouble splitting up the middleware for my different routes in Compojure

alice21:07:56

Anyone have information / a blog post / etc on the topic?

michaellindon21:07:20

I have a question about structural sharing in nested maps. Suppose I have a map called mymap that looks like this

mymap
=> {:mykey [{:A 1, :B 2} {:A 2, :B 2} {:A 3, :B 2}]}
I want to write a function that goes down and increments each value for :A I can do this with
(assoc mymap :mykey (map #(assoc % :A (inc (:A %))) (:mykey mymap)))
{:mykey ({:A 2, :B 2} {:A 3, :B 2} {:A 4, :B 2})}
do the keys :B "point to the same place in memory" after this modification as the original maps? That is, is there structural sharing going on between the maps in the vector before and after this modification?

andy.fingerhut23:07:21

Yes, there is. You can verify yourself whether this is so using identical? on the pieces you hope are being shared, as shown below

andy.fingerhut23:07:26

user=> (def mymap {:mykey [{:A 1, :B 2} {:A 2, :B 2} {:A 3, :B 2}]}) #'user/mymap user=> (def m2 (assoc mymap :mykey (map #(assoc % :A (inc (:A %))) (:mykey mymap)))) #'user/m2 user=> (identical? (-> mymap :mykey (nth 0) :B) (-> m2 :mykey (nth 0) :B)) true

soxley01:07:35

Hmm, my gut tells me that's not a good example because:

user=> (identical? 2 2)
true

soxley01:07:55

This would be a better test:

user=> (identical? {:test 1} {:test 1})
false
user=> (def mymap {:mykey [{:A 1, :B {:test 1}} {:A 2, :B {:test 1}} {:A 3, :B {:test 1}}]})
#'user/mymap
user=> (def m2 (assoc mymap :mykey (map #(assoc % :A (inc (:A %))) (:mykey mymap))))
#'user/m2
user=> (identical? (-> mymap :mykey (nth 0) :B) (-> m2 :mykey (nth 0) :B))
true

andy.fingerhut01:07:25

The better test works, too, as I expected it would. Thanks.

soxley01:07:27

Also, for clarity, there isn't any structural sharing going on within the vectors themselves - only at the same key "paths" between mymap and m2:

user=> (identical? (-> mymap :mykey first :B) (-> mymap :mykey last :B))
false
user=> (identical? (-> m2 :mykey first :B) (-> m2 :mykey last :B))
false
user=> (-> mymap :mykey first :B)
{:test 1}
user=> (-> mymap :mykey last :B)
{:test 1}

soxley01:07:58

Yeah - this is a cool approach to discover the structural sharing. I hadn't thought of using identical? for this.

michaellindon04:07:58

hey @U0DATSMH6 , @U0CMVHBL2 , I didn't know that identical? could be uesd in such a way to examine structural sharing - thanks!

spangler21:07:22

Asymmetry in string/split and string/join makes me sad : (

parts (string/split kafka #":")
        host (string/join ":" (butlast parts))

alricu21:07:46

Hi all, I am trying to write some test in clojure and I need to do some Mocks and proxies, however I cannot figure out how to proxy some java objects and methods I have this function

alricu21:07:18

(defn singletest
  [cert]
  (let [x500principal (.getSubjectX500Principal cert)
        dn (.getName x500principal)]
    (apply str "abcdefg"))) 

alricu21:07:48

cert is a java object of type X509CertImpl

alricu21:07:56

I know that I am not using x500principal and dn; but it is an example

alricu21:07:25

However I am having a hard time trying to do the test

alricu21:07:35

(deftest singletest
  (let [cert (.X509CertImpl)
        x500principal (proxy [X509CertImpl] []
                       (getSubjectX500Principal [] nil))
        dn (proxy [X500Principal] []
                       (getName [] "works"))]
       (is (= "" (c/singletest cert))))) 

alricu21:07:13

throws me java.lang.IllegalArgumentException: Malformed member expression, expecting (.member target ...)

alricu21:07:42

any idea??

alricu21:07:09

someone has worked with certificates before 😭😭

bfabry21:07:29

what is c?

bfabry21:07:13

c/singletest looks like a syntax error

bfabry21:07:30

oh sorry no it's not

bfabry21:07:32

god I'm tired

alricu21:07:05

no worries

bfabry21:07:20

this (.X509CertImpl)

bfabry21:07:23

is invalid syntax

bfabry21:07:42

I think you want (new X509CertImpl) or (X509CertImpl.) (latter preferred generally)

alricu21:07:57

I change it to

(deftest singletest
  (let [cert (proxy [X509CertImpl] []
               (getSubjectX500Principal [] nil))
        x500principal (proxy [X500Principal] []
                       (getName [] "works"))]
       (is (= "" (c/singletest cert))))) 

alricu21:07:07

but I am getting

alricu21:07:14

java.lang.VerifyError: Cannot inherit from final class

alricu21:07:30

this is because X500Principal is a final class

alricu21:07:54

then how can I work around that

bfabry21:07:22

I think you want to implement java.security.Principal not X500Principal

alricu21:07:57

the problem is that I have everything working!

bfabry21:07:05

ditto you probably want to implement X509Certificate not X509CertImpl (program against abstractions, not concretions)

alricu21:07:13

I mean, the only thing left is the test

bfabry21:07:30

ok, test code is still code though

alricu21:07:37

and there is no X509Certificate class from sun.security.x509

alricu21:07:23

what about the final class?

alricu21:07:30

I cannot proxy that

gmercer22:07:45

@spangler what is the asymmetry ?

alice22:07:32

Would anyone know why all my api routes are being broken by CORS and/or the solution?

alice22:07:45

404s and OPTION requests in the chrome console

spangler22:07:49

@gmercer In split the delimiter is last, whereas in join the delimiter is first

spangler22:07:05

I only ever remember they are opposed, never which one is which

gmercer22:07:20

oh, in the args ..

spangler22:07:31

I literally have to try it in the repl every time I want to use them

dpsutton22:07:52

string join works on a collection which always goes in the last positional argument

dpsutton22:07:13

split works on a single object which always goes first positionally

spangler22:07:44

So you are saying the inconsistency is actually an example of a greater consistency?

spangler22:07:28

This must be what Gödel was talking about

spangler22:07:41

Still, why not always have "the thing being operated on" either always last or always first? What value does having one rule for single objects and a different rule for collections provide?

dpsutton22:07:03

(map fn coll) is a very standard idiom

dpsutton22:07:25

think of the threading macros -> vs ->>. basically one is do stuff to object and one is do stuff to collection

spangler22:07:09

@dpsutton But.... that doesn't answer my question

dpsutton22:07:46

i thought the question was why do these seem inconsistent. so then yes the "greater consistency" sounds good to me

spangler22:07:22

I did ask a few questions. The one I was referring to was this: "Still, why not always have "the thing being operated on" either always last or always first? What value does having one rule for single objects and a different rule for collections provide?"

dpsutton22:07:13

well i can't speak to that i guess

spangler22:07:24

@joshjones Funny, they don't answer it there either : )

spangler22:07:31

just show ways to work around it

bfabry22:07:12

I think it's nice having it obviously clear whether code is working on collections or objects myself

joshjones22:07:22

@spangler with things like this I think you are bound to find reasons for doing it one way or another, and just as with anything, there are likely to be differences of opinion. Particularly with functions one does not use very often, you'll need to look at the docstring or IDE hints anyway to determine what it takes, so unless if vexes you greatly, I'd say this is not much of an irritation 😉

spangler22:07:16

@joshjones Appreciated, though it does irritate me every time I have to look it up

spangler22:07:46

It is okay, nothing is perfect

spangler22:07:06

Really I gripe because clojure is so well-designed in most other ways, these funny inconsistencies stand out all the more

joshjones22:07:10

Your point is well taken, and justifying its correctness may or may not be a losing battle -- if that's one of your irritations then I'd say you'll be just fine :thumbsup::skin-tone-2: 😉

dpsutton22:07:10

not sure what your environment is but if in emacs eldoc will solve that for you

spangler22:07:52

@dpsutton Thanks I'll take a look at that

dpsutton22:07:34

if in CIDER, apropos, grimoire, browse ns and eldoc are quite nice

dpsutton22:07:40

i've been using grimoire quite a bit

dpsutton22:07:08

That's awesome. It's just so handy. Much appreciated

mjo324_5623:07:47

can anyone explain me what a java.lang.IllegalArgumentException: array element type mismatch means?

hiredman23:07:48

it means the array type you are calling a java method with doesn't match

mjo324_5623:07:36

so fi it expects an array of ints and i am using an array of strings