Fork me on GitHub
#clojure
<
2018-08-30
>
hackeryarn00:08:41

What is the best way to deal with updating a deeply nested parsed XML structure? More specifically I need to find specific elements and attributes through a few nested layers.

flowthing09:08:11

XPath for finding specific elements from an XML document, XSLT for transforming one. If you're willing to venture outside Clojure, that is. 🙂

hackeryarn00:08:08

I tried using zippers, but it feels really clunky to run the checks at every level. Is there a better way?

hackeryarn00:08:04

A thank you, does it support updating a deeply nested elements as well as querying?

Chris O’Donnell00:08:08

Yes, it supports updating with transform

hackeryarn00:08:11

Ah thank you so much. It seems much easier than the zipper madness I was dealing with.

Chris O’Donnell00:08:36

Sure thing. There's also a #specter channel here on slack.

hackeryarn00:08:00

I'll definitely check it out. I'm enjoying playing with it so far ::grin:

👍 4
seancorfield04:08:33

Anyone else seeing Travis CI builds failing for Clojure projects at the moment?

Could not transfer artifact org.clojure:data.json:jar:0.2.6 from/to central (): Access denied to:  , ReasonPhrase:Forbidden.
Nothing will transfer from Maven (but Clojars is fine). Leiningen 2.8.1 (the default choice right now it seems).

seancorfield14:08:43

Thank-you! Yes, jobs seem to be running properly now. Interesting.

Bobbi Towers04:08:01

Not sure if it's related, but my Gitlab CI build also failed about 20 minutes ago with undefined method 'force_encoding' for nil:NilClass, but I retried and seems fine now

restenb06:08:08

anybody got a way of doing something like map-indexed on multiple lists?

schmee07:08:54

can you give an example of the input and output you would like?

restenb07:08:23

basically something like (map-indexed (fn [idx a b c] ...) coll-a coll-b coll-c) would be the use

restenb07:08:46

working exactly as map-indexed just with multiple list inputs

schmee07:08:24

user=> (map vector (range) [:a :b] [:a :b])
([0 :a :a] [1 :b :b])

👍 4
schmee07:08:57

i.e pass (range) as coll-a

restenb07:08:30

hm thats pretty neat.

sneakypeet10:08:52

Hi all, Is there a channel where clojure blog posts and articles get shared?

schmee10:08:27

@sneakypeet yes, #news-and-articles, don’t know how active it is though

Marc O'Morain11:08:42

Does this docstring have a typo in it? https://clojure.github.io/clojure/clojure.test-api.html#clojure.test/test-vars > test-vars > function > Usage: (test-vars vars) > Groups vars by their namespace and runs test-vars on them with appropriate fixtures applied. It references itself (`test-vars`). I assume it should read "and runs test-var on them".

Andreas Liljeqvist13:08:01

I got a problem with tools.namespace.reload/refresh trying to load a namespace that isn't referenced in my source anymore

Andreas Liljeqvist13:08:52

The namespace has been removed. Anyone know how to debug it?

manutter5114:08:57

Some kind of caching? If you’re using lein, you could try lein clean; if you’re using IntelliJ/Cursive, you could try File -> Invalidate Caches / Restart.

Andreas Liljeqvist14:08:35

using clj from commandline

Andreas Liljeqvist14:08:56

There it is - A cljc namespace was left in my target folder

Ramzi16:08:09

Anyone have experience connecting to postgres through JDBC and clojure?

ghadi16:08:48

there's a lot of documentation for that on the clojure.java.jdbc docs

Ramzi16:08:08

I've tried following a few. They all result in errors for me.

Ramzi16:08:43

Can you link one, and I'll try following it and tell you what errors I get?

dpsutton16:08:45

go to #beginners and ask for some help

annarcana16:08:01

Clojurice starter app uses JDBC with Postgres. You may find the code instructive: https://github.com/jarcane/clojurice

Ramzi17:08:23

I get BatchUpdateException while trying to follow that Heroku guide.

dadair17:08:34

Hard to help without more information into the error

Ramzi17:08:56

