Fork me on GitHub
#clojure-uk
<
2018-06-19
>
korny05:06:07

Not a huge fan - but I did watch the match, it was entertaining.

thomas07:06:26

mogge šŸ˜¼

thomas07:06:08

I had a really weird dream last night... a non-java programmer friend was somehow convinced they needed to install Kafka and run it.... and they weren't looking forward to that. And in my dream I tried to convince them to use an Isomorphic programming language. I am not even sure that actually makes any sense :thinking_face:

agile_geek07:06:25

The only surprising thing about that dream is that you managed to convince them! Iā€™ve never managed to convince anyone to use something like Clojure!

thomas07:06:23

I am not sure I managed to convince them....

sundarj07:06:21

in your dreams

šŸ˜‚ 8
thomas07:06:26

and remember... it was a dream after all šŸ˜‰

guy08:06:16

Morning!

guy08:06:56

Noob clojure question

guy08:06:11

(defn list*
  "Creates a new seq containing the items prepended to the rest, the
  last of which will be treated as a sequence."
  {:added "1.0"
   :static true}
  ([args] (seq args))
  ([a args] (cons a args))
  ([a b args] (cons a (cons b args)))
  ([a b c args] (cons a (cons b (cons c args))))
  ([a b c d & more]
     (cons a (cons b (cons c (cons d (spread more)))))))
What does :static true do?

guy08:06:23

I guess itā€™s a java interop thing?

manas_marthi08:06:31

good morning all

šŸ‘‹ 4
thomas08:06:50

I think it means that the generated Java method is a static method

guy08:06:58

Thats what i was thinking

guy08:06:01

alright cheers!

thomas08:06:27

but I am sure someone else can give you a much better explanation.

šŸ‘ 4
bronsa09:06:50

itā€™s useless

bronsa09:06:55

itā€™s a no-op since clojure 1.2

bronsa09:06:15

it used to be an experimental flag for manual direct linking

guy09:06:32

Whats direct linking?

bronsa09:06:33

clojure infers automatically now if a function can be direct linked or not

guy09:06:06

alright thanks!

thomas09:06:45

see... I was at least correct on one thing... (that someone else can give a better explanation šŸ˜‰ )

šŸ˜‚ 4
Rachel Westmacott09:06:33

knowing the limits of oneā€™s own knowledge is possibly the most important thing you can know

maleghast09:06:29

Morning All... Sorry to ask the same question again, but I could really do with finding out the answer... Does anyone remember how much Conj tickets were in 2017, Early Bird and / or Standard Price..? I am trying to firm up support for me to attend this year, now that the dates are known...

maleghast09:06:42

