Fork me on GitHub
William Steinberg02:06:35

Am looking for a guide to help me get started with ClojureScript and rapidly be productive. Will pay for the service. Need only a couple of hours of help. Anyone interested? <mailto:[email protected]|[email protected]>

William Steinberg03:06:30

Need to see an example where JavaScript code calls a ClojureScript function, and a ClojureScript function calls a JavaScript library/file.

Manuel Ceron10:06:45

Hi everyone, I have a code style question. I want to match a text line against some regex patterns and return different functions depending on what matches. For example:

(if-let [value (re-find pattern1 line)]
  (foo value)
  (if-let [value (re-find pattern2 line)]
    (bar value)
    (if-let [value (re-find pattern3 line)]
      (baz value)
I dislike a bit the nested if-let style. So I'm wondering if there is a nice way of having the structure a bit flatter, like with cond , but in a way that allows me to capture the values.


Maybe the more straightforward way would be to move the re-find evaluations to a single let and use cond

(let [v1 (re-find pattern1 text)
      v2 (re-find pattern2 text)
      v3 (re-find pattern3 text)]
    (some? v1) (bar v1)
    (some? v2) (foo v2)
    (some? v3) (baz v3)))

Manuel Ceron14:06:33

thanks, I think I'm going to do something like this


That sounded like a nice macro writing exercise... so I wrote one 🙂


The difference to @UBSREKQ5Q's solution being that all (potentially slow/expensive) tests don't have to be performed ahead of time.


For simple regex on short inputs, that will be sufficient, though


If you want to avoid the potentially slow/expensive tests, you could do something like this:

(let [patterns [pattern1 pattern2 pattern3]
      fns [foo bar baz]]
  (loop [pattern patterns -fn fns]
    (when-not (empty? pattern)
      (if-let [value (re-find (first pattern) text)]
        ((first -fn) value)
        (recur (rest pattern) (rest -fn))))))

👍 3

Well greetings all did my first Clojure weekly study yesterday.


Did LISP ages ago at university, looking forward to doing it it's style again while learning functional programming.


Just sanity checking Ring is a good way to go to write Rest things in Clojure?


Ring is great. 😃


I like bidi better as it supports reverse routing:


I am trying to deploy a Clojure app on Ubuntu 20.04. Is openjdk-11-jre-headless enough, or I should install default-jre?


That’s fine I think; should be easy to try


it’s better to be explicit about the version of the runtime environment, so i would choose the former.


Ok thanks - my confusion stemmed from the version being labeled headless.


oh, “headless” can be interpreted as “no gui”.


so unless your clojure application has gui, headless should be good enough.

🆒 3

Giving it a go now


it’s better to be explicit about the version of the runtime environment, so i would choose the former.


If I have a list of instance methods (e.g. [length getName ...]), how do I apply them to a java object instance? This didn't work

(let [f (io/file "/bin/sh")]
  (map #(. f %) [getName length]))


without using macros:

(let [f ( "/bin/sh")]
  ((juxt #(.getName %)
         #(.length %))

👍 3

the . is a special form, so it won't work dynamically


My uberjar is working normally on my local machine (Mac):

[~] ⤑ java -jar myproj-0.1.0-SNAPSHOT-standalone.jar
2020-06-27 14:36:32.117:INFO::main: Logging initialized @1412ms to org.eclipse.jetty.util.log.StdErrLog
WARNING: seqable? already refers to: #'clojure.core/seqable? in namespace: clojure.core.incubator, being replaced by: #'clojure.core.incubator/seqable?
2020-06-27 14:36:34.878:INFO:oejs.Server:main: jetty-9.4.28.v20200408; built: 2020-04-08T17:49:39.557Z; git: ac5acd51c9ab228e9164c738d7fa1fde9e5521f8; jvm 11.0.7+8-LTS
2020-06-27 14:36:34.929:INFO:oejs.AbstractConnector:main: Started ServerConnector@1ce45e18{HTTP/1.1, (http/1.1)}{}
2020-06-27 14:36:34.930:INFO:oejs.Server:main: Started @4225ms
Started server on port 6000
And when I go to localhost:6000 the app works normally. I scp’ed the same .jar file to my Ubuntu 20.04 server and when I run it it gets stuck somewhere without any indication of what’s going on:
# sudo java -jar myproj-0.1.0-SNAPSHOT-standalone.jar
2020-06-27 18:56:48.117:INFO::main: Logging initialized @4487ms to org.eclipse.jetty.util.log.StdErrLog
WARNING: seqable? already refers to: #'clojure.core/seqable? in namespace: clojure.core.incubator, being replaced by: #'clojure.core.incubator/seqable?
How can I debug this?


if you curl localhost:6000 while ssh'ed into the ubuntu machine what do you see?


curl: (7) Failed to connect to localhost port 6000: Connection refused


what version of java is on your mac? what version is on the server?



java version "11.0.7" 2020-04-14 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.7+8-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.7+8-LTS, mixed mode)
openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode)


It’s superfluous, I am already using root


can you install clj and run a regular repl and try it there on the server?


how did you create the jar?


lein ring uberjar
:ring {:handler myproj.server/app}
  :main ^:skip-aot myproj.server
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all
                       :omit-source true
                       :env          {:cookie-secret-key "64du37483*h48b3t"} ; Must be exactly 16 characters (even in uberjar profile for the build to succeed).
                       :dependencies [[ring/ring-mock "0.4.0"]]}}) ; Build fails without ring/ring-mock for some reason!


> can you install `clj` and run a regular repl and try it there on the server? I don’t have the source code on the server but I can pull it and install the dev env if that’s the only way to find out what’s wrong


not saying its the only way to find out what's wrong. but seems like a good candidate


or if its using lein, just get the source and use lein ring server and see what happens


Got it, will try that and report back. Thanks.


Same problem. Even tried Oracle Java. I guess I’ll need to reconstruct the app little by little 😞


The problem is in my setup though. lein new compojure hello-worldlein ring server-headless works


Oooh, I was omitting -headless from my setup. The server is a mess now. Will have to start over 😄


My uberjar was taking forever to launch because it couldn’t connect to Postgres :man-facepalming:


I'm having a problem trying to use a Java dependency in Clojure. I have been playing with Lanterna. There's a bug I wanted to help with that requires me to install the git master version. I used lein-git-down to get it and install the master from github. But, I can't get it to import the library in the REPL, it keeps saying java.lang.ClassNotFoundException com.googlecode.lanterna.terminal.TerminalFactory. I've checked that lein-git-down compiled the lanterna-master.jar file correctly using jar -tvf, and it's showing a MANIFEST and classes etc. I've checked the classpath in the REPL and it can see the lanterna-master.jar file is there. Can anyone suggest any steps I could try?


what does lein classpath show?


what does your dependencies list look like?


lein classpath shows it (there's a lot of output), but it does have: /home/steve/.m2/repository/lanterna/lanterna/master/lanterna-master.jar


Dependencies is:

:dependencies [ [lanterna "master"] ]
:repositories [; specifically used by lein-git-down to enable github
                 ["public-github" {:url ""}]
                 ["private-github" {:url "" :protocol :ssh}]
:git-down {
            lanterna {:coordinates mabe02/lanterna}


Normally when I use it the dependency line is

;[com.googlecode.lanterna/lanterna "3.0.3"]
When I put that it, it grabs it from maven central and installs/works fine: I double checked it earlier in case I'd messed something else up. It's something I'm doing wrong in trying to use it from a git repo


com.googlecode.lanterna.terminal.TerminalFactory is an interface, not a class


can you import com.googlecode.lanterna.terminal.DefaultTerminalFactory


Same error:

(import com.googlecode.lanterna.terminal.DefaultTerminalFactory)
java.lang.ClassNotFoundException: com.googlecode.lanterna.terminal.DefaultTerminalFactory


what if you do: (import 'com.googlecode.lanterna.terminal.DefaultTerminalFactory)


the import statement requires a quote before the class name


I get:

(import 'com.googlecode.lanterna.terminal.DefaultTerminalFactory)
java.lang.ClassNotFoundException: com.googlecode.lanterna.terminal.DefaultTerminalFactory


I think there's some part of the chain I don't understand. I don't really know Java. I thought I understood how it went together but I must be missing a step.


looks like you've done everything correct to me


how are you running the code?


is it even having issues when run from lein repl?


I'm in the REP, (I use Rebel Readline). That's how I've been testing it up to this point - play in the REPL and then create my source and use lein run . This set-up works fine with the Maven released version 3.0.3. The minute I changed over to trying to use it from GitHub it won't work. I guess I will ask the lein-git-down maintainer - though I'm sure it's something I'm doing wrong that I don't understand.


Thanks for confirming I haven't gone totally mad 🙂


well, I would try importing under lein repl just to see if maybe it's something not getting picked up by REP


otherwise, I'm pretty stumped ¯\(ツ)


one other thing to note is that it seems like lein-git-down is for targeting clojure libraries. it may be that it doesn't work with java libraries