Fork me on GitHub
#clojure
<
2017-03-02
>
tankthinks01:03:14

is it possible to use custom clojure.spec conformers in generators?

grav06:03:00

I’d like Yada to NOT catch my exceptions when developing, so that my IDE can start the debugger. I cannot find a way to do this, seems exceptions are always handled

dominicm08:03:38

grav: you can set an error interceptor chain. You need to be careful about sending responses though I think, else you may find requests never finish. Btw, #yada is very active

grav06:03:08

Anyone having had the same problem?

ikitommi06:03:58

@andrea.crotti swagger seems to be de facto now, all/most web libs have support for it (using plumatic schema). and there is both openapi3 & spec support soon.

mike70657407:03:44

I'm having trouble creating specs for nested vectors

mike70657407:03:14

For example, creating a spec for [[n]], where n is an integer

mike70657407:03:00

(s/cat :bar (s/cat :foo int?)) doesn't seem to work

mike70657407:03:17

Anyone know what I'm doing wrong?

timrichardt07:03:35

you have to explicitly indicate the nesting with s/spec, e.g. (s/cat :bar (s/spec (s/cat :foo int?)))

mike70657407:03:51

Thanks, that works - I missed that part in the docs

adambrosio07:03:44

in the future i would run (sg/sample (s/gen (s/cat :bar (s/cat :foo int?)))) so you can see what it actually does

adambrosio07:03:56

which in this case gives you ((-1) (-1) (0) (1) (-1) (4) (-1) (-1) (-8) (0))

adambrosio07:03:30

so what’s the reasoning behind s/cat not nesting without s/spec? is the idea that you are still talking about the same regexy spec?

timrichardt08:03:37

adambros, if cat would respect the nesting you would need something else than cat to concatenate two regexes, clojure just chose the way it is and i personally prefer it that way

qqq09:03:53

anyone else find that for storing data, maps work much better than vectors becuase you can do nested updates via update-in, whereas with vectors, it's constant destructuring + rebuilding ?

mpenet09:03:55

if you know the index of the thing you want to modify update-in works just the same

mpenet09:03:25

but maps are generally more useful, true

qqq09:03:37

yeah, do you like (update-in ... [ 3 1 4 1 5 9 2 6] inc) or (update-in .... [:bank-account :checking 2345232] inc)

Matt Butler10:03:36

Do iterators like map pmap doseq exert "backpressure"? If i have a chain of iterators where (A -> B) are both iterators and A iterates faster than B does my seq bundle up between A and B or does B only ask for As output at roughly the speed it can use it?

Matt Butler10:03:12

Maybe It cant be generalised for them all but I'm talking the clojure.core iterators for now.

not-raspberry10:03:11

Not sure about pmap (it may be lazy or eager) but map and friends like filter are single-threaded. There's no implicit paralelism with collection functions. map and filter produce lazy sequences that are realized in chunks of 32 on demand. So (range) returns an infinite lazy sequence but (take 20 (range)) will only realize some initial elements. Since lazy sequences chain nicely, (take 20 (map inc (range))) also won't blow up your memory.

not-raspberry10:03:09

and doseq is a macro, like a for i in sth: loop in Python.

Matt Butler10:03:03

Yeah, sorry i maybe tried to oversimplify my question

Matt Butler10:03:49

I guess pmap is the tricky one since it uses futures

Matt Butler10:03:32

But yeah, now i've thought about it, your answer is correct for things that consume/produce lazy seqs

Matt Butler10:03:46

fits with what i got from my simple (and probably naive) test (doseq [i (map (fn [x] (Thread/sleep 100) (println "in" x) x) (range 1000))] (Thread/sleep 1000) (println "out" i))

benh11:03:28

pmap runs ahead by availalbProcessors +2

benh11:03:32

but is otherwise lazy

jooivind13:03:03

what’s the reasoning behind having lists as the default datastructure? (vs vectors?) is it lisp compatability, or is there more technical reasons for it?

tbaldridge13:03:14