java.sql.BatchUpdateException: Batch entry 0 CREATE TABLE users (data text) was aborted. Call getNextException to see the cause., compiling:(my_app/handler.clj:53:1) clojure.lang.Compiler$CompilerException: java.sql.BatchUpdateException: Batch entry 0 CREATE TABLE users (data text) was aborted. Call getNextException to see the cause., compiling:(my_app/handler.clj:53:1)

Ramzi17:08:53

This is line 53: (j/db-do-commands "<postgresql://user:pass@localhost:5432/dbname>" (j/create-table-ddl :users [[:data :text]]))

Ramzi17:08:12

j is sql, from a different tutorial

dadair17:08:37

surround that with a try ..catch and see if the next exception (as the error indicates you to use) provides more information:

(try
  <your code here>
  (catch Exception e (.getNextException e)))

Ramzi17:08:36

now the page loads

Ramzi17:08:41

but i dont see the exception

Ramzi17:08:47

Yes!!! It worked!!! I made a table!!

Ramzi17:08:53

Thanks so much for the help!

Ramzi17:08:33

My insert isn't working though. 😞

dadair17:08:02

Again, will need more information to help.

Ramzi18:08:19

Here is my code: (try (j/db-do-commands "<postgresql://user:pass@localhost:5444/dbname>" (j/create-table-ddl :asdf [[:data :text]])) (j/insert! "<postgresql://user:pass@localhost:5444/dbname>" :asdf {:data "Hello World"}) (catch Exception e (.getNextException e)))

Ramzi18:08:37

The page loads. I see no exception. The table asdf is made, but it has no Hello World row.

Ramzi18:08:54

oh, i guess the first line is throwing the exception

Ramzi18:08:58

so the second line isnt being run

dadair18:08:34

And what is the exception?

Ramzi18:08:55

Sweet! I got the Hello World to write by separating the second statement and surrounding it with its own try catch

dadair18:08:57

My guess to what is wrong is that you keep re-running the application, which will re-run the create-table-ddl command, which will throw an exception since the table already exists. (if you aren’t clearing the SQL database between restarts)

dadair18:08:40

Surrounding things with try .. catch doesn’t magically make these things work, it’s just allowing you to get around the issue that you are trying to create a table that already exists. Surrounding the insert with its own try .. catch probably does nothing, since I’m assuming the data column has no constraints that could cause an exception to be thrown.

Ramzi18:08:43

I am making an ajax call and successfully getting {:data "Hello World"}{:data "Hello World"}{:data "Hello World"}{:data "Hello World"}{:data "Hello World"}{:data "Hello World"} back from the database. Problem is I can only see it in my network tab. I can't seem to alert it or write it to a div.

Ramzi18:08:00

Here's my attempt: (defn ajax-input [id] [:input {:id id :on-change #(js/alert (.-value (.send goog.net.XhrIo "/database"))) } ] ) It gives undefined.

dadair18:08:34

Can’t help you there, not my area of expertise.

Bravi18:08:20

hi everyone. this is not a clojure question but I don’t really know where else to ask 😕 I’m trying to use mysql database that lives in docker, with my application

Bravi18:08:34

and I’m unable to even ping the docker container

Bravi18:08:47

perhaps someone here knows how to ..

the2bears19:08:20

Maybe #docker might help.

neural19:08:30

greetings for all!!!

neural19:08:53

anyone knows how to make a jar file from clj cli?? need deps?

seancorfield19:08:18

@neural.works.com There are a couple of tools listed on the wiki for the tools.deps repo...

neural19:08:57

will look at that... tks!

gfredericks19:08:31

is there a good tool for having the repl show stack traces in reverse order? with the message at the bottom too?

gfredericks19:08:26

nine years scrolling up to see the top of the stack trace was fine, but sometime soon I'll have been doing it for ten years, and that's too many

4
andy.fingerhut19:08:40

I don't know of one, but it sounds like a perfect feature creep for your seventy-one project

gfredericks19:08:25

only works on stack traces with seventy-one elements

benzap19:08:06

@gfredericks are you using emacs with cider? I thought it broke up the exceptions in a way that made it a bit more sane

gfredericks19:08:53

it might actually -- I just realized it's the clojure.test output I'm dealing with, so I probably need something that customizes that