(I've looked on the Conj 2017 site, but no joy)

guy09:06:05

@maleghast iā€™ve done a bit of googling i cant find a price anywhere, best to alex miller i reckon

maleghast09:06:57

Thanks @guy - I Googled about a fair bit as well, I was hoping to happen on someone who remembered what they paid šŸ™‚

maleghast09:06:36

You mean Alex Miller at Cognitect?

maleghast09:06:14

Okie dokie - I will have to just @ him on Twitter or something; I don't know__ him...

guy09:06:18

nah hes in slack lol

guy09:06:34

Iā€™ve moved ur question to #clojure-conj hopefully that was what you were looking for šŸ‘€ @maleghast

maleghast09:06:58

Oh thx

šŸ‘ 4
reborg09:06:11

@maleghast 500$ for a late registration (sept for oct)

hyankov09:06:52

Morning everyone

šŸ‘‹ 8
maleghast12:06:46

@reborg - Thanks for that, very helpful šŸ™‚

šŸ‘ 4
jamescroft13:06:21

Hello šŸ‘‹ , wondering if anyone can help? I have a question about how to run a script written in clojure on my server. I have a webapp that Iā€™ve packaged into an uberjar using lein. This is deployed on my server and is happily running with java -jar xxx-standalone.jar. I have now written a script that I want to run on the server too. How would I go about getting this script included in the uberjar, and how do I run the script on the server?

flefik13:06:35

include it in the project and rebuild the uberjar?

jamescroft13:06:48

@cfeckardt yeah, sorry this is a really newbie question. I think Iā€™ve included it in the uberjar, but what java command do I run on the server to run the script. Eg. I run java -jar xxx-standalone.jar to run the webapp, what do I run to call the script that is contained within the uberjar?

Rachel Westmacott13:06:17

are you trying to start a new JVM process on your server, or do you want your currently running server to execute some code?

Rachel Westmacott13:06:49

if you want a new Java process then this might be helpful: https://clojure.org/reference/repl_and_main#_launching_a_script

Rachel Westmacott13:06:10

if you want it in the same process then you probably want to be running an HTTP server and respond to some HTTP request?

jamescroft13:06:11

I donā€™t want to run it in the same process - not trying to expose it via HTTP or anything. Itā€™s just a one off script that I want to run on the server. I took a look at this: https://clojure.org/reference/repl_and_main#_launching_a_script, but the script uses dependencies. The dependencies are all included in the uberjar (as is the script). Is there a way of calling the uberjar and telling it to run the script contained within in, eg. java -jar xxx-standalone.jar -run-this-script

jamescroft13:06:46

The link says to run the script with java -cp clojure.jar clojure.main /path/to/myscript.clj arg1 arg2 arg3 but I donā€™t have the clojure.jar on the server, or the myscript.clj. All I have is the uberjar (which should hopefully contain the myscript.clj)

thomas14:06:59

@jamescroft sounds like it would be simpler to make two different uberjars, one for the webapp and one for your script.

jamescroft14:06:25

@thomas ok thanks. Still finding my feet with this stuff. Iā€™d considered that option but it seemed like overkill and I wondered if there was a better way. Thanks

thomas14:06:09

one advantage would be that you could update either independently

sundarj14:06:39

would java -cp xxx-standalone.jar clojure.main /path/to/myscript.clj do it? i'm fuzzy on how uberjars work

flefik14:06:18

so myscript.clj is not a compiled java class file

flefik14:06:36

if you include the class inside the uberjar

flefik14:06:59

then you can invoke it using the java command

flefik14:06:55

the synopsis and description of man java explains it quite well i think

flefik14:06:03

if you are unsure if your class is inside the jarfile you can run jar -tvf jarfile

flefik14:06:05

(and if it's not in there it could be that you are missing (:gen-class) in your (ns at the top of your script

jamescroft14:06:25

ok, thanks for the pointers

flefik14:06:14

no worries

Rachel Westmacott15:06:34

I would have thought you wouldnā€™t need to compile the script to java class files if youā€™re running it via the clojure.main entry point.

flefik16:06:11

oh shoot you're right

Rachel Westmacott15:06:53

There are certainly more options in this area now due to the ā€˜tools.depsā€™ work that is ongoing.

Rachel Westmacott15:06:07

options for eg. standalone scripts with dependencies

dominicm15:06:02

If you use pack, you don't need to :gen-class for your main šŸ™‚ feature

korny18:06:16

I donā€™t know about uberjars, but I assume they are like normal jars - ā€œjava -jar foo.jarā€ loads foo into the classpath, then uses a default Main class (from distant memory) that is in the foo.jar metadata.

korny18:06:46

So you should be able to somehow specify a different entry point - youā€™d need to :gen-class to make it exposed as a class. Hmm.

korny19:06:02

if I unzip an uberjar I can see the file META-INF/MANIFEST.MF containing:

Manifest-Version: 1.0
Built-By: korny
Created-By: Leiningen 2.5.3
Build-Jdk: 1.8.0_162
Main-Class: cloc2flare.cli

korny19:06:42

and in the jar thereā€™s a cloc2flare/cli.class file.

korny19:06:07

So I strongly suspect if you make a new namespace with a :gen-class in the ns header, and a -main method, you can then run it from the uberjar just fine. Something like:

(ns mypackage.cli
  (:require
    [stuff])
  (:gen-class))
(defn -main [& args]
  (puts "Hello world!"))

korny19:06:17

then java -cp MyUberjar.jar mypackage.cli should load clojure (as itā€™s in the uberjar) and run your -main

seancorfield19:06:29

You can do it without :gen-class and AOT: run the clojure.main class and then specify the namespace whose -main you want to run: java -cp foo.jar clojure.main -m my.namespace

seancorfield19:06:54

(we actually run all our code that way and we don't AOT anything and we don't use :gen-class)

seancorfield19:06:37

We commonly have multiple namespaces containing -main functions in a single JAR.

seancorfield19:06:54

AOT and :gen-class are the slippery slope to madness šŸ™‚

šŸ‘ 8
manas_marthi21:06:06

Please tell us more about this..

seancorfield22:06:29

@U7ANZ2MTK So many problems... unfortunately, since the default Leiningen templates include AOT and :gen-class, and that's perpetuated in most of the tutorials and books, it tends to be the way most beginners get started -- and then continue with until they start tripping over problems. Stale class files, incompatible versions of a class being loaded, transitive compilation (so the whole world ends up getting compiled), weird breakages in REPL-based workflows, incompatibilities with the maven-shade-plugin, conflict between "source" and "binary" artifacts (e.g., Cursive issue 234), confusion over differences between e.g., lein run behavior and running the result of lein uberjar when not all of the fiddly bits line up, etc.

seancorfield22:06:26

AOT is sort of OK as a way to minimize start up time if you really need to do that for a complete application just at the very last step when building an uberjar for deployment.

manas_marthi22:06:40

that's really helpful

seancorfield22:06:15

:gen-class is sort of OK if you absolutely must generate a Java-compatible .class file for Java-calling-Clojure scenarios where you want the Clojure namespace to look exactly like a Java class (e.g., providing a library that can be used directly from a Java application -- and you don't want the Java code to have to use the Clojure Java API).

seancorfield22:06:25

Personally, I think the Clojure Java API is far and away the more powerful way to integrate Clojure into a Java application as it opens up the whole of Clojure, dynamically. That's how we use it at work, from our legacy apps.

seancorfield19:06:06

BTW, that also means you can start a REPL with all your code/dependencies available using an uberjar: java -cp foo.jar clojure.main -- with no -m argument will start a REPL.

korny20:06:28

Is that java -jar foo.jar or java -cp foo.jar ?

korny20:06:10

Very handy to run a REPL against an uberjar!

seancorfield21:06:32

Oh, sorry, yes, -cp.