Fork me on GitHub
#clojure
<
2015-11-09
>
roberto00:11:21

@twillis: I’ve used like before, but not in sqlite:

(defn find-by-title-or-description
  [db search-term]
  (let [query    "SELECT * FROM recordings WHERE title ILIKE  ? OR description ILIKE ? "
        search-q (str "%" search-term "%")
        q        (-> (h/select :*)
                     (h/from :recordings)
                     (h/where [:or 
                               [:like :title :?title]
                               [:like :description :?title]])
                     (sql/format :params {:title search-q}))]
    (j/query db q)))

roberto00:11:28

that was with honeysql, btw

fluffywaffles05:11:37

Hey, any friendly clojure...ists? willing to help me answer a question? I have a vector of 1s and 0s and I want to sum the 1s and combine the 0s eg, [ 0 0 1 1 1 0 1 0 1 1] => [ 0 3 0 1 0 2 ] It seems like there should be a clojure-y way to do this, but I can't seem to figure it out

fluffywaffles05:11:34

nvm, I figured it out

richiardiandrea06:11:45

@fluffywaffles how did you do it? I would have partitioned by 0 and 1 and then reduced the sublists. Puzzles are always interesting 😄

richiardiandrea06:11:13

ah and flattening at the end...maybe.. I need to try

richiardiandrea06:11:55

For 0 partition you just take first, for 1 paritions you reduce with sum

fluffywaffles06:11:58

I did it using partitions, partly, yeah!

fluffywaffles06:11:13