andy.fingerhut19:08:15

Maybe aviso does what you want? Search for word "reverse" on this page: https://ioavisopretty.readthedocs.io/en/latest/exceptions.html

gfredericks19:08:18

yeah that looks good; thanks

hiredman20:08:07

the stractrace.raw readme conveniently links to other projects that manipulate stacktraces

hiredman20:08:21

it is also very useful to know that stracktrace.raw exists sometimes

hiredman20:08:11

we use some timbre logging and boot at work, both of which do some stracktrace munging, I think maybe using aviso, so stracetrace.raw has been very helpful to me

gfredericks20:08:46

it doesn't seem like the problems he lists aren't solvable

gfredericks20:08:05

I mean I guess if you don't control the library and can't change it quickly then you practically can't solve it

hiredman20:08:06

maybe, I dunno, I just have yet to see a library that doesn't at least sometimes get in the way

hiredman20:08:21

it has been a bit, but I think with aviso it is usually a problem with eliding the frame I am interested in

gfredericks20:08:31

(try (fancy-thing e) (catch Throwable _ (do-what-stu's-thing-does e)))

gfredericks20:08:53

yeah I don't want any frames elided

aarkerio20:08:29

Hi! newbie quick question: if a function returns "clojure.lang.LazySeq@3c72489" and I know it's a hash map, how can I "extract" the content?

hiredman20:08:45

it isn't a hash map

hiredman20:08:56

it is a clojure.lang.LazySeq

hiredman20:08:51

that is the kind of not super useful thing you get back from the .toString method on a lazy seq

hiredman20:08:06

you may want to try using pr, prn, or pr-str

aarkerio20:08:09

I see, thanks a lot.

aarkerio20:08:18

hmmmm, but I don't want a string, I want my precious map

hiredman20:08:55

I am suggesting those as ways to inspect the data to see what you actually have, because you don't know what you have

andy.fingerhut20:08:09

Maybe your precious map is an element of the lazy sequence?

andy.fingerhut20:08:34

Unless the double quotes you show mean the function returns a string, in which case you have a string, not a LazySeq or a map

hiredman20:08:03

you think you got a map, you actually got a lazy seq, so you may need to do some debugging of your function, and it might be useful to look at the contents of the lazy seq that is returned when doing that

aarkerio20:08:05

hmmm, I'm using: (db/create-question! question) if I run it in the repl I got {:id 67}

aarkerio20:08:18

the last id in the table

andy.fingerhut20:08:19

Maybe that function is executing a Clojure sequence-returning function like map on your map, and returning a lazy sequence?

andy.fingerhut20:08:48

e.g. (map identity {:a 1 :b 2}) => ([:a 1] [:b 2]) (type (map identity {:a 1 :b 2})) => clojure.lang.LazySeq

aarkerio20:08:28

but If I run it inside a (doseq [question questions] , (db/create-question!) returns a lazyseq

hiredman20:08:40

no it doesn't

hiredman20:08:49

you are doing something else

hiredman20:08:54

doseq always returns nil

andy.fingerhut20:08:23

When you run (db/create-question! question) in the REPL, do you know whether it is returning a map, or printing a map? If code prints something to the out stream, it can be a little confusing to distinguish the stuff being printed from the return value.

hiredman20:08:42

so you don't mean you are calling something that contains the doseq and it is returning a lazy-seq, you mean you are getting a lazy-seq when you call create-question! in the doseq?

aarkerio20:08:38

no, I just followed Andy's advice and he es right:

aarkerio20:08:55

is a lazySeq also in the repl

andy.fingerhut20:08:59

I don't know what (db/create-question! question) does internally, but perhaps depending upon its argument, or some state in the database/etc., it returns different types?

hiredman20:08:13

but that isn't from the code you pasted

hiredman20:08:45

the code you pasted will only ever evaluate to nil, because doseq by definition evaluates to nil

aarkerio20:08:23

sorry my mistake, the function that I'm interested is (db/create-question! question)

andy.fingerhut20:08:25

I think he means that the (log/info ... (pr-str last-id)) call is showing LazySeq... as the return value from pr-str ?

aarkerio20:08:24

yes, I thought than I was getting a map in the repl, but I'm not

aarkerio20:08:34

thanks a lot for your time!

roklenarcic20:08:07

I have the dumbest problem, and I'm probably overlooking something, but when using clj-http it doesn't encode spaces in query params correctly

roklenarcic20:08:43

If I specify a query-param of A B it encodes it as A+B instead of A%20B

roklenarcic20:08:00

has anyone else had this problem?

hiredman21:08:39

that is the correct way to encode spaces in query parameters

manutter5121:08:25

I was getting ready to type that but I couldn’t find a good reference to back it up with.

urbanslug21:08:37

Hey, I'm using gitlab CI with clojure and trying to cache my .m2 like so https://gitlab.com/gitlab-org/gitlab-ci-yml/blob/master/Maven.gitlab-ci.yml#L30

urbanslug21:08:08

however every time the pipeline doesn't seem to find .m2/repository

urbanslug21:08:30

is it that the flag -Dmaven.repo.local=.m2/repository doesn't work for clj?

urbanslug21:08:51

Anyone using gitlab CI and caching their m2?

noisesmith21:08:18

are you sure you want .m2/repository instead of ~/.m2/repository ?

urbanslug21:08:50

I'm just following their doc tbh

urbanslug21:08:19

@noisesmith I'll use whatever works. It's just for CI anyway

urbanslug21:08:43

at end I keep getting WARNING: .m2/repository: no matching files

urbanslug21:08:01

Let me try ~/.m2/repository

urbanslug21:08:21

but I am setting

variables:
  MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"

urbanslug21:08:26

so I don't get it

noisesmith21:08:38

but you likely aren't using maven

noisesmith21:08:59

you need to make sure your build tool is told where the maven cache is

noisesmith21:08:21

eg. CI might only provide MAVEN_OPTS to maven, so nothing happens if you don't invoke maven(?)

urbanslug21:08:39

or that's what I assume it's pulling from

noisesmith21:08:55

I'm talking about the program that is being invoked (eg. lein or boot)

urbanslug21:08:09

I'm using clojure with deps.edn

noisesmith21:08:22

does CI hand your MAVEN_OPTS to your build tool? if not, you probably need to adjust that

noisesmith21:08:32

clojure with deps.edn doesn't call mvn (the maven command), but it does use the same cache and some of the same java libraries

urbanslug21:08:00

I'm skimming through https://clojure.org/reference/deps_and_cli and can't really find anything

noisesmith21:08:45

the key thing is that the config that tells the maven libs where to put the cache needs to be supplied to the tool actually fetching the deps

urbanslug21:08:15

can't find anything explicit there

noisesmith21:08:31

my hunch is use -J to pass the same -D that would be passed to mvn

-Jopt           Pass opt through in java_opts, ex: -J-Xmx512m

noisesmith21:08:57

so it would be -J$MAVEN_OPTS in the invocation

noisesmith21:08:13

or you could define a CLJ_JVM_OPTS that works similarly but includes the -J before each one

noisesmith21:08:26

and use it the same way the example does on mvn calls

Alex Miller (Clojure team)21:08:01

you can set the location of the Maven repository in your deps.edn

Alex Miller (Clojure team)21:08:41

like {:deps ..., :mvn/local-repo "/home/.m2/repository"}

urbanslug21:08:32

but only for CI

urbanslug21:08:39

so this would be in an alias

Alex Miller (Clojure team)21:08:49

won’t work in an alias

Alex Miller (Clojure team)21:08:21

you could pass it on command line with -Sdeps '{:mvn/local-repo "/home/.m2/repository"}'

Alex Miller (Clojure team)21:08:02

$HOME/.m2/repository is the default local repo though so not sure whether you’re helping

urbanslug21:08:14

would be best if it were just .m2 for the current dir

urbanslug21:08:22

not in any $HOME

urbanslug21:08:54

trying to think about how to pass that arg to clojure via shadow-cljs

Alex Miller (Clojure team)21:08:35

relative dirs should work too, assuming you can control current directory

johnj22:08:22

does 1.9 starts slower than 1.8 because of the specs deps?