Fork me on GitHub
#clojure
<
2015-10-30
>
danielcompton00:10:36

@bradford: If the keys weren’t nested then you’d use select-keys. I’ve run into this from time to time, https://groups.google.com/forum/#!topic/clojure/gGigc9BWzNw and https://gist.github.com/cgrand/2823916 are on the right track. Thinking about it now, I wonder if Spectre could help, I haven’t looked into it much

bradford00:10:09

@danielcompton: Thanks! I’ve looked at most of those and they’re on the right path (the iroh.common code doesn’t seem to …work), but nothing’s really hitting me yet. Will keep kicking it.

danielcompton00:10:47

Why do you need to filter the map keys in the first place?

danielcompton00:10:49

I mean, what’s the use case for needing to pick some of them out? Can they get filtered elsewhere?

danielcompton00:10:41

the other option would be to do select-keys on all of the level one keys, then a get + select-keys on all of the two level keys, e.t.c.

bradford00:10:22

They’re in a JSON blob read from a S3 file, and then I’m transforming that map to write to BigQuery (a database)

bradford00:10:57

So… no logic, really. Just need to filter out the KVs in S3 that aren’t columns in BigQuery. A pretty common use case in my day-to-day.

isaac04:10:02

What do you think?

mishok1307:10:35

@isaac: current behavior is suprising to say the least

isaac08:10:21

I know, you mean, I can use (assoc m …) directly.

isaac08:10:42

Sometimes, you want the the update-in keys is configurable .

mishok1309:10:15

this might explain a bug I had a few years back

tjg10:10:43

