Fork me on GitHub
#clojure
<
2016-08-11
>
josh_tackett01:08:48

Can anyone show me how to do a java script hover on this element: #clj_webdriver.element.Element{:webelement #<Tag: <li>, Class: dropdown-submenu pull-left, Value: 0, Object: [[ChromeDriver: chrome on XP (8ff1a709570edb6244915d8fb4bd8c04)] -> xpath: //li[@class='dropdown-submenu pull-left']]>}

josh_tackett02:08:57

yep got it šŸ™‚

tap04:08:05

Question from @lamelambda in #C03RZGPG1 room >[{:keys [state] :as env} key params] - this are the parameters of the read method >Specifically what does this represent? {:keys [state] :as env} >Does this represent the map of keys which is exposed as an env?

tap04:08:37

yes, {:keys [state] :as env} represent a map. The whole map will be bound to env and value of :state key will be bound to state

tap04:08:38

This feature is called Destructuring. You can read more about it here http://clojure.org/guides/destructuring#_associative_destructuring

lamelambda04:08:13

thank you! i got tripped up by that!

kauko04:08:07

Note that you don't need the :as env part if you only care about the value under the state key šŸ™‚

kauko04:08:34

There's also another way to destructure maps, but I prefer the one you mentioned

kauko04:08:16

@lamelambda: in the future please use #C053AK3F9 for questions, the channel you used is for announcements only to almost 7k people

lamelambda04:08:25

sure - will be more prudent in the future! first time on this channel!

lamelambda04:08:23

i got the :as point as well - thanks!

bur06:08:53

trying to parse the login field i get back from http-kit.client/get "" tried cheshire and clojure.data.json

bur06:08:06

but no success

shidima06:08:38

Iā€™m looking for a gui lib, and I found seesaw. Is there any other you could recommend?

urbanslug08:08:21

hey how come I canā€™t (map and ā€˜(false true))

joost-diepenmaat08:08:20

because you canā€™t map macros

urbanslug08:08:40

I guessed it was because and was a macro but wasnā€™t sure

urbanslug09:08:04

is there anything I can use for such?

joost-diepenmaat09:08:05

