Fork me on GitHub
#clojure
<
2015-07-07
>
kongeor08:07:45

Hello, I want to use core.match, but I want to load the patterns from a file or db, is there a clean way to do it ?

socksy08:07:39

what do the patterns look like in the file?

kongeor08:07:07

it's exactly the same as in the patterns, for example ["foo" "bar" _ 1] could be one entry, where the first three would match to the value 1, makes sense ?

socksy08:07:21

(read) and (read-string) are your friends then, that should be fairly straightforward simple_smile

zoldar08:07:52

@kongeor @socksy there's also clojure.edn/read|read-string which is safer if you are dealing with input from uncertain sources

zoldar08:07:18

unless there's something that can't be expressed in edn

socksy08:07:01

I +1 zoldar’s recommendation, can’t think of any situation where you want to have arbitrary logic in an external matching specification

kongeor08:07:28

@socksy @zoldar: Thanks, my first approach was to use edn/read-string because all my input can be expressed in edn. Well, that's the simple part. Then I have to restructure the data to format it for core.match, right? That has to be done with a macro?

socksy08:07:16

but you said it’s the exactly the same as the patterns? What’s the exact format of the match? Maybe give two/three lines

zoldar08:07:07

@kongeor: yes, you will have to use macro to match the pattern with core.match, but if pattern form is close to the match body format, it shouldn't be that much of a hassle.

socksy08:07:16

hmm, it’s a little more subtle than what we’ve been saying

socksy08:07:31

but only a wee bit

socksy08:07:19

you need to have something around each match line, otherwise the edn reader will disregard the match result

kongeor08:07:20

what I actually want to do is to construct dynamically (based on a edn file) and then to pass through it a bunch of data

kongeor08:07:50

construct dynamically the matching clauses

socksy09:07:40

actually surprisingly pernickity

socksy09:07:55

user=> (def match-input (read-string "([1 2] \"geronimo\")"))
#'user/match-input
user=> (defn mymatch [[row val]] `(match [1 2] ~(identity row) ~val))
#'user/mymatch
user=> (eval (mymatch match-input))

socksy09:07:14

it’s bad

socksy09:07:47

but couldn’t work out how to define a macro, given it expects the [] form around the pattern row (that’s the left hand side of each match)

kongeor10:07:45

The problem is that when I pass the data from the edn file it fails. I guess I'm missing something about the time the macro expands the code ...

Lambda/Sierra12:07:56

@danielcompton: My understanding is that Leiningen does not read ~/.m2/settings.xml. Instead, passwords have to be placed in ~/.lein/profiles.clj

meow14:07:09

Is this a typo on clojuredocs? (clojure.core/lower-case "FOO") https://clojuredocs.org/clojure.string

meow14:07:53

@alexmiller: ok, I'll report it

r4um14:07:55

how do i make leiningen discover tools.jar (for com.sun.tools.*), currently compilation fails

Exception in thread "main" java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine, compiling:(core.clj:1:1)
works fine in repl though 😕

r4um14:07:18

I tried adding following to profiles.clj

:resource-paths [(format "file:///%s/../lib/tools.jar" (System/getProperty "java.home"))]

r4um14:07:38

but fails with

java.lang.IllegalArgumentException: No implementation of method: :as-file of protocol: #' found for class: clojure.lang.PersistentList

ordnungswidrig14:07:33

r4um: I think you need to switch to macro land to make that work in a leiningen profile

nberger14:07:32

@r4um: yes, unquote should do it, something like :resource-paths [~(format "file:///%s/../lib/tools.jar" (System/getProperty "java.home"))]

r4um15:07:50

@ordnungswidrig: @nberger: thanks! unqoute worked.

noisesmith17:07:53

michaeldrogalis: just a quick sanity check - does it make sense to have two separate projects that would share an onyx catalog via a lib that both require, and then interact via onyx? would it make more sense to send requests via eg. zookeeper?

noisesmith17:07:33

@michaeldrogalis: retagging with @ because I have no idea how this crazy slack thing works really.

voxdolo17:07:13

@noisesmith: there's a #C051WKSP3 also. Might try there.

michaeldrogalis18:07:38

Yeah, @noisesmith. Will answer in #C051WKSP3

mikecarter20:07:33

what's the best way to run a function once every minute?

Lambda/Sierra20:07:20

@mikecarter: ScheduledThreadPoolExecutor

Lambda/Sierra20:07:22

You're welcome.

denik20:07:45

does anyone know how to check whether a mvn package is installed in ~/.m2 in leiningen, else I want to run a script to install it?

bostonaholic20:07:35

@denik leiningen will check for you and will install if it doesn't exist in the local repo

denik20:07:25

@bostonaholic the problem is its not on climate (and can't be due to licensing issues) so I have to manually install it through mvn based on a local jar

denik20:07:47

Clojars not climate 😊

bostonaholic20:07:02

so we use :repositories {"local" ~(str (.toURI (java.io.File. "maven_repository")))} and have a maven_repository directory in the project for those types

bostonaholic20:07:26

so you could do ./maven_repository/com/example/project/1.0.0/project-1.0.0.jar etc.

bostonaholic21:07:04

but if you have the jar in the correct place in ~/.m2 then leiningen should be able to find it if you put it in :dependencies

bostonaholic21:07:49

we use the maven_repository trick b/c we have to check that particular jar into git

denik21:07:47

yep, @bostonaholic the idea is to build a template that install this one dep locally once

denik21:07:59

It’s a one time thing, so I will write a separate script to install it in .m2 and skip the check in lein

bostonaholic21:07:30

but for your project to use it, it will need to be in the classpath. and adding it to :dependencies in your project.clj is how'd you do that

bostonaholic21:07:49

maybe I'm not fully understanding what or why you're trying to accomplish

denik22:07:52

thanks @arohner will have a look!

joshg22:07:55

Odd that not-any? is in core but any? is not. I understand that it’s close to some (def any? (comp boolean some)), but it’s a slightly confusing inconsistency.

jwm23:07:44

there is a library for it hehe

jwm23:07:38

(def any? (comp boolean some))

aengelberg23:07:09

That wouldn't work for the evil nil case.

aengelberg23:07:23

(any? #(nil? %) [nil]) => false

aengelberg23:07:38

@jwm @joshg This would probably work:

clojure
(defn any? [f coll]
  (cond
    (empty? coll) false
    (f (first coll)) true
    :else (recur f (rest coll))))

aengelberg23:07:41

Did I just find a bug in Clojure?

aengelberg23:07:52

user=> (not-any? nil? [nil])
false

aengelberg23:07:00

Never mind, that's correct. simple_smile

aengelberg23:07:10

Sorry, I had a misunderstanding of what some returns.