This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-27
Channels
- # announcements (1)
- # babashka (2)
- # beginners (64)
- # cider (1)
- # cljs-dev (49)
- # cljsrn (2)
- # clojure (49)
- # clojure-europe (3)
- # clojure-norway (1)
- # clojure-spec (7)
- # clojurescript (116)
- # conjure (3)
- # cursive (4)
- # datomic (1)
- # emacs (2)
- # fulcro (15)
- # graalvm (10)
- # kaocha (1)
- # leiningen (4)
- # meander (1)
- # music (1)
- # off-topic (7)
- # re-frame (37)
- # reagent (3)
- # releases (1)
- # rewrite-clj (6)
- # sci (4)
- # shadow-cljs (16)
- # sql (8)
- # tools-deps (16)
- # xtdb (5)
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]>
Need to see an example where JavaScript code calls a ClojureScript function, and a ClojureScript function calls a JavaScript library/file.
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)
default-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)]
(cond
(some? v1) (bar v1)
(some? v2) (foo v2)
(some? v3) (baz v3)))
thanks, I think I'm going to do something like this
That sounded like a nice macro writing exercise... so I wrote one š https://github.com/walterl/clj-walterl/blob/master/src/clj_walterl/core.clj#L15
The difference to @UBSREKQ5Q's solution being that all (potentially slow/expensive) tests don't have to be performed ahead of time.
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))))))
Did LISP ages ago at university, looking forward to doing it it's style again while learning functional programming.
Looks to be the way with Compojure and Hiccup. https://purelyfunctional.tv/mini-guide/what-web-framework-should-i-use-in-clojure/
I like bidi better as it supports reverse routing: https://github.com/juxt/bidi
I am trying to deploy a Clojure app on Ubuntu 20.04. Is openjdk-11-jre-headless
enough, or I should install default-jre
?
itās better to be explicit about the version of the runtime environment, so i would choose the former.
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 %))
f))
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)}{0.0.0.0:6000}
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?what version of java is on your mac? what version is on the server?
Mac:
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)
Ubuntu:
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)
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
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-world
⦠lein 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 repocom.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.
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