This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-05
Channels
- # announcements (5)
- # beginners (49)
- # boot (9)
- # calva (34)
- # cider (9)
- # clara (18)
- # clj-kondo (1)
- # cljsrn (7)
- # clojure (196)
- # clojure-dev (4)
- # clojure-europe (11)
- # clojure-france (3)
- # clojure-nl (13)
- # clojure-norway (2)
- # clojure-spec (8)
- # clojure-uk (85)
- # clojurescript (87)
- # clojurex (202)
- # core-logic (6)
- # data-science (6)
- # datomic (9)
- # dirac (1)
- # duct (93)
- # emacs (9)
- # events (1)
- # fulcro (22)
- # hoplon (30)
- # jackdaw (10)
- # keechma (1)
- # leiningen (5)
- # malli (17)
- # off-topic (9)
- # other-languages (3)
- # pedestal (7)
- # re-frame (3)
- # reagent (5)
- # reitit (9)
- # remote-jobs (6)
- # rewrite-clj (80)
- # ring (2)
- # shadow-cljs (191)
- # tools-deps (54)
- # vim (14)
- # xtdb (7)
What is the difference in what compiles between lein ring server-headless
vs lein run
? In lein run I am able to slurp in strings of code, read them, and evaluate them, with lein ring server I cannot. Why is that?
there are lots, my guess is you are depending on ns having a particular value at runtime, which you can't
@hiredman got it, how can I fix that? I have this working with the same code snippet being slurped in and evaled when I start the code with lein run
, but I need to offer an API that can run these snippets that get slurped in. This only effects deps that are outside clojure core. Can I force the jetty server to include all deps to be available to read-string -> evals at runtime?
Packaged the question a bit better here:
I am running a system that slurps in string code snippets from a db, reads them, and evaluates them. When I do this with a main method via lein run
I am able to use all dependencies. But when I run a jetty server, and try to slurp in the string code snippets from a db, read them, and evaluate them I get this error saying I don't have access to the dependency the string code snippet needs:
{:type clojure.lang.Compiler$CompilerException
:message "java.lang.RuntimeException: No such namespace: http, compiling:(NO_SOURCE_PATH:0:0)"
:at [clojure.lang.Compiler analyze "Compiler.java" 6688]}
Is there a way to force jetty to load all deps and make them available at run time to string code snippets that are slurped in at run time as strings and evaluated?figured the pin was just for me
yes, and that precise thing is working today. But when I introduce a jetty server it stops working
you are expecting to be evaluated with *ns*
bound to whatever namespace is at the top of the file, which has a particular set of aliases
which is not true, it happens to happen for code loaded via lein, but is not true in the general case
when your code runs, *ns*
could have any arbitrary value, so when you load and evaluate some other code, if it does set *ns*
itself, you could get anything
(`*ns*` is the binding that points to the current namespace which is used to resolve aliases and what not by the compiler)
a very typical value for *ns*
to have at runtime when running from a jar is clojure.core
hmmmm
so maybe something like this:
(defn local-eval [x]
(binding [*ns* (find-ns 'my-namespace)]
(eval x)))
what's strange is the code snippet I'm trying to run is being evaled in the correct ns...or at least I think it is
good idea
let me see what I get real quick
but like, if you write your code with an ns declaration at the top, you can load it an compile it in almost any context
"NS: " #object[clojure.lang.Namespace 0x1896a6c "clojure.core"]
yep clojure core
so that's not what I want haha
and it will make it much easier for someone to come along later, decide they don't like the snippet thing, an replace it with the standard require call
you mean declare the ns in the snippet?
just (def *ns* (find-ns 'my-namespace))
like that?
no, I mean, in the text file that you are loading and evaluating, give it the same kind of ns form you are presumably putting at the top of all your other source files
got it
I got it working now with the local-eval thing
thank you for your help
I'll need to consider if we update the 100+ scripts with their own ns also
Any suggestions on who is good to follow on 4clojure? A Colleague suggested Christopher Grand (cgrand) but while I've found a few of his solutions online (https://github.com/nbenketaf/4clojure/blob/master/problem105.clj) I can't find his user on 4clojure 😮
@U3E46Q1DG 😊 Just in case, am I just not searching by the correct thing or do your solutions live somewhere I've overlooked?
Oh, my bad, the user search isn't great, navigating directly to the url worked http://www.4clojure.com/user/cgrand
Hey, I didn’t realize you can view others users solutions on 4clojure. The help page doesn’t mention it. How does that happen? 🙂
When you complete a solution yourself you can see answers of users that you follow
4clojure, it has been a long time — not sure I would still solve problems in the same way; plus there’s the golf aspect that makes some answers not “production ready”
No problem, thanks! Still learning a lot from it regardless, (apply map list b)
just blew my mind on your 111. Crossword puzzle 😂
my version of getting columns was about 3 lines and less readable
@ULNRSUK8C in real world I would certainly write something more like
(fn [word cw]
(->>
(for [line (concat cw (apply map str cw))
slot (.split line "#")
:when (seq slot)] ; not necessary to pass 4clojure tests
(apply str (keep #({\_ \. \space nil} % %) slot)))
(some #(re-matches (re-pattern %) word))
boolean))
My initial solution wasn't terrible (maybe) 😬 but just interesting to see what other ways exist. I wasn't trying to golf it, I'm not there yet 😂
(fn [word board]
(let [width (-> board
first
count
inc
(/ 2))
get-col (fn [i] (apply str (map #(nth % i) board)))
cols (map #(get-col (* 2 %)) (range width))]
(-> (concat board cols)
((partial clojure.string/join "|"))
(clojure.string/replace #" " "")
(clojure.string/replace #"#" "|")
(clojure.string/replace #"_" ".")
(re-pattern)
(re-matches word)
string?)))
(clojure.string/replace #"[ #_]" {" " "" "|" "#" "_" "-"})
can replace your 3 calls
Didn't think about the function version of regex, thanks for the help today!
(fn [word board]
(let [cols (apply map str board)]
(-> (concat board cols)
((partial clojure.string/join "|"))
(clojure.string/replace #"[ #_]" {" " ""
"#" "|"
"_" "."})
(re-pattern)
(re-matches word)
boolean)))
I'm not familiar with Java and I would like to know how to deploy an H2O model (POJO/MOJO) http://docs.h2o.ai/h2o/latest-stable/h2o-docs/productionizing.html using Clojure. Has anyone done this before, or know who could give me some hints? 😄
you can use genclass to generate java POJOs https://clojuredocs.org/clojure.core/gen-class
isn't that using clojure to generate POJOs? what if I already have a POJO and want to load it in Clojure?
here's an example of using genclas on a namespace: https://gist.github.com/mping/1e784c1c81108dd61d301863a06b3e28
yes, always has
what are you concerned about?
@alexmiller Heard somebody mention that pomegranate does not play with java > 8. Guessed tools.deps.alpha
may have similar issues loading deps at runtime.
Those issues with pomegranate have to do with dynamic dep loading and the changes in classloader structure in Java 9+
tools.deps does not currently have dynamic classloading facilities in the main line
there is an add-lib branch of tools.deps with some speculative code in this area but it does not have the same issues
@alexmiller Is Java 9+ missing a critical bit, or how come tools.alpha and pomegranate appear to be struggeling to get dynamic dep loading implemented?
tools.deps doesn't have an issue with this
iirc, pomegranate relies on dynapath, which can use a clojure DynamicClassLoader if it finds it but if not, also has some code to invoke protected methods on the URLClassLoader class. In Java 9+, this violates accessibility constraints.
that is, dynapath does some dirty stuff, and it's more tightly checked as of Java 9
I'm trying to add support for compojure route macros to clj-kondo and I'm wondering if the destructuring syntax can be combined with POST as well. probably yes, but I don't see any example of this in its codebase
@borkdude I would expect the destructuring to be orthogonal to the verbs since everything goes through a single request
function behind the scenes.
newb question: trying to get a preload for my repl working, but seemingly having classpath issues:
profiles.clj:
{:user {:dependencies [[cider/piggieback "0.4.2"]
[org.clojure/tools.nrepl "0.2.13"]]
:source-paths ["/home/daniel/.lein/preload/"]
:repl-options {:init-ns user}}}
cat /home/daniel/.lein/preload/user.clj:
(ns user)
(def data 23)
(println "that's podracing!")
lein repl
#error {
:cause Could not locate user__init.class, user.clj or user.cljc on classpath.
:via
[{:type java.io.FileNotFoundException
:message Could not locate user__init.class, user.clj or user.cljc on classpath.
user=> (seq (.getURLs (java.lang.ClassLoader/getSystemClassLoader)))
(#object[java.net.URL 0x6b5df995 "file:/home/daniel/.lein/self-installs/leiningen-2.9.1-standalone.jar"])
well, no idea about the classpath issue, but :init (load-file $path)
seems to be working.
Thanks all.
I am facing issue while installing clojure inside the docker..any pointers please. I am trying to install it with Java 11
I am working on tap-mssql for pipelinewise that is written in clojure language. To create an image of my pipelinewise doker I need to install clojure as well that requires leiningen (RUN curl https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > lein && mv lein /usr/local/bin/lein && chmod a+x /usr/local/bin/lein). when it installs clojure it is giving this error java.io.IOException: Cannot run program "/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java" (in directory "/pipelinewise/.virtualenvs/tap-mssql"): error=2, No such file or directory at java.lang.ProcessBuilder.start (ProcessBuilder.java:1128) java.lang.ProcessBuilder.start (ProcessBuilder.java:1071) java.lang.Runtime.exec (Runtime.java:591) jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (NativeMethodAccessorImpl.java:-2) jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke (Method.java:566) clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:167) clojure.lang.Reflector.invokeInstanceMethod (Reflector.java:102) leiningen.core.eval$sh.invokeStatic (eval.clj:179) leiningen.core.eval$sh.doInvoke (eval.clj:173) clojure.lang.RestFn.applyTo (RestFn.java:137)
I have version JAVA 11 installed but is it checking for 8..
I tried setting up /usr/lib/jvm/java-11-openjdk-amd64 in JAVA_HOME variable but still it is looking for 8
taking a closer look at this stack trace - clojure is already running at this point, and it is using leiningen.eval/sh to invoke a new lein process (with a new java process)
it looks like the tap-mssql command is doing something weird (based on the other screenshot you shared)
this project is defined in a weird way, this isn't a lein problem, it's a problem with the way this tap-mssql project is set up https://github.com/singer-io/tap-mssql/blob/9895f93fb960a73432b9e7a2b7622fe6ec14f227/project.clj#L31
you could fork it and ovverride its java versions?
or use a different project
what's the best way to programmatically install a particular version of clojure? per https://clojure.org/guides/getting_started#_installation_on_linux i was hoping that i might be able to use
to install clojure 1.10.1, but that doesn't seem to work.
or you actually don't care about the version of the command line utilities and you want a specific version of the language?
so you just specify the version you want in either your deps.edn or project.clj whatever you're using to manage dependencies
yup - my memory started in that direction as soon as you pointed out the difference between the CLI and language.
haha, I just wanna say, today I got a stack trace that wasn't verbose enough (a StackOverflowError with only 1,033 frames).
a lazy seq is a delayed execution, when you force it that will be the top of the stack
(under the thing that forced it of course)
@seancorfield hi, I found your example https://github.com/seancorfield/dot-clojure
:jar -- pulls in and runs the latest stable release of my fork of depstar to create a "thin" JAR; clj -A:jar MyProject.jar; along with a pom.xml (created via clj -Spom), this can be deployed to Clojars etc (via mvn deploy:deploy-file ...)
How exactly do you set
<groupId>master</groupId>
<artifactId>master</artifactId>
<version>0.1.0</version>
<name>master</name>
in pom.xml to deploy to Clojars?The pom.xml
generated by clojure -Spom
is very minimal and needs a lot of stuff added to it in order to deploy to Clojars and/or cljdoc.
But -Spom will sync and leave that stuff in it once you do add it
I have a deploy
script that modifies the <tag>
element to be the SHA of the git head.
I extracted this from tools-deps to update version from command line, like that: clj -A:build -m version 1.0.0
@alexmiller Yeah, I just meant the initial pom.xml
file isn't sufficient -- it needs editing/augmenting.
it probably can be generalized to be standalone library, but you can just copy-paste it and change lines 33-34 for your needs
FWIW, I stopped using clojure.data.xml
etc to deal with pom.xml
in depstar
because of Java 9+ issues. I just changed it to regex instead 🙂
Don't you get warnings about illegal reflective access or something?
there were issues with extra whitespace, but they were fixed both in tools-deps and in that script (`:skip-whitespace` arg)
Oh, it was clojure.xml
, not clojure.data.xml
.
Because depstar
cannot have any dependencies beyond itself and Clojure.
(and Java 🙂 )
Do you have a public example for continous deployment to clojars with deps.edn? The best for ClojureScript 😉
I don't do any cljs.
@U47G49KHQ Right, depstar
knows it can just exclude itself and use whatever is on the classpath for the JAR file. A deliberate design choice that says "Trust the user" 🙂
@U0WL6FA77 If you're doing CD, you're generating new versions as part of your CD script? Can you just modify that to read <version>XXX</version
from the front of the pom.xml
file, calculate a new version, and update the file?
There are uberdeps
that compute classpath for jar using tools-deps, so they can use other libs
Here's my cheating way to do some of it in bash
sha=`git rev-parse HEAD`
version=`fgrep '<version>' pom.xml | head -1 | sed 's;.*<version>\(.*\)</version>.*;\1;'`
echo "Setting tag to ${sha} for version ${version}..."
cp pom.xml /tmp/${1}.pom.xml
sed "s;<tag>[0-9a-f]*</tag>;<tag>${sha}</tag>;" < /tmp/${1}.pom.xml > pom.xml
🙂I want to use github actions and make version from tag version of the github release
depstar
relies on the classpath computed by the CLI / t.d.a. 🙂
Can I push to clojars and remove it after that? To test CD. Or it has to stay there after deploy?
http://Clojars.org is immutable. You can only add to it.
(except in catastrophic release situations -- such as removing a security risk)
That still leaves cruft up on Clojars tho', right?
If artifact was pushed to clojars and no one knows about it, did it really make sound
org.clojars.<yourusername>
should always be available if you wanted to use that for testing / unofficial releases.
I'd strongly discourage creating random extra group IDs on http://clojars.org -- that's antisocial.
You can test pushing to org.clojars.kwladyka/test-lib without cluttering up http://clojars.org (if that's your username).
When you have a lib that you want publicly available, maybe pick a different/better group ID (such as kwladyka
if you think that'll be unique enough).
I have org.clojars.seancorfield
but I have only used that for pushing early test versions of libs I think. I publish publicly under the seancorfield
group ID.
Yeah
Projects
org.clojars.seancorfield/clj-soap
org.clojars.seancorfield/congomongo
Those aren't "real" versions for the public.
> I’d strongly discourage creating random extra group IDs on http://clojars.org -- that’s antisocial. Oh ok, I understood it in a different way.
If you want to test your lib you can always just install to your local repo and not push at all
I want to test continuous deployment on the first place. I will use org.clojars.kwladyka
for tests purpose. Sounds reasonable.
Do you sign you clojar deploy? https://github.com/slipset/deps-deploy#signing
Pretty much no one does that any more. Clojars used to have a two-tier system where only signed JARs could be promoted to the "top tier" but it caused confusion -- and the whole signing process, dealing with GPG, seemed to be problematic for a lot of people, especially on Windows.
If you use deps-deploy
and signing works for you out of the box, there's certainly no harm in signing your JARs.
Hmm is it possible to sign it without upload private certificate for deps-deploy use?
I've no idea. I stopped signing JARs years ago.
Like I said, if you are using deps-deploy
(which I do not), and that signing option works out of the box without you needing to do anything else, then go for it. Otherwise, be like the vast majority of people pushing JARs to Clojars and don't bother 🙂
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="
<modelVersion>4.0.0</modelVersion>
<groupId>org.clojars.kwladyka</groupId>
<artifactId>form-validator-cljs</artifactId>
<version/>
<name>form-validator-cljs</name>
<url>https://github.com/kwladyka/form-validator-cljs</url>
<description>ClojureScript library to validate forms.</description>
<developers>
<developer>
<name>Krzysztof Władyka</name>
</developer>
</developers>
</project>
Do you recommend to add something more to pom.xml?Yes, lots more.
That minimal POM won't tell Clojars (or cljdoc) anything useful.
Take a look at https://github.com/seancorfield/depstar/blob/master/pom.xml or https://github.com/seancorfield/clj-new/blob/master/pom.xml
You need the scm
section so that Clojars can tie the JAR back to your GitHub repo and SHA version (or a tag). The other stuff I believe is "nice to have" (`licenses`, description
, url
, repositories
, distributionManagement
).
clojure -Spom
produces a minimal pom.xml
with a lot of useful stuff missing.
Once you've added that stuff to pom.xml
, clojure -Spom
will not overwrite it -- it will just update the dependencies
section.
But I make sure all my POM files have all of that information in them, so that Clojars and cljdoc and provide extra information and links to the source repo etc.
hmm clj -Spom
add <sourceDirectory>src</sourceDirectory>
in project
but your files contain it in <build><sourceDirectory>src</sourceDirectory></build>
. Is it a bug?
@alexmiller mentioned something about when it decides to insert sourceDirectory
but I don't remember the details.
These days I tend to copy a pom.xml
file from a project that I know "works", edit everything outside dependencies
to match the new project, and then run clojure -Spom
to just update it. I don't tend to start from a clojure
-generated POM.
Deploying org.clojars.***/form-validator-cljs-test-0.0.1 to clojars as ***
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See for further details.
Execution error (AuthorizationException) at org.apache.maven.wagon.shared.http.AbstractHttpClientWagon/put (AbstractHttpClientWagon.java:625).
Access denied to: , ReasonPhrase: Forbidden - invalid pom file: Unrecognised tag: 'sourceDirectory' (position: START_TAG seen ...</dependencies>\n <sourceDirectory>... @53:20).
Hmm it looks like sourceDirectory doesn’t workCan I do something about that? It looks like a bug in clj -Spom
command unless I miss something
@alexmiller Did you see this bug before? Do you know why clojure -Spom
generate sourceDirectory
in project
instead of project.build.sourceDirectory
?
hmm I found if I prepare:
<build>
<sourceDirectory>src</sourceDirectory>
</build>
before clj -Spom
it doesn’t create project.sourceDirectory
then.This is the thread between @U0666UM3J and @alexmiller about sourceDirectory
from October 28th: https://clojurians.slack.com/archives/C03S1KBA2/p1572324457047300
The pom.xml
generated by clojure -Spom
is very minimal and needs a lot of stuff added to it in order to deploy to Clojars and/or cljdoc.