in this case you could do something like (map #(and %) ā€¦)

joost-diepenmaat09:08:16

but it depends on the macro

urbanslug09:08:31

but and takes two args

urbanslug09:08:37

you gave it just one?

joost-diepenmaat09:08:38

and takes any number of args

joost-diepenmaat09:08:53

and your map will only supply one arg

joost-diepenmaat09:08:39

maybe you want something like (map #(and %1 %2) [[false true]]) ?

joost-diepenmaat09:08:08

oh wait that wonā€™t work

urbanslug09:08:17

naaaah I want it to take many args

urbanslug09:08:26

Idk at this point how many

joost-diepenmaat09:08:28

then you donā€™t want to map

joost-diepenmaat09:08:38

what are you trying to do?

urbanslug09:08:04

maybe I can use map instead of apply

urbanslug09:08:07

Let me show you

joost-diepenmaat09:08:23

something like (every? identity [arg1 arg2 arg3 ā€¦])

joost-diepenmaat09:08:56

note that if you donā€™t know how many args, you canā€™t actually write (function arg1 arg2 argā€¦)

urbanslug09:08:57

(def from-form-id "123ā€)
(def forms [{:formid "123"} {:formid "456"}])
(r/fold and (fn [form] (not= from-form-id (:formid form))) forms)

urbanslug09:08:18

gnejs: yes I actually want a reducer

urbanslug09:08:34

(require '[clojure.core.reducers :as r])

urbanslug09:08:48

but the and wonā€™t work

urbanslug09:08:55

let me look at every

joost-diepenmaat09:08:44

(every? (fn [form] (not= from-form-id (:formid form))) forms) I think that would work

joost-diepenmaat09:08:55

also, every? returns when the first test fails, r/fold etc need an explicit (reducedā€¦ ) call otherwise it will always test the whole collection

urbanslug09:08:24

Thatā€™s a good thing

urbanslug09:08:45

Only question is whether every? will iterate over the forms

joost-diepenmaat09:08:33

it should - until itā€™s found an exception

urbanslug09:08:02

yaaaay it worked

urbanslug09:08:15

this is waaay efficient than using a reducer

urbanslug09:08:19

Thanks šŸ™‚

joost-diepenmaat09:08:27

youā€™re welcome

urbanslug09:08:27

should look at the simpler tools first

jamesmintram12:08:05

So a bit of an odd question (and probably has highly opinionated answers) but I wanted to get a rough idea of what people thought. I am currently weighing up the use of Elixir vs Clojure for running a web server to handle many concurrent Web socket connections. Now Elixir/Phoenix seems a natural fit for this and you see benchmarks demonstrating how far it scales (I doubt this has an bearing on real life load) but most of our infrastructure is written in Clojure. So the question is - would you consider taking on another language/ecosystem because it is a better fit for a particular job (and I am not even sure how much better it would be at the task) vs using a tool that is already a large part of your existing ecosystem. And in case anyone knows the answer to this, does Elixir/Phoenix exceed Clojure/JVM by a significant margin under real world loads for this kind of task?

jamesmintram12:08:06

(I may also ask this on SO as the question feels bigger than I originally anticipated šŸ™‚ )

yonatanel13:08:23

@jamesmintram: I would try to stay with clojure and look for a server that supports "many" concurrent websocket connections, perhaps using aleph (https://github.com/ztellman/aleph)

dhruv113:08:01

i need to send a get request which has a body. how do i do that using one of clojure libraries?

chris13:08:39

why do you want to send a GET with a body?

chris13:08:10

you can, but itā€™s not really done afaik

chris13:08:58

https://stackoverflow.com/questions/978061/http-get-with-request-body this page has lots of reasons to not, especially regarding caching

dhruv113:08:57

thank you. The rest API i am using requires it.

pesterhazy13:08:24

yeah it's weird that you're not supposed to send a request body with GET -- encoding as query params is so inconvenient

chris13:08:36

can you not just set a {:body } in the GET?

chris13:08:58

looking at cljs-http and clj-http it looks like request will accept that

chris13:08:20

or rather, doesn't specifically forbid it

bur14:08:05

I kinda got a roadblock with http-kit/client

bur14:08:35

how do I parse a json response that i get with client/get? I tried cheshire and clojure.data.json to no avail.

bur14:08:12

(http/get ""
    (fn [{:keys [status headers body error]}]
      (if-not error
        (parse-string body))))

bur14:08:30

leaving out parse-string gives me the json that i expect

bur14:08:44

but I am only interested in the login field for now

chris14:08:49

so it seems like for some reason parse-string is lazy

chris14:08:56

adding a println works for me

chris14:08:23

the doc says that if the top level object is an array it will be processed lazily, but itā€™s not

chris14:08:43

nvm itā€™s just the future thatā€™s causing the problem

chris14:08:57

dereffing fixes it

bur14:08:35

okay, for a noob whats dereffing šŸ™‚

bur14:08:48

and thanks for taking your time to look at my problem

bur14:08:00

something like (parse string @body) ?

chris15:08:39

so http/get returns a future

chris15:08:02

so deref the whole form @(http/get ā€¦ )

chris15:08:37

or (let [f (http/get ā€¦)] @f)

ag15:08:02

how can I write a defmulti that dispatches on a vector not a map? i.e.: instead of something like this:

(defmulti greeting :language)
(defmethod greeting "English" [_] "Hiā€) (defmethod greeting "French" [_] "Salut")
(greeting {:language "English"}) ; => ā€œHiā€
It could be called more like this:
(defmethod bar :foo [label amount] ā€¦.)
(greeting :foo ā€œTitleā€ 42)

bur15:08:12

so i would parse the dereferenced value @chris?

chris15:08:04

@(http/get ""
           (fn [{:keys [status headers body error]}] ;; asynchronous response handling
             (when-not error
               (parse-string body))))

chris15:08:04

sorry couldnā€™t figure out the formatting

chris15:08:11

thatā€™s what I have

chris15:08:35

so itā€™s basically the same as yours

chris15:08:10

then it returns edn

dominicm15:08:47

Err, I didn't see the :foo part, ignore that.

dominicm15:08:28

@ag: defmulti takes a function to dispatch on as the value. I don't really understand your question very much. Can you provide another example of what you're trying to achieve?

bur15:08:00

Thanks chris šŸ™‚

gnejs15:08:48

(defmulti greeting (fn [lang _] lang)) (defmethod greeting ā€œEnglish" [_ b] (str ā€œHello, ā€œ b)) (greeting ā€œEnglishā€ ā€œagā€) ;;=> ā€œHello, ag"

gnejs15:08:00

Maybe something like that, @ag ?

gnejs15:08:16

(Not sure I understand your use case though)

gfredericks16:08:09

is it still hard to run a single clojure.test test with fixtures?

gfredericks16:08:18

(from a repl)

pesterhazy16:08:55

hard but not impossible šŸ™‚

pesterhazy16:08:34

you can use run-all-tests with the appropriate regex (but maybe that matches only namespaces?)

pesterhazy16:08:12

you can run the fixtures manually I believe, e.g. (-> my-test schema.test/validate-schemas .call)

ag16:08:46

@gnejs: I still canā€™t wrap my head around multimethods. Every example I found describes it how to make it work when a map being passed. But I need something like this:

(defmulti element ...)

(defmethod element :text-field
  [ctx label key]
  (html [:div.text-field label]))

(element :text-field "This is a simple text-field" :main-text-field)
I can of course make it work easily if I was ok with it to be invoked like this:
(element {:type :text-field :label "This is a simple text-field" :key :main-text-field})
but this seems to be unnecessarily cumbersome

ag16:08:59

also a side question; mutlimethods in clojure and clojurescript are the same? at least syntactically? In my case Iā€™m actually need them in cljs

grzm16:08:02

@ag: that :text-field keyword in the defmethod is the dispatch function (the keyword acting as a function in this case on the argument passed in)

ag16:08:30

I understand, yet Iā€™m struggling with the correct syntax

grzm16:08:43

@ag: are you still working on that language example from above?

ag16:08:53

tryingā€¦. donā€™t seem to be much successfully šŸ˜ž

gnejs16:08:51

@ag: did you try my example?

ag16:08:20

in this exact snippet, how exactly defmultiā€™s body should be in order it to work:

(defmulti element ...)

(defmethod element :text-field
 Ā [ctx label key]
 Ā (html [:div.text-field label]))

(element :text-field "This is a simple text-field" :main-text-field)

grzm16:08:21

@ag: Yeah, I'm not sure I understand the use case either

gnejs16:08:21

(defmulti element (fn [context _ _] context))

ag16:08:35

so I can render an element and have access to all 3 params in the function ctx, label and key

gnejs16:08:54

(and, if youā€™re getting strange arity errors in the repl - try restarting the repl. Iā€™ve read something about defmulti being sensitive to arity changes)

ag16:08:42

so, defmulti should wrap a function that returns thing that it would dispatch on, in this case first argument, in my exact case it is :text-field keyword, right?

gnejs16:08:49

the function defined by defmulti returns a value. That value is used to select the proper defmethod. So in my example the function simply returns the first argument.

ag16:08:29

now in the defmethod it should also have equal number of arguments?

ag16:08:36

in this case exactly four?

gnejs16:08:16

Why 4? [ctx label key], thatā€™s three?

ag16:08:54

this finally worked for me:

(defmulti filter-element
  (fn [type _ _ _] type))

(defmethod filter-element :text-field
  [_ ctx label key] ...

gnejs16:08:25

ah - I thought that the :text-field was the ā€œctxā€ šŸ™‚

ag16:08:05

no, ctx in my case is the context of ui-component from which itā€™s being called

ag16:08:09

not really related

ag16:08:27

now finally I think I understand how multimethods work.

ag16:08:32

Thanks a lot!

gnejs16:08:34

:thumbsup:

grzm16:08:39

I'm debugging what looks like a server-side transit encoding issue. While debugging, I want to create an edn literal that includes an #C06DT2YSY/id tagged literal. Here's what I'm trying:

(def edn-body
  {some/new-item {:tempids {#om/id["2e486bfc-aacb-4736-8aa2-155411274e84"] 852154481843896390}}})
When I do so, I'm getting No reader function for tag om/id Is there a way to quote this so the compiler ignores it? Or include a reader?

ag16:08:21

@grzm ehhhā€¦. prob, really stupid suggestion. maybe handle it in :default handler for read?

grzm16:08:04

@ag: thanks. I'll look into that.

grzm17:08:23

I ended up constructing the id instead:

(def edn-body
  `{some/new-item {:tempids {~(tempid/tempid "2e486bfc-aacb-4736-8aa2-155411274e84") 852154481843896390}}})

grzm17:08:30

Google didn't help me find a way to add a handler to the clojure reader

ag17:08:56

now I dug up and opened another can of worms. I have no idea where to put docstring for defmethod. Google not helping

ag17:08:39

right, but kinda strange, in ordinary functions youā€™d put docstring before params

hiredman17:08:41

that isn't a docstring

hiredman17:08:47

it is a string literal

hiredman17:08:02

defmethods don't have a place to put docstrings

hiredman17:08:25

docstrings exist as metadata on a var, defmethods don't have their own var

zackbleach17:08:26

does anyone have a link to a blog post / one pager / any explanation of why hot reloading in Clojure seems (is?) so much more robust than hot reloading in Java?

chris17:08:20

this is nonscientific but I would imagine it has a lot to do with the way each handles state

chris17:08:30

java itā€™s everywhere, clojure itā€™s siloed

Alex Miller (Clojure team)18:08:08

Because Clojure DynamicClassLoader is much different than the typical Java class loader hierarchy

Alex Miller (Clojure team)18:08:32

And because Clojure programs have late binding via vars

Alex Miller (Clojure team)18:08:39

In Java one method calls another. In Clojure, a function looks up a var, resolved it to a function, then invokes it

Alex Miller (Clojure team)18:08:54

So if the var has changed, you see it

Alex Miller (Clojure team)18:08:37

The DCL helps in making new classes immediately visible globally

Alex Miller (Clojure team)18:08:04

by ā€œgloballyā€ I mean up and down a tree of DCLs (as they share a static class cache)

zackbleach18:08:35

tree of DCLs?

zackbleach18:08:59

I think I need to spend some hammock time on the DCL

Alex Miller (Clojure team)18:08:27

there are cases where you will have nested DCL instances

Alex Miller (Clojure team)18:08:26

I have not worked on it in long enough that I can not precisely describe when that happens and when it does not, but looking at where DCLs are created in the source can tell you that

zackbleach18:08:29

thanks, Iā€™ll look it up

hueyp18:08:59

does reify have garbage issues? e.g. thinking if I reify something per request.

hueyp18:08:37

basically I have no idea if generating a class creates something that is persistent forever? šŸ˜œ

hiredman19:08:59

No at compile time reify created a class, and at runtime you just get new instances

hiredman19:08:29

You would only get new classes every request if you where using eval

hiredman19:08:56

On older jvms classes are part of what is called the permgen space, which means they are not garbage collected, but newer jvms get rid of the permgen, so classes can get gc

andrewboltachev20:08:08

Hi. Is there a separate channel to discuss project ideas/finding people with similar interests etc?

dpsutton21:08:37

I can't imagine a channel dedicated to that, and if there was it would have 5 participants

dpsutton21:08:40

just talk about stuff there

didibus22:08:12

I'm wondering now that specs are coming in 1.9, is it better for me to model my entities as records or simple maps. Which one will be easier to add spec functionality to it

andrewboltachev22:08:44

@dpsutton: yes, sorry. that sounded more like offtopic. And what's worse sounds like I'm begging. Now I understood it would be still more interesting to work on that "ideas" myself šŸ™‚

dpsutton22:08:05

oh i didn't mean you were being offtopic to this room, just that that would be a great place to talk to people

Alex Miller (Clojure team)22:08:07

@didibus: you can spec either (but plain maps are currently a little nicer)

dpsutton22:08:22

lots of people are there and you could probably find collaborators

andrewboltachev22:08:31

@dpsutton: yeah, sure, I've been here for a while too. So thanks for answering

dg22:08:45

@didibus I keep falling into a pattern of using spec on maps, and then using a multimethod to build records out of the conformed values (since you can dispatch on the name returned from s/or)

didibus22:08:20

@alexmiller: I see, so unless I want protocols, map seems like the way to go for Spec.

didibus22:08:21

@dg: Hum, so do you use the record in your code, but create the record using a map through a multimethod which validates the spec and returns the record?

dg22:08:39

Most useful when you're using protocols as you said

didibus22:08:05

Ya, that actually sounds like a pretty nice solution

lvh22:08:42

What are the current best practices re: tooling that might have its own dependencies but canā€™t conflict with the software it runs? Iā€™m asking for cloverage, which would like to use e.g. a templating engine but canā€™t conflict with the software it instruments. Iā€™m guessing part of it is ā€œminimal core with basically no dependencies, extended processing around it that runs in a separate processā€?

danielcompton22:08:03

@lvh Iā€™ve run into this painful problem several times, your options are minimal core with no deps, manually vendoring deps you need, or using something like https://github.com/benedekfazekas/mranderson

danielcompton22:08:15

Also keep in mind that Leiningen deps are uberjarred, so you wonā€™t see any warnings for conflicts, but you will silently get the Leiningen versions instead of your ones

danielcompton22:08:24

You probably know this already, but for completeness, keep in mind that Leiningen plugins run in Leinā€™s JVM and dependency space unless you use the eval-in-project function

lvh23:08:36

heh, I guess that confirms my fears šŸ˜„ Thanks @danielcompton šŸ™‚ For cloverage I think itā€™s going to be the minimal core solution, I donā€™t think itā€™s a very big deal; thereā€™s already a clear separation between instrumentation and processing of resulting data

hiredman23:08:53

Have you looked at what Eastwood does?

hiredman23:08:09

It vendors the namespaces of everything

lvh23:08:13

that sounds like a higher-effort version of what mranderson accomplishes though

lvh23:08:15

maybe Iā€™m misunderstanding it