With SQL selects, I want rows in vectors, not maps. How to do this? (FWIW I'm using yesql.)

tjg10:10:28

Ah, clojure.java.jdbc has :as-arrays?... let's see if I can get yesql to expose it...

wei10:10:28

you could transform the query result yourself

wei10:10:24

sounds like something nathanmarz/specter could handle. I haven’t used it before but I’ve been trying to find a good excuse to simple_smile

tjg10:10:16

Yeah, I was hoping to just be lazy. Unfortunately, yesql removed support for :as-arrays? at some point... https://github.com/krisajenkins/yesql/pull/116/files

tjg10:10:39

Sucks, because that's information loss.

tjg10:10:49

Maybe I'll ask about it... perhaps resubmit PR.

Pablo Fernandez14:10:25

Is there a way to test if a value is a thing I can map over, as in, vector, list, set, etc?

Pablo Fernandez14:10:15

dot_treo: seq? is false for vectors.

Alex Miller (Clojure team)14:10:47

you really want seqable? (although that doesn't actually exist in core)

Alex Miller (Clojure team)14:10:02

there is a version in core.incubator

Pablo Fernandez14:10:27

alexmiller: thanks.

Pablo Fernandez14:10:08

I have this pattern of a function that I want to take one value or a sequence of values and do an operation to each of them. Is this anti-idiomatic?

thosmos14:10:36

@bradford: you wrote: https://clojurians.slack.com/archives/clojure/p1446158343003081 You might try https://github.com/nathanmarz/specter ? it's amazing for transforming nested data structures

roberto14:10:59

Is there an “official” JavaFX wrapper for clojure?

ghadi14:10:22

roberto: no, but there are a few interesting things. Fn-fx https://github.com/halgari/fn-fx

roberto14:10:14

interesting

tim.linquist15:10:32

Ok Clojurians. Lets talk vars.

tim.linquist15:10:34

(def revenue.system {})
=> #'revenue.main/revenue.system
(def test-conn
  (get-in var-get(#'revenue.system) [:datomic :conn]))
CompilerException clojure.lang.ArityException: Wrong number of args (0) passed to: PersistentArrayMap, compiling:(form-init3451962995536705092.clj:2:18) 
(var-get #'revenue.system)
=> {}
(get-in (var-get #'revenue.system) [:datomic])
=> nil

tim.linquist15:10:58

Using var-get within the def I get an error every time. Same call outside the def magic. What gives?

tim.linquist15:10:15

ghadi: !! My brotha!

ghadi15:10:37

the second form is erroring because of (#'revenue.system)

ghadi15:10:19

it's taking the value inside (a map) and trying to call it

tim.linquist15:10:32

Wow I'm a dink

tim.linquist15:10:40

I just realized what I did there. Ha.

ghadi15:10:42

if you're trying to remember a part of a map, make a handle for it in a var, and keep it updated you can't - soorrry

tim.linquist15:10:23

I'm only using a var in this case because I'm doing setup/teardown in a fixture so I was unable to get a handle on the map (value of this var) in the tests. Hopefully nobody will change this under my feet

tim.linquist15:10:51

(defn fresh-db-seeded [f]
  (let [sys (start-system! #'revenue.system test-system)]
    (fixtures/transact-all (test-conn) (fixtures/resource "fixtures.edn"))
    (f)
    (d/delete-database (memdb sys))
    (stop-system! #'revenue.system)))

tim.linquist15:10:11

Ideally we could pass the system to (f) which in this case ends up being a test

tim.linquist15:10:24

(use-fixtures :each fresh-db-seeded)

ghadi15:10:18

I see. That will break if anyone is referring to the system directly

ghadi15:10:05

through a normal var access. they'll potentially see an old value

tim.linquist15:10:13

Because of the def? I'm working on removing it from the def now

ghadi15:10:29

which def?

tim.linquist15:10:58

(def test-conn
  (get-in (var-get #'revenue.system) [:datomic :conn]))

ghadi15:10:42

1) this def for test-conn is evaluated immediately - var-get or not. it's going to be a value (the datomic connection)

ghadi15:10:10

it's the exact same as (get-in revenue.system ...)

ghadi15:10:25

Sorry g2g!

tim.linquist15:10:12

Cool cool I see that playing around in the REPL. I didn't realize the var would be eval'd passing to get-in etc

richiardiandrea16:10:33

My two cents, you can wrap it in a delay that you can then deeref at the initialization phase

ghadi17:10:41

tim.linquist: if the compiler sees a symbol it will try to resolve to a let binding, var, or java Class

gtrak18:10:36

Why is the tools.reader maven artifact jar using AOT?

gtrak18:10:52

this has had me pulling my hair out for a few hours

Alex Miller (Clojure team)18:10:44

the main one should not be

Alex Miller (Clojure team)18:10:56

there is a classifier version that does

gtrak18:10:15

core.match is pulling it in for me via tools.analyzer.jvm

gtrak18:10:54

getting an error trace like this intermittently:

Caused by: java.lang.RuntimeException: Unable to resolve symbol: init in this context, compiling:(clojure/tools/reader/impl/ExceptionInfo.clj:1:1)
	at clojure.lang.Compiler.analyze(Compiler.java:6543)
	at clojure.lang.Compiler.analyze(Compiler.java:6485)
	at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3791)
	at clojure.lang.Compiler.analyzeSeq(Compiler.java:6725)
	at clojure.lang.Compiler.analyze(Compiler.java:6524)
	at clojure.lang.Compiler.analyze(Compiler.java:6485)
	at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5861)
	at clojure.lang.Compiler$TryExpr$Parser.parse(Compiler.java:2261)
	at clojure.lang.Compiler.analyzeSeq(Compiler.java:6723)
	at clojure.lang.Compiler.analyze(Compiler.java:6524)
	at clojure.lang.Compiler.analyze(Compiler.java:6485)
	at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5861)

gtrak18:10:12

on other people's boxes

gtrak18:10:31

which is a gen-class

Al Baker18:10:35

gtrak: hey Gary, fancy seeing you in here 😄

Alex Miller (Clojure team)18:10:01

I don't see anything like that in either the main tools.reader jar or the aot-ed classifier variant

Alex Miller (Clojure team)18:10:20

I know that there is some weird stuff going on in there to support older clj versions though

Alex Miller (Clojure team)18:10:38

can you do a lein deps :tree ?

gtrak18:10:39

simple_smile this whole thing reminds me of revelytix days

gtrak18:10:35

@alexmiller: this is a maven project, I'll paste the dependencies

gtrak18:10:23

[INFO] +- org.clojure:clojure:jar:1.7.0:compile
[INFO] +- prismatic:schema:jar:0.4.3:compile
[INFO] +- org.clojure:tools.nrepl:jar:0.2.6:compile
[INFO] +- clj-time:clj-time:jar:0.9.0:compile
[INFO] |  \- joda-time:joda-time:jar:2.9:compile
[INFO] +- org.clojure:java.jdbc:jar:0.3.7:compile
[INFO] +- cheshire:cheshire:jar:5.2.0:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-core:jar:2.2.1:compile
[INFO] |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-smile:jar:2.2.1:compile
[INFO] |  \- tigris:tigris:jar:0.1.1:compile
[INFO] +- clojurewerkz:elastisch:jar:2.2.0-beta4:compile
[INFO] |  +- clojurewerkz:support:jar:1.1.0:compile
[INFO] |  \- org.elasticsearch:elasticsearch:jar:1.7.2:compile
[INFO] |     +- org.apache.lucene:lucene-core:jar:4.10.4:compile
[INFO] |     +- org.apache.lucene:lucene-analyzers-common:jar:4.10.4:compile
[INFO] |     +- org.apache.lucene:lucene-queries:jar:4.10.4:compile
[INFO] |     +- org.apache.lucene:lucene-memory:jar:4.10.4:compile
[INFO] |     +- org.apache.lucene:lucene-highlighter:jar:4.10.4:compile
[INFO] |     +- org.apache.lucene:lucene-queryparser:jar:4.10.4:compile
[INFO] |     +- org.apache.lucene:lucene-sandbox:jar:4.10.4:compile
[INFO] |     +- org.apache.lucene:lucene-suggest:jar:4.10.4:compile
[INFO] |     +- org.apache.lucene:lucene-misc:jar:4.10.4:compile
[INFO] |     +- org.apache.lucene:lucene-join:jar:4.10.4:compile
[INFO] |     +- org.apache.lucene:lucene-grouping:jar:4.10.4:compile
[INFO] |     +- org.apache.lucene:lucene-spatial:jar:4.10.4:compile
[INFO] |     |  \- com.spatial4j:spatial4j:jar:0.4.1:compile
[INFO] |     \- org.yaml:snakeyaml:jar:1.12:compile
[INFO] +- com.stuartsierra:dependency:jar:0.1.1:compile
[INFO] +- org.clojure:tools.logging:jar:0.3.1:compile
[INFO] +- clj-antlr:clj-antlr:jar:0.2.2:compile
[INFO] |  +- org.antlr:antlr4-runtime:jar:4.2.2:compile
[INFO] |  |  +- org.abego.treelayout:org.abego.treelayout.core:jar:1.0.1:compile
[INFO] |  |  \- org.antlr:antlr4-annotations:jar:4.2.2:compile
[INFO] |  \- org.antlr:antlr4:jar:4.2.2:compile
[INFO] |     +- org.antlr:antlr-runtime:jar:3.5.2:compile
[INFO] |     \- org.antlr:ST4:jar:4.0.8:compile
[INFO] +- fast-zip:fast-zip:jar:0.7.0:compile
[INFO] +- fast-zip-visit:fast-zip-visit:jar:1.0.2:compile
[INFO] +- org.clojure:core.match:jar:0.3.0-alpha4:compile
[INFO] |  \- org.clojure:tools.analyzer.jvm:jar:0.6.5:compile
[INFO] |     +- org.clojure:tools.analyzer:jar:0.6.4:compile
[INFO] |     +- org.ow2.asm:asm-all:jar:4.2:compile
[INFO] |     \- org.clojure:tools.reader:jar:0.8.12:compile
[INFO] \- org.clojure:core.memoize:jar:0.5.6:compile
[INFO]    \- org.clojure:core.cache:jar:0.6.3:compile
[INFO]       \- org.clojure:data.priority-map:jar:0.0.2:compile

gtrak18:10:28

I think the older versions of tools.reader don't exclude class-files: https://github.com/clojure/tools.reader/blob/tools.reader-0.8.12/pom.xml#L29

gtrak18:10:36

so bumping up the version might help

Alex Miller (Clojure team)18:10:47

yeah, that looks like a pretty old version

gtrak18:10:06

0.8.16's pom seems a bit better

gtrak18:10:03

still includes the genclass, though

gtrak18:10:21

<include>clojure/tools/reader/impl/ExceptionInfo*.class</include>

Alex Miller (Clojure team)18:10:12

might ask @bronsa about that stuff, I don't know the history of the tools reader version of ExceptionInfo

gtrak18:10:56

it was 1.3 compatibility, removed in 0.10.0, my fear is breaking core.match or tools.analyzer.jvm, but I haven't tried yet, just tried to understand what could be breaking things.

Alex Miller (Clojure team)18:10:41

I suspect you're prob fine with tools.analyzer.jvm and core.match

Alex Miller (Clojure team)18:10:18

the next version of tajvm will bump up the reader dep

Alex Miller (Clojure team)18:10:35

it may be worth releasing a new version of core.match that merely bumped those older deps, not sure

gtrak18:10:09

I think that would be helpful, I'm using the latest, which is an alpha anyway, relying on these old deps.

bronsa19:10:12

@gtrak: yeah you shud be fine bumping tools.reader with both t.a.jvm and core.match

gtrak19:10:08

seems to have worked simple_smile

gtrak19:10:15

thx for the help

jsa-aerial20:10:49

Is the 'right' (only?) way to get a compojure/ring web server (running from an uberjar) to serve static files from the local file system, to use routes/files explicitly instead of routes/resources? There's wrap-files as well, but not sure how that composes with route/* stuff. This scenario needs to change a couple things in a js file from the 'defaults' in the version in the jar. So, it creates an 'installation' in a local directory and extracts the resources from the jar into that local directory, then makes the tweak change to the js file. Currently it uses route/resources to set root for this, but that always uses the version in the jar - even if I use -cp ... when running it. Thanks in advance for any info!

staypufd20:10:12

Given enums like so:

staypufd20:10:13

[:db/add #db/id[:db.part/user] :db/ident :state/AL] [:db/add #db/id[:db.part/user] :db/ident :state/AK] [:db/add #db/id[:db.part/user] :db/ident :state/AZ] [:db/add #db/id[:db.part/user] :db/ident :state/AR]

staypufd20:10:35

I’m trying to figure out how to query all the state enums

staypufd20:10:46

I’ve done something like so

staypufd20:10:47

(datomic.api/q '[:find [?name-str ...] :where [?e :db/ident ?ident] [?ident :db/ident ?name-keyword] [(name ?name) ?name-str] [ (count ?name-str) ?len] [(= 2 ?len)] ] (bonfire.api.data.core/db))

staypufd20:10:56

but it includes anything of length 2

staypufd20:10:16

so other keywords that are length of 2 come thur

staypufd20:10:21

thru as well

Joe R. Smith20:10:36

You could look for idents that start with :state (e.g. using Java String’s startsWith method)

staypufd20:10:48

I found this way too

staypufd20:10:49

(datomic.api/q '[:find [?name-str ...] :where [?e :db/ident ?ident] [?ident :db/ident ?name-keyword] [(name ?name-keyword) ?name-str] [(namespace ?name-keyword) ?ns] [(= "state" ?ns)] ] (bonfire.api.data.core/db))

devn20:10:41

Sorry if this is borderline spammy, but I wanted to drop a note in here for anyone interested that I created a #C08TC9JCS channel. For folks who don't know what Clara is: https://github.com/rbrush/clara-rules

phil21:10:06

Given (def hello 'some.namespace/blah), how do I call the value of hello as a function.

phil21:10:11

(assume it exists)

phil21:10:13

The value is a symbol.

phil21:10:25

At that point.

phil21:10:00

I know about resolve-ns, but there's a namespace in that symbol name.

xpe22:10:07

@phil (def x 'clojure.core/map) (x inc [1 2 3]) ; => [1 2 3]!

phil22:10:33

Yea, thanks. I'd misspelled the ns. :-/

xpe23:10:56

@phil here is the working example, in case you haven't seen this way of doing it ((find-var x) inc [1 2 3]) gives (2 3 4)

xpe23:10:03

My 6:19 pm example was the result of this behavior: symbols, like keywords, are also functions that look themselves up in a map. So ('x {'x 1}) => 1 and ('x {'y 1} :not-found) => :not-found

xpe23:10:30

hence ('clojure.core/map inc [1 2 3]) -> [1 2 3]. still, I wouldn't have expected inc to pass muster as a map