Fork me on GitHub
#clojure-uk
<
2017-08-30
>
yogidevbear07:08:21

Morning beautiful people

jonpither08:08:12

@conan back in '14 we tried using Datomic for geosearches. Elasticsearch was a much better fit here.

jonpither08:08:07

I like Datomic too btw

thomas08:08:02

morning đŸ˜Œ moin moin

jonpither08:08:51

got to stop... procrastinating.... on talk preparation... time for coffee and dedication

yogidevbear09:08:14

Aren't you presenting this weekend? That should be enough reason to get cracking 😉

seb23108:08:48

Any recommendations on passing a Clojure cmd-line tool a string? I would expect this to work: java -jar target/uberjar/bar-0.1.0-SNAPSHOT-standalone.jar "foo", but nothing is returned?

seb23108:08:33

or actually just an argument, doesn’t need to be a string


seb23108:08:50

I’ve looked at a number of examples, but none quiet hit what I’m looking for

conan08:08:55

@jonpither yeah, datomic + elasticsearch is lovely

conan08:08:44

@seb231 that should come through as an arg to the -main function, right?

dominicm08:08:00

@seb231 how does your -main look?

seb23108:08:24

yeah @dominicm I was just thinking a better/actual example might be in order!

dominicm08:08:17

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (prn args))
/tmp/foo
❯ java -jar target/uberjar/foo-0.1.0-SNAPSHOT-standalone.jar     
nil

/tmp/foo
❯ java -jar target/uberjar/foo-0.1.0-SNAPSHOT-standalone.jar foo
("foo")

dominicm08:08:23

Based on the lein app template

conan08:08:24

clojure.tools.cli/parse-opts might give you a clue https://github.com/clojure/tools.cli

seb23108:08:23

thanks both 🙂

djtango09:08:36

can confirm tools.cli is useful

seb23109:08:28

my main:

(defn -main [database]
  (prn (query-nhm-api database "Archaeopteryx")))
database is a number of def’ed objects in the same namespace. Perhaps that is my issue?

seb23109:08:36

this works from cmd line if I hard code the entry for database, but I would like to get to a point where database and the string (“Archaeopteryx”) are both args

dominicm09:08:46

> database is a number of def’ed objects in the same namespace. Perhaps that is my issue? (edited) Clojure can handle shadowing just fine, e.g.:

(let [db 10]
  (let [db 20]
    db))
;; => 20

seb23109:08:58

but @dominicm I don’t think the cmd line knows what I mean when I give it an argument for database. For example java -jar target/uberjar/dippi-0.1.0-SNAPSHOT-standalone.jar collection-specimens collection-specimens is a def’ed object in the namespace, but why would the cmd line know what/where that is?

dominicm09:08:31

:thinking_face: What is your issue exactly?

seb23109:08:44

I think I need to actually spend some more time with clojure.tools.cli

seb23109:08:21

this: java -jar target/uberjar/dippi-0.1.0-SNAPSHOT-standalone.jar collection-specimens doesn’t return anything from cmd line, but works fine from the REPL (`(-main collection-specimens)`)

dominicm09:08:30

They're different 😉

dominicm09:08:35

Okay, I understand now

seb23109:08:44

sorry 😬

dominicm09:08:59

You want collection-specimens at the CLI to refer to dippi.core/collection-specimens ?

dominicm09:08:33

gotcha, one sec

dominicm09:08:08

(ns foo.core
  (:gen-class))

(def thing "some-value")

(defn -main
  "I don't do a whole lot ... yet."
  [lookup]
  (prn @(resolve (symbol lookup))))
/tmp/foo
❯ java -jar target/uberjar/foo-0.1.0-SNAPSHOT-standalone.jar foo.core/thing
"some-value"

dominicm09:08:53

However, don't think this is generally a good idea, recommend you do something like this:

(def dbs
  {"collect-speciments" collect-specimens})
For security reasons & such.

seb23109:09:20

@dominicm how would that then be called from the cmd line?

dominicm09:09:26

(get dbs <argument name that I forgot>)

seb23109:08:16

Thanks a lot @dominicm got it working with @(resolve (symbol lookup)) just need to make it more secure as you suggest 🙂

maleghast09:08:25

Interesting conversation

maleghast09:08:55

(the CLI args stuff, I mean)

dominicm09:08:05

woah, did not expect this. If you do (prn *ns*) inside of -main, you get clojure.core

Sam H09:08:49

yeah, it seems to be the very top level. I had an issue using *ns* for some error logging and ended up using a macro similar to the ones in clojure/tools.logging

dominicm09:08:57

I'll have to look at how they work. I'm guessing they work because they expand ns at macro time instead of at runtime.

dominicm09:08:02

If you use:

(defn -main
  "I don't do a whole lot ... yet."
  [lookup]
  (prn @(ns-resolve (find-ns 'foo.core) (symbol lookup))))
Then you can do ❯ java -jar target/uberjar/foo-0.1.0-SNAPSHOT-standalone.jar thing (without the ns)

chrjs10:08:55

Mornin’ morning

dominicm10:08:34

Question for the day, as this is bothering me right now: How do people treat their git commits? Seems to be a couple of approaches: * commits like s, stuff, implements X, does X & Y & Z * commits are "Rewrite X\n\nOld X sucked because A, B, C (See GH-10). New X uses floobits to ensure that fellanges are entirely secure at all times." I find myself doing the latter form, and avoiding the "X & Y & Z" via careful use of Magit to make it "X" "Y" "Z"

dominicm10:08:50

I'm guessing the real answer is "What will your team agree to do" 😆

sundarj10:08:34

i tend to try to follow the advice from https://chris.beams.io/posts/git-commit/

dominicm11:08:00

@sundarj skimmed that article just now, it seems to mirror what I attempt to do.

sundarj11:08:37

in a team, something like Commitizen is also a good idea

yogidevbear11:08:05

Re-posting here in case anyone knows: >Are there any online resources / books that would teach about the underlying architecture of Clojure? I'm looking for things that would help me to understand how Clojure actually works (code compilation/execution, behind the scenes processes, caveats with things like macros, etc.) as opposed to things like syntax and results of running code.

sundarj11:08:17

probably not quite what you're looking for, but Joy of Clojure is pretty in-depth

jonpither11:08:09

I would ask that Q of @reborg

jonpither11:08:20

he spends a lot of time with his head under the bonnet

reborg12:08:44

hey @yogidevbear, no resources of that kind in a single place AFAIK

reborg12:08:46

there are several talks on the topic (one is mine) about following the journey of an s-expression into the compiler down to bytecode

yogidevbear12:08:10

That sounds perfect

reborg12:08:49

would be nice to collect all the resources together

yogidevbear12:08:01

Complete agree with that sentiment

reborg12:08:27

A nice experience to try is to put a breakpoint in intellij somewhere in LispReader and fire up the repl in debug mode to follow step by step

yogidevbear12:08:48

Are there any videos/posts on that (intellij/LispReader/repl in debug mode)?

reborg12:08:27

I don't know of any but I can create one 🙂

yogidevbear12:08:19

That would be amazing!

reborg12:08:11

Ok, let me see what I can do in the following days

maleghast13:08:02

@gjnoonan - Morning 🙂 How’s it?

bronsa13:08:22

i could do a talk about how the internals of clojure work at some london meetup in the future, if there's interest

dominicm13:08:00

I'd come down to see that

reborg14:08:46

looking forward to that @bronsa