(->> array
        (partition-by #(= 1 %))
        (map (partial reduce +)))

fluffywaffles06:11:27

I didn't need a flatten at the end, but I could have used that to get it back into normal list format

charliegriefer06:11:52

(->> [0 0 1 1 1 0 1 0 1 1] 
     (partition-by zero?) 
     (mapv #(apply + %)))

charliegriefer06:11:44

I wanted to play, too simple_smile

fluffywaffles06:11:02

@charliegriefer: I like using zero? better; I didn't realize that would work

charliegriefer06:11:33

Yeah, seemed a bit cleaner

charliegriefer06:11:45

I’m constantly amazed by how many built-in functions Clojure has that make so many tasks easier than I expect they’ll be.

luxbock10:11:49

I wish there was one? as well

thheller10:11:33

pos? and neg? are there 😉

bronsa11:11:08

one? is just #{1}

tap11:11:56

or (partition-by identity)

chedgren12:11:11

@tap: wow. That makes such perfect sense. I, too, am I’m constantly amazed by how many built-in functions Clojure has that make so many tasks easier than I expect they’ll be.

mishok1313:11:54

@bronsa: not really, no (group-by (comp boolean #{1}) [1 1.0 1N 1M]) => {true [1 1N], false [1.0 1M]}

bronsa13:11:16

@mishok13: that's the same for (partial = 1)

bronsa13:11:48

I don't think an hypotetical one? would default to == rather than to =

mishok1313:11:30

oh I'm pretty sure it would, just like it does for zero? simple_smile

mishok1313:11:49

in reality of course it just dispatches to Numbers.isZero but that's implementation detail, the semantics are identical to (== 0)

pesterhazy14:11:35

Does anyone have a "gauge" for map/filter pipelines?

pesterhazy14:11:32

I'm thinking of a step you add to your processing pipeline that prints a dot for every 1,000 items processed

pesterhazy14:11:22

@delaguardo: that looks nice (but uses a global (init) function it seems)

delaguardo14:11:05

yes, but also it has re-init function

danielgrosse14:11:51

Hello, someone here, who could me with clj-wamp?

pesterhazy14:11:00

@delaguardo: I just copied the idea of a tick function with dynamic var

delaguardo14:11:53

you’re welcome)

derwolfe15:11:57

Hi - I’m getting an error with lein/clojure typed that I’m not understanding: Caused by: java.io.FileNotFoundException: Could not locate clojure/tools/analyzer/passes/trim__init.class or clojure/tools/analyzer/passes/trim.clj on classpath. This is using clojure 1.7, lein typed 0.3.5, and org.clojure/core.typed 0.3.15. Any tips to debug this? I’m new to both clojure and the java ecosystem.

swizzard15:11:26

@derwolfe: this looks to me like you’re messing something up in your :requires somewhere

derwolfe15:11:09

@swizzard: thanks, I’ll start looking there simple_smile

swizzard15:11:07

i’m not familiar with tools.analyzer, but i suspect that you’re accidentally requiring a var as if it were a namespace

swizzard15:11:07

if you want something named trim that lives in clojure.tools.analyzer.passes, you’ll need to do something like (:require [clojure.tools.analyzer.passes :refer [trim]])

derwolfe15:11:23

swizzard: interesting, it doesn’t look like I’m calling trim directly. I’m guessing a library on which I depend might be...

swizzard15:11:01

@derwolfe: oh weird! maybe try lein-ancient or something?

nha15:11:19

Hello, I'm trying since quite a bit of time to make a deep-walk clojure function (I did ask a question on SO - hope it is ok to cross-post http://stackoverflow.com/questions/33594375/clojure-walk-with-path ).

derwolfe15:11:11

@swizzard: so my error apparently has to do with how we are using Gradual Typing. Sorry for the goose chase simple_smile

xeqi16:11:06

@ghadi: I don't see much java deserialization in clojure, so not too worried from my standalone services (with embeded jetty). If I was running things in a container that brings in a lot of java things I'd be very concerned.

donaldball16:11:59

Is there a substantive difference between require :refer :all and use?

xeqi16:11:45

@donaldball: no, :refer :all was designed to do the same thing

stuartsierra16:11:15

Is there some EDN reader which can capture line/column position for keywords?

bronsa16:11:51

a reader can't do that by definition

bronsa16:11:59

there's no place to attach that information to

stuartsierra16:11:01

Yes, because keywords can't have metadat.

stuartsierra16:11:15

I'm thinking of replacing keyword with some other type as part of the read.

bronsa16:11:30

that sounds really tricky to get right

bronsa16:11:42

also sounds like you want a parser rather than a reader maybe?

stuartsierra16:11:30

yeah, I want to parse EDN but with custom error messages for users who aren't Clojure programmers.

stuartsierra16:11:10

But not enough to write a complete parser simple_smile

bronsa16:11:36

I had plans a while ago to implement tools.reader as a two-pass parsing+data-structure-reification process that might have helped

bronsa16:11:22

never found the time to do it unfortunately, also I worry about the perf implications

stuartsierra16:11:15

yeah, that would be useful in some rare instances, but more complicated than a standard reader

bronsa16:11:30

there actually was a project on github that used tools.reader internals to build an parse tree and had an emitter built on top

bronsa16:11:38

I don't remember the name unfortunately

bronsa16:11:56

I'll let you know if I can remember

stuartsierra16:11:47

no worries, not worth it, thanks @bronsa

benslawski17:11:12

is there a good way to find (or estimate) the size in memory of a clojure.lang.PersistentArrayMap?

benslawski18:11:13

@stathissideris thanks, i'll check it out

stathissideris18:11:01

@benslawski: sorry for the confusion, this has nothing to do with your question!

domkm20:11:06

What is the rationale for (and) => true but (or) => nil?

rm21:11:43

Hi! Please help me. I'm trying to use opencv3.0 in clojure in ubuntu 15.10. And I can't because of the following error:

Caused by: java.lang.UnsatisfiedLinkError:  <...>/target/native/linux/x86_64/libopencv_java300.so: libIlmImf.so.6: cannot open shared object file: No such file or directory
And there is really no such file:
$ locate libIlmImf
/home/s/Downloads/opencv-3.0.0/build/3rdparty/lib/libIlmImf.a
/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22
/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22.0.0
/usr/lib/x86_64-linux-gnu/libIlmImfUtil-2_2.so.22
/usr/lib/x86_64-linux-gnu/libIlmImfUtil-2_2.so.22.0.0
Any idea how to get the lib?

Alex Miller (Clojure team)21:11:38

@domkm can't say I know the history but I would assume and = "true if all (empty set) clauses = true" and or = "true if any (empty set) clauses = true" which lead to those logical answers.

rm21:11:38

@alexmiller: I tried already. The thing is it's ubuntu 15.10 specific. It worked on ubuntu 12.04, and then I decided to upgrade...

Alex Miller (Clojure team)21:11:22

sorry, I haven't used it so don't know any more

devn21:11:35

a bit confused. i am using .addShutdownHook the way I've always down to gracefully handle SIGINT

devn21:11:52

running with leiningen trampoline run -m foo.core as I've always down

devn21:11:05

but it doesn't seem to get called. any ideas?

stig21:11:27

I’m using test.check with a spec like (prop/for-all [v (gen/not-empty gen/bytes)] …) — but the test output for a failing test is not entirely useful. In particular, it says :fail [#object["[B" 0x7fafbfb7 "[[email protected]”]] — is there a way to post-process it, or provide a different printer so I can see which byte array breaks my function?

rm21:11:57

btw, I just forgot to remove target dir after OS upgrade and opencv lib tried to link with not existed lib. With fresh install everything is ok

arcdrag21:11:01

@stig: test.chuck’s for-all implementation has a nice :let block that helps there.

arcdrag21:11:43

So for the property (def p (cprop/for-all [v (gen/not-empty gen/bytes) :let [v-vector (into [] v)]] false)), you would get {:result false, :seed 1447105698037, :failing-size 0, :num-tests 1, :fail [{v #object["[B" 0x24a5b313 "[[email protected]"], v-vector [98]}], :shrunk {:total-nodes-visited 15, :depth 7, :result false, :smallest [{v #object["[B" 0x7a8fb730 "[[email protected]"], v-vector [0]}]}}

stig21:11:59

@arcdrag: fantastic. That’s just what I need!

arcdrag22:11:12

test.chuck has lots of other niceties as well.

lvh22:11:22

If you’re merging maps, is conj considered idiomatic as well? It seems to work quite similarly to merge, FWIW

lvh22:11:01

(conj {:c 5} {:a 1 :b 2} {:a :b}) and (merge {:c 5} {:a 1 :b 2} {:a :b})

lvh22:11:07

… appear to do the same thing

Alex Miller (Clojure team)22:11:26

while they overlap, merge communicates intent better for maps

bsima22:11:53

Does anyone know what is the Clojure equivalent of cljs.core/IWatchable? Specifically, I'm looking to implement notify-watches

Alex Miller (Clojure team)22:11:35

@bsima: I do not think there is an equivalent in Clojure. the watch functionality is contained in clojure.lang.ARef super class

Alex Miller (Clojure team)22:11:28

you could of course create a type in Java or a proxy that extends ARef

Alex Miller (Clojure team)22:11:04

the interface for watching is in IRef

Alex Miller (Clojure team)22:11:34

so you could also implement IRef - then add-watch etc will work with it

bsima22:11:04

I've implemented IRef, add-watch, remove-watch - all I need is the notify-watches function, so I guess I can just make my own protocol called INotifyWatches to implement with my type. I don't think I want to extend ARef...

Alex Miller (Clojure team)23:11:13

prob not - although you can look at the java impl in ARef for how to implement

bsima23:11:55

yeah, thanks alexmiller!

malcolmsparks23:11:06

@domkm: fwiw, there are other examples such as (+) => 0, (*) => 1, and (comp) => identity.

malcolmsparks23:11:41

the result makes sense when you're potentially computing the arg-list, and want the empty list to work sensibly

domkm23:11:35

@malcolmsparks: Yes, that makes sense. I wasn't questioning why the nullary version was implemented. I was just curious about the apparent inconsistency between the nullary versions of and and or.

darwin23:11:10

hello, is it possible to somehow parametrize macros, I

darwin23:11:18

ah, hit enter too early

darwin23:11:21

I’m generating API wrapper library in clojure, and I have info about platform version when api function was introduced, I want my library to do compile-time version checks

darwin23:11:48

I want to let user specify which version of platform he targets and then do the checks at compile time