@jooivind lists, which append to the left side of the datastructure fit really well with code transformations. A lot of macros will manipulate the head of the expression. Also it matches the evaluation order of arguments. Lisp evaluates left-to-right, top-to-bottom.

tbaldridge13:03:33

This happens to fit perfectly with lists, which do the same if you use first/next.

tbaldridge13:03:53

but yes, you could write a lisp with vectors.

jooivind13:03:06

obviously- ring buffers

jooivind13:03:24

for efficient front insertion

tbaldridge13:03:53

I suppose, but why go to all that trouble when you can do it with a Cons cell

jooivind13:03:55

but yeah that makes sense

jooivind13:03:33

id say ring buffers are simpler than lists

jooivind13:03:48

but thanks for your thorough explanation 🙂

tbaldridge13:03:29

So...I have to challenge that assertion, what's simpler than: (deftype Cons [head tail])

jooivind13:03:49

the datastructure is java, no?

tbaldridge13:03:49

(->Cons 'println (->Cons 42 nil))

dpsutton13:03:26

ring buffers just cannot be simpler than lists

dpsutton13:03:19

isn't a ring buffer a list with rules about pointing to itself and a complicated dance when removing the last item, etc

jooivind13:03:24

it’s an array

jooivind13:03:33

just that you can wrap around

dpsutton13:03:36

no it's a contract on top of an underlying type

dpsutton13:03:41

the list has no contract

dpsutton13:03:43

it's two pointers

tbaldridge13:03:54

And complex logic on what to do when you have to resize the array

tbaldridge13:03:18

Yeah, a ring buffer is (deftype RingBuffer [array insert-pos end-pos])

jooivind13:03:41

I think i’m coming from this from a different direction than you are arguing.

dpsutton13:03:45

and then it will need to implement some interfaces for inserting and other stuff

dpsutton13:03:11

well, if your ring buffer doesn't wrap around and allow resizing, etc, we aren't talking about the same thing

tbaldridge13:03:37

@jooivind you're right, I don't think I understand.

jooivind13:03:13

interesting answers though

jooivind13:03:22

and I think i understand your points

tbaldridge13:03:38

So what do you mean by a ring buffer being simpler than a list?

jooivind13:03:43

Data is data

jooivind13:03:45

not pointers

jooivind13:03:59

but this is a bit moot

jooivind13:03:06

considering we’re running on the JVM anyways

tbaldridge13:03:35

right, but that's the same in any language, an array of two items in C is exactly the same as a struct with two item pointers.

tbaldridge13:03:54

or more correctly an array of pointers to items in C

jooivind13:03:02

you can have intrusive datastructures

jooivind13:03:18

and arrays can be in memory defined objects

tbaldridge13:03:25

True, but it's really hard to have intrusive data pointers that are fully polymorphic.

dpsutton13:03:26

can you give me an example of an intrusive data structure?

dpsutton13:03:09

looked it up

tbaldridge13:03:11

@jooivind one of the draws of Clojure is that you can arbitrarily nest data: {[1 {2, 3}] :some/key 11 {:my :map}}

dpsutton13:03:15

had never heard of that term

tbaldridge13:03:14

dpsutton: In C++ it's possible to create a union of sorts between types. So that if you have Array<Object> the data for that array contains a flat layout of all the data of the objects.

tbaldridge13:03:35

So Array<Int> is not an array of pointers, it's an array of actual data.

tbaldridge13:03:57

That is next to impossible in C++ without everything inheriting from a common class, in which case intrusive data structures become really inefficient.

jooivind13:03:25

and it’s a very specific implementation

jooivind13:03:35

But still an array in C

jooivind13:03:49

will in effect be a memory area with actual stuff

jooivind13:03:53

not pointers to other stuff

tbaldridge13:03:34

Right, but you really don't want that. Hashmaps require a overhead of close to 100bytes, while an integer may take 4-8bytes. You don't want "Object" to be the size of the largest object in your runtime.

jooivind13:03:01

which is why int is not an object in c/c++

jooivind13:03:03

anyways, thanks for all the responses

jooivind13:03:21

and yes i like clojure

tbaldridge13:03:01

@jooivind think about that though...that's the entire value proposition behind Clojure, arbitrarily nested data. It's impossible to have both. Boost or no, it's not possible without a ton of JIT magic.

jooivind13:03:30

Yeah i’m not saying i want that

jooivind13:03:36

i was just giving examples

tbaldridge13:03:17

And if that was possible Cons cells would still be simpler than arrays, since most arrays in safe languages contain stuff like a length count.

dpsutton13:03:48

and arrays in Clojure are quite different from just a simple area in storage

jooivind13:03:27

but lists are as well ?

jooivind13:03:31

to keep them immutable

dpsutton13:03:46

ah i think i see you're point

jooivind13:03:47

as far as i understand it arrays are shallow trees with buckets

dpsutton13:03:00

i think we were arguing that a list is inherently simpler than a ring buffer

dpsutton13:03:12

but you are arguing that Clojure's implmentations are not necessarily so

dpsutton13:03:18

is that correct?

jooivind13:03:52

that was my first point

tbaldridge13:03:54

Lists in Clojure are just a bog-standard single-linked-list like in any other language.

dpsutton13:03:03

i'm with you now

nooga13:03:22

(defn cons [h t] (fn [c] (if c h t))) (defn first [c] (when c (c true))) (defn rest [c] (when c (c false))) I always do this to my co-workers as a revenge for office pranks

futuro14:03:57

@tbaldridge is the primary difference between the nREPL and your preferred network repl the time at which the supporting functions/libraries are loaded into the host?

tbaldridge14:03:50

@futuro No, it's more that there isn't a reason to load anything on the remote end at all

tbaldridge14:03:34

99% of what a remote repl does can be done by just sending forms over. For example, to get the docstring for a var first you could just send: (:doc (meta #'first))

futuro14:03:15

I hadn't thought about that. Cool, thank you.

tbaldridge14:03:42

@futuro I just looked at refactor-nrepl, apparently that's middleware that runs on the server side of the connection. There's no reason for that, why should my refactor logic be inside my repl server?

patrkris14:03:42

Perhaps this has been talked about before, but are there any plans to provide a way in Clojure to easily create a subnamespace without a corresponding file? I know you can do it now with a combination of in-ns and *ns*, but thought that a more pleasantly looking, bult-in mechanism would be useful. I am asking because of the increasing use of qualified keywords as a means of defining entities and their attributes.

tbaldridge14:03:03

@patrkris Yes and no. Recognize that what you're asking is a possible solution, for the real problem: You want to use ::foo/bar without foo existing as a file. That is something I've seen some discussion around.

tbaldridge14:03:48

Personally I doubt the outcome of that will be something that creates a namespace just to be able to alias it. That seems like a work-around for the root problem of wanting a way to alias namespaces that don't exist.

futuro14:03:01

@tbaldridge looking at the code for refactor-nrepl, it seems that sans all that code living on the server, I'm either recreating most of the logic in my editor's scripting language, passing every form to the repl anyway, or perhaps a mix of the two. With the code living on the server I only need to handle message creation, sending, and reception.

patrkris14:03:51

@tbaldridge I see what you mean. Could you maybe provide anecdotes on what you've done in your own work?

futuro14:03:57

Something like fn documentation is pretty straightforward, but they're doing much more in refactor-nrepl

patrkris14:03:36

Of course, in some cases it makes sense to have a file for the subnamespace for various reasons

tbaldridge14:03:18

@futuro right, but the problem is that if nrepl-baz uses [foo 1.2.3] and I need [foo 3.4.4], I'm sunk, I can only one version of a library, if I use the newer library, it may break nrepl-baz. Not to mention that there's tons of stuff that can conflict. Basically I have to blindly include any deps that are in use by the middleware.

tbaldridge14:03:59

So the crusty-old-programmer side of me wants to tell editor developers: "Go use a real language in your editor...something like Java where you can run Clojure". But I know it's not that easy.

mpenet15:03:13

what's the point of "sequence" xform signature? I am running some quick benches and it seems to always be slower than normal (->> coll (map ..) (filter ..) (remove ...)) etc

mpenet15:03:25

(other than reuse of the xform)

tbaldridge15:03:31

@mpenet can you post your code? A true apples-to-apples comparison would require you to consume all the results of the seqs

mpenet15:03:37

(def x (comp (map inc) (filter odd?) (remove nil?)))


(dotimes [_ 5 ]
  (time (dotimes [i 10000]
          (doall (sequence x (range 1000))))))

(dotimes [_ 5 ]
  (time (dotimes [i 10000]
          (doall
              (->> (range 1000) (map inc) (filter odd?) (remove nil?))))))

mpenet15:03:50

I know I should be using criterium, but it just a quick dirty run

mpenet15:03:11

1800 ish msec for the first, 1500ish for the second (on average), tried different seq sizes as well

mpenet15:03:52

or is there something magic happening with range maybe (I recall it might have specialized path for iteration)

tbaldridge15:03:20

yeah, sequence is a strange beast.

mpenet15:03:27

that might be it (take 100 (repeat 10)) turns it around

mpenet15:03:46

in that case sequence is 30% ish faster

mpenet15:03:05

a lot more actually

tbaldridge15:03:12

yeah, and 1000 items is rather small, that might play into it as well.

tbaldridge15:03:22

there is some spinup time every time you use a transducer

mpenet15:03:28

I tried various sizes, same result

mpenet15:03:22

Sizes does matter indead 100k iterations changes the results too (I guess jit warmup takes time).

schmee15:03:18

mpenet try using Criterium, it tries to compensate for stuff like GC and JIT warmup

mpenet15:03:59

I kinda knew I was heading into strange results land by not using it

tbaldridge15:03:24

and it will also warn you when lein mucks with your JVM JIT settings (as it does by default)

mpenet15:03:57

anyway, sequence is actually quite nice

tbaldridge15:03:45

personally I really like eduction you can use like like a sequence (append stuff to it), but at the end if you use reduce or transduce it's just as fast as a transduce pipeline.

mpenet15:03:57

eduction is nice too yep, using it in a few places, but I somehow discarded sequence early and I am now rediscovering it

tbaldridge15:03:31

so for my own edification, when should I use sequence vs eduction? I never took the time to read-up on `sequence.

gfredericks15:03:13

at a glance my guess is the difference is caching

mpenet15:03:29

sequence will return a lazy seq

gfredericks15:03:42

sequence gives you a lazy seq that you can read extra times for free, but have to keep memory in mind if you do that

mpenet15:03:44

eduction a reducible/iterable

gfredericks15:03:05

eduction gives you a reducible so it takes the same amount of work to process it repeatedly, but might be easier to reason about memory implications

gfredericks15:03:22

also obvious differences if the source data isn't immutable

bronsa15:03:39

@tbaldridge eduction has some head holding implications

bronsa15:03:52

it will keep a reference to the original sequence

bronsa15:03:02

so beware of that

gfredericks15:03:25

@bronsa the original might not be a sequence though, right?

bronsa15:03:33

whatever coll is

gfredericks15:03:39

it might be a reducible thing that queries a database each time you reduce it, for example

bronsa15:03:09

which I guess is what people usually use with eduction

mpenet15:03:15

sequence is apparently a good replacement for the very common (->> xs (map f1) (remove f2) (filter f3))

bronsa15:03:28

also IIRC http://dev.clojure.org/jira/browse/CLJ-1793 fixes that head retention thing in eduction and it's marked for 1.9 so hopefully not an issue in the future

mpenet15:03:34

well when hotspot can do its magic at least (apparently)

gfredericks15:03:51

at one point I was trying to figure out how to remove intermediate data structures in test.check's shrink trees, and I think I concluded that sequence was the only way to do it

mpenet15:03:26

yes exactly, that's why I was using it in the first place

mpenet15:03:07

it's a bit the sidekick of transduce for lazy seqs results

gfredericks15:03:03

@bronsa it should still hold onto the head if the caller is holding onto the return value of eduction, right?

bronsa15:03:56

but not in when you're e.g.`(into [] (eduction .. coll))`

bronsa15:03:09

(i'm going off of memory about this tho, I might be recalling the issue wrong. It's been a while)

jooivind15:03:26

any frequent users of cider here?

nooga15:03:51

I use it every day :]

jooivind15:03:43

I found a channel for it, so i asked my question there 🙂

nooga16:03:15

is keeping a list of atoms in an atom a very bad idea? how else I could model a “mutable” collection of “mutable” records?

ghadi16:03:41

yeah @bronsa @gfredericks eduction will hang on to head while reducing

nooga16:03:48

I don’t want to lock the whole thing when swapping individual items but I still want the list to grow and shrink.

7h3kk1d16:03:21

@nooga is it a huge performance problem just to use one atom?

7h3kk1d16:03:03

If that did become a problem I might just use a indexing atom or something to keep track of some sort of Ids for the others and store the others in their own atoms but not nest them themselves.

7h3kk1d16:03:30

I’ve never tried though and a basic google turned up this so take it with a grain of salt http://stackoverflow.com/questions/8117404/clojure-states-within-states-within-states

nooga16:03:14

Slight, the records are holding state associated with open websockets - I could easily get away with making this state completely local to the websocket handlers but then I will not be able to access it in any way if I’d like, for example, to write some kind of admin UI that will allow me to modify the data, kill sockets etc.

nooga16:03:02

So basically, what I have is just a bunch of atoms holding records and they’re local. What I want is to keep track of them globally.

7h3kk1d16:03:30

Unless you’re bashing each of those states constantly you can probably just store them all in one atom.

nooga16:03:18

but then I will have to do lookups every time I want to access/change a record, instead of just touching an atom that’s local to my handler

7h3kk1d16:03:56

So you can use assoc-in, get-in, update-in, etc. to deeply modify the atom

7h3kk1d16:03:08

If you just don’t want to refactor your current handler that’s different

nooga16:03:02

(defn make-handler [socket] (let [state (atom {}))] (fn [msg] … (swap! state assoc :foo 1))) vs (defn make-handler [socket] (let [state (new-global-state))] (fn [msg] … (swap! global-state assoc-in [state :foo] 1)))

nooga16:03:17

and then suddenly the handlers must care about global state

not-raspberry16:03:18

@nooga Use cursors to provide partial view. And deref cursors in components.

nooga16:03:37

oh, I thought that cursors are only in reagent

tech_hutch16:03:28

I have a question. In JavaScript, you can place variables directly in object literals, with no key, and they're added with the variable name as the key. Is there a shortcut like this in Clojure, for maps? (I'm actually making a JS object, but the syntax uses a map.)

nooga16:03:34

and I’m writing in Clojure, this is server-side

7h3kk1d16:03:04

@nooga can’t you just make a function that transforms the individual handlers state in the atom and pass that to the handler.

7h3kk1d16:03:18

Like a partial that just does the assoc-in so it’s transparent to the handler

nooga16:03:47

hm, good idea, but I would take it further and write some kind of universal proxy for swap!, which is essentially a cursor 😉

tech_hutch16:03:05

Basically, what I'm asking is I'm making a map with keywords mapped to local variables (made with let) that are the same as the keywords. Is there any shortcut for this?

residentsummer17:03:21

tech_hutch:

(defmacro ->map [& symbols]
  `(hash-map ~@(interleave (map keyword symbols) symbols)))

residentsummer17:03:25

yep, the same question was few days ago

residentsummer17:03:27

it’s just I was too slow finding that answer again 🙂

tech_hutch17:03:10

Is one better than the other?

residentsummer17:03:10

nope, they are the same

tech_hutch17:03:31

I tried it on http://clojurescript.net/, and it returns (hash-map).

tech_hutch17:03:05

Does that mean it returns a function, or another type called hash-map? (Sorry, I'm new to Clojure.)

residentsummer17:03:25

does the one from plumbing works there?

tech_hutch17:03:50

Nope. That one seems to always return an empty map, so it could be a problem with that repl.

residentsummer17:03:06

I remember that there is some specifics with macros in cljs

residentsummer17:03:11

e.g. when you are requireing macros in .clj, you do it as any other non-macro

residentsummer17:03:43

but when you’re in .cljs, it’s done via special require-macro

residentsummer17:03:24

I guess it means that you can’t test macros at that site with repl

tech_hutch17:03:13

I guess so. Thanks for your help.

residentsummer17:03:35

you’re welcome

gfredericks16:03:43

@tech_hutch macros can do it, but there's no way to do it with curly braces, which I've found ruins it for me

tech_hutch16:03:18

Okay, thanks.

tech_hutch16:03:27

I'll just do it by hand.

gfredericks16:03:43

you made a data reader like #local-map {:_ foo bar baz}

gfredericks16:03:57

where you'd need some dumb placeholder like :_ to get an even number of entries

gfredericks16:03:08

which would drive me bananas

tech_hutch16:03:53

Well, you could use a vector for the syntax instead, I suppose.

tech_hutch16:03:27

That's more work than it's worth, I think, since this is only one time I'd use it.

tech_hutch16:03:17

Oh, someone's already done it?

7h3kk1d16:03:19

That’s nifty

tech_hutch16:03:13

That's not in CLJS core, is it?

tech_hutch16:03:23

I mean, it's a library?

gfredericks16:03:36

correct it's a library

nooga16:03:38

just steal borrow the macro 😛

gfredericks16:03:08

it's one line

7h3kk1d16:03:17

How little code can you steal without violating licensing

dpsutton16:03:10

> Distributed under the Eclipse Public License, the same as Clojure.

tech_hutch16:03:10

Violating licensing? It's under the EPL.

7h3kk1d16:03:51

Oh is the EPL commercial useable?

7h3kk1d16:03:54

like apache?

tech_hutch16:03:13

It's an open source license.

tech_hutch16:03:23

Oh, commercially? I don't know.

tech_hutch16:03:26

I would assume so.

7h3kk1d16:03:36

Yeah, GPL is a public license but you can’t use the code unless you opensource your code.

7h3kk1d16:03:40

Or don’t redistribute it

tech_hutch16:03:50

Quick question: if I would use a macro like keyword-map, could I put #js before it to make it a JavaScript object? (In CLJS, of course)

7h3kk1d16:03:37

I think so, but not sure.

tech_hutch16:03:07

Okay. I'll try it.

7h3kk1d16:03:36

I can’t get the macro to work with http://clojurescript.net

tech_hutch16:03:11

I was just trying that, myself.

tech_hutch16:03:25

It returns an empty map.

7h3kk1d16:03:43

I would consider posting in #clojurescript

7h3kk1d16:03:48

they might know what’s going on

stathissideris17:03:48

how come I can set! *warn-on-reflection* but I can’t do the same for my own dynamic var?

gfredericks17:03:25

set! requires that the var have a thread-local binding

gfredericks17:03:28

and it only changes that

gfredericks17:03:34

(in contrast to alter-var-root)

gfredericks17:03:52

there are some special vars, like *warn-on-reflection*, that the compiler and/or the repl set up thread-local bindings for

jaymartin17:03:30

How can we build better "first contact" experiences for new programmers and Clojurians? Our open source learning group is hosting the free online webinar Essential Klipse this Saturday at 7 pm UTC to address that question. Everyone is welcome! http://discuss.thevalueoflearning.org/t/webinar-discussion-2-essential-klipse/39?u=jay

nooga18:03:05

I just found out that clojurescript interfaces are totally different from clojure interfaces :S

hiredman18:03:25

do you mean protocols?

nooga19:03:35

hmm… I think that there are interfaces defined in clojure.lang

nooga19:03:32

I think I just got deref,`reset!` and swap! working but I still need the others 😮

tbaldridge19:03:49

yeah, they're all named slightly differently,

tbaldridge19:03:16

a few pointers: IMeta -> IObj

tbaldridge19:03:55

IPrintWithWriter -> is the clojure.core/print-method multimethod (extend that instead of using a protocol)

tbaldridge19:03:29

and IWatchable -> clojure.lang.IRef

hiredman19:03:07

protocols on the clojurescript side and interfaces on the clojure side

mruzekw19:03:25

Has anyone here worked with alumbra (graphql for clojure)?

nooga19:03:13

@tbaldridge looks like it actually works! I’m surprised with how straightforward that was given that I just deftyped something that looks and quacks like one of the core types 😄

tbaldridge19:03:53

yep, that's the awesome thing about clojure almost everything is backed by really simple interfaces. These interfaces were broken up even more in CLJS, but CLJ is still really good.

jjttjj19:03:39

are there any libraries out there that help in turning xml to edn, something higher level than the data.xml elements. so the resulting structure is just a recursive clojure map of tag name to the content of the element?

futuro20:03:21

@tbaldridge Yeah, I hear that. It's personally a price I haven't had to pay yet, but I can definitely see that as a possibility. I've wanted a way to load multiple versions of the same dependency into a project -- specifically to avoid dep collision between my code and libraries -- but haven't spent the time to learn about dependency resolution/namespacing to do anything meaningful about that desire.

zerocooljs20:03:20

hi please can you help me?? how I can make a spec case insensitive:

(s/def :vtex/channel #{"KUSHKIPAGOS"})

Alex Miller (Clojure team)20:03:08

you could replace that with #(= (clojure.string/upper-case %) “KUSHKIPAGOS”)

dpsutton21:03:05

I love your username, @zerocooljs

zerocooljs21:03:16

@alexmiller thank you that works!!

tech_hutch21:03:39

lol. zerocoolclj

qqq21:03:34

(into {} [[1 2] [3 4]]) <-- works (into [] ((1 2) (3 4))) <-- does not work now, I have a list of even length, and I do (into {} (partition 2 lst)) <-- does not work how do I make this work?

dpsutton21:03:15

qqq, can you post the error that you are getting on teh second one? ((12) (34))

jjttjj21:03:09

@qqq the map entries specifically have to be vectors i believe

qqq21:03:09

(into [] `((1 2) (3 4)))
gives: No protocol method IMapEntry.-key defined for type number: 1

dpsutton21:03:26

ah ok, i was just making sure you were quoting the list

jjttjj21:03:49

so (into {} (map vec (partition 2 lst))) should work I believe but I think there might be a better way to accomplish what you're trying

qqq21:03:09

@jjttjj: confirmed that works

plins21:03:31

hello everyone, im new to clojure and the JVM in general... i have an existing database, which is, unfortunately full of triggers .. i have a field (phone region prefix) which isnt optional ( you have to provide a value ), but there are triggers that calculate those values and input them for me if i try to make a insert statement on the mysql CLI, everything goes fine, but when i try to run it via JDBC I get an java exception java.sql.SQLException: field 'ddd' doesn't have a default value [6:10] is there a way to mimic the CLI behaviour?

(defn create-usuer
  [^String email ^String phone ^String username ^String cpf]
  (jdbc/insert! db :tb_usuario {:tipo "p"
                                :logado 0
                                :ativo 1
                                :idPaisTelefone1 1
                                :telefone1 phone
                                :usuario email
                                :email email
                                :senha "hash the cpf"
                                :celular phone
                                :cpf cpf
                                :dataCriacao "NOW()"
                                :dataAtualizacao "NOW()"
                                :nome username}))
this is how im trying to insert it

hiredman21:03:30

"NOW()" like that is going to attempt to insert the literal string NOW(), not call the mysql function

plins21:03:53

@hiredman thanks, but i getting errors prior to this 😕

hiredman21:03:59

inserting a record like that escapes all the values

dpsutton21:03:22

what is field ddd?

plins21:03:26

isnt defined in the query, its a field which the pre-insert trigger is supposed to take care of everything is fine when i try to insert it via CLI

plins21:03:21

will take a look

plins21:03:11

@hiredman, thank you very much, this looks like the problem!

dpsutton21:03:51

https://github.com/clojure/java.jdbc/blob/master/src/main/clojure/clojure/java/jdbc.clj#L1111 this looks like the code that makes the query in jdbc. You could perhaps see what code it is generating and compare to what you are running from the cli

seancorfield21:03:02

@dpsutton According to the link @hiredman gave, the difference is “strict” mode — JDBC is stricter than the CLI.

dpsutton21:03:12

whoops. my bad

hiredman21:03:31

I saw a mailing list post somewhere that it has changed in newer versions of mysql

seancorfield21:03:39

As I said in #sql I was surprised that CLI even allowed it!

seancorfield21:03:52

Ah, so CLI is strict by default now?

hiredman21:03:19

I think they did the reverse of course 🙂

seancorfield21:03:51

Ah, so a more recent JDBC driver might have a different behavior too?

hiredman21:03:19

or a more recent mysql-server

mobileink21:03:08

howscome nobody uses slack threads here? not complaining, juswondering. not useful?

qqq21:03:08

threads are a rather low level primitive

qqq21:03:33

@mobileink: it's easier to reason about stms + queues than locks/mutual exclusion

mobileink21:03:49

no, i mean slack threads.

qqq22:03:14

@mobileink: the ui is weird and often it's easier to just DM people

mobileink22:03:38

this channel is a firehose. i go away for a day and there are 9000 messages waiting. threads would help with that, in principle. but maybe they're not so great in practice?

hiredman22:03:21

chat is something you consume more or less live

mobileink22:03:24

sure, but dm is private, no?

qqq22:03:58

why do you want to read the channel log?

mobileink22:03:57

qqq: a) so i can keep up with the cool kids, and b) so i don't embarrass my self by asking a quetion that was answered 3 hrs ago.

tech_hutch14:03:44

When you have a question, you could always just search right before asking, to see if it was answered recently.

dominicm14:03:34

It's way easier to track parallel conversations when they're in threads. (funny how that relates to primitives)

mobileink22:03:01

@hiredman except when you can't.

qqq22:03:03

all the important stuff goes into blog posts anyway

mobileink22:03:20

sgnl: i can't keep up, but my friend the Web tells me that means "fear of missing out". lovely, and exactly right!

sgnl22:03:40

yeah I have to try real hard to ignore all the chats. Turining off notifications (muting channels) works well 😉

mobileink22:03:44

but ... then i might miss out!

mobileink22:03:49

the other reason: on the main channel everything gets mixed up. not a tragedy, but it does make it harder to follow the conversation.

qqq22:03:22

is there a variant of (let[{:keys [foo bar dog cat]} ... ]) that also says assert that foo, bar, dog, cat are NOT nil ?

andrea.crotti22:03:11

mm this doesn't look right

At src/cljs/scrabble/views.cljs:86:
Consider using:
  :div
instead of:
  (fn [v] [:div v])

andrea.crotti22:03:16

one of the suggestions from kibit

andrea.crotti22:03:39

should probably file a an issue unless I'm missing something obvious

weavejester23:03:14

@andrea.crotti no, pretty sure that’s a bug 🙂

mike70657423:03:52

Can anyone give me a clue as to how I could create a spec for a collection with frequency limits for distinct items? An example might be a vector that contains at most two 0's and one 1, where [0 0 1] would be valid, but [0 0 0 1 1] wouldn't.

mike70657423:03:18

Assuming that's something that can be done

ghadi23:03:38

since spec is a predicative system, your step #1 is to make a predicate that identifies such a collection

ghadi23:03:09

after you do that, clojure.spec/and is your friend

moxaj23:03:12

@mike706574 you could do (s/and <your-coll-spec> (fn [coll] (let [freqs (frequencies coll)] <verify-freqs>)))

mike70657423:03:44

Ah, that makes sense