This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-23
Channels
- # announcements (1)
- # aws (13)
- # babashka (31)
- # beginners (102)
- # calva (46)
- # cider (16)
- # clj-kondo (1)
- # cljs-dev (3)
- # clojars (1)
- # clojure (396)
- # clojure-argentina (1)
- # clojure-australia (4)
- # clojure-europe (64)
- # clojure-nl (2)
- # clojure-uk (8)
- # clojurescript (20)
- # conjure (5)
- # cursive (4)
- # datomic (15)
- # emacs (48)
- # graalvm (69)
- # graalvm-mobile (1)
- # jobs (4)
- # jobs-rus (1)
- # lsp (6)
- # malli (15)
- # meander (2)
- # observability (11)
- # off-topic (10)
- # pathom (2)
- # portal (4)
- # re-frame (19)
- # reitit (1)
- # remote-jobs (3)
- # sci (1)
- # shadow-cljs (51)
- # tools-deps (11)
- # vim (12)
- # xtdb (13)
I’m trying to use a deps.edn file to compile CLSJ as a bundle. My deps.edn looks like this:
{:deps {org.clojure/clojurescript {:mvn/version "1.10.758"}}
:asset-path "src"
:target :bundle
:optimizations :advanced
:output-to "main2.js"}
anyone know why the compiler shows this warning?Because deps isn’t a valid compiler option. You really shouldn’t merge those two files
from
- Create a deps.edn file the following contents:
- In order for this to work we need to set a couple of compiler options. Create a build.edn file with the following:
and then invoke with clj -M -m cljs.main -co build.edn -v -c -r
note -co uses a bespoke file build.edn
and doesn't try to repurpose the deps.edn file.
Not sure if this is a stupid qn but does lein uberjar
take everything inclusive of what is being used in the /resources
folder and package it into a jar
? Meaning any .csv
and even .py
I might be calling with shell/sh
yes, everything, unless you explicitly filter some files out using :uberjar-exclusions
On that same note, are there any guides you recommend to compile a leinigen backend and shadow-cljs frontend? And dockerise the solution?
is your backend serving the assets compiled by shadow-cljs?
asking because there is no silver bullet ) every situation is unique and requires some special care
Not to my knowledge. Currently am using a separate project.clj
for the backend and separate shadow-cljs.edn
for the frontend
then I would recommend to read at this link - https://shadow-cljs.github.io/docs/UsersGuide.html#release
understand what artifacts will be generated for production usage
then general advise - split your docker image preparation into stages:
• generate your client assets
• build uberjar with those assets included
• add uberjar to some thin image with jdk. An entrypoint could be something like java -jar /path/to/uber.jar
Would this only be for the frontend? Or is this if I use shadow-cljs for both frontend and backend? o: (Am only aware I can use project.clj for both)
idk, nether used shadow-cljs for backend
a jar file is basically a zip file, you can inspect it and see yourself. on my BSD system, tar works. tar xvf foo.jar | grep *.py
> Meaning any .csv and even .py I might be calling with shell/sh
these will end up in the jar if they are on the calculated classpath (eg. inside the resources/
directory with a default setup), but for shell/sh to provide the document to an OS process it needs to be copied out of the jar into a location the process can use (eg. by spitting it to a file, or providing its contents to stdin etc.)
I am curious what logging libraries people recommend or prefer. For context, I'm creating a new Clojure CLI project that will be a rest api with reitit and dynamodb and deployed on AWS Fargate (so logs will end up in cloudwatch) The common options seem to be • clojure.tools.logging and logback • Timbre • BrunoBonacci/mulog I would prefer to send logs as data rather than strings and minimising dependencies is always preferable. Thank you.
I decided to go with mulog for the logging of the new application and very happy with it so far. Its been very simple to use in the repl and wire up to the application with Integrant and Integrant REPL
if you want minimal dependencies something like https://gist.github.com/hiredman/64bc7ee3e89dbdb3bb2d92c6bddf1ff6 might be a nice start. it uses the built in java logging stuff and has an api (macros for different log levels) vaguely similar to tools.logging
I've only played around with the above, not used it at work. At worked we use clojure.tools.logging and log4j2, after migrating off of timbre
Yup we use https://github.com/gja/clj-log4j2 and it has served us well for quite a long time. Just plain old log4j2 and some macros as done in the lib work quite well. Easy to roll one's own like hiredman's gist.
how can I solve this one :
(ns rich4clojure.elementary.problem-4
(:require [hyperfiddle.rcf :refer [tests]]))
;; = Intro to Lists =
;; By 4Clojure user: dbyrne
;; Difficulty: Elementary
;;
;; Lists can be constructed with either a function or a
;; quoted form.
(def __ '(:a :b :c))
(comment
)
(tests
(list __) := (quote (:a :b :c)))
;; Share your solution, and/or check how others did it:
;;
Perhaps it is a bug in the test? The rich4clojure project is brand new and some of the auto-translated examples might be buggy...
I do not thinnk so. on 4 clojure the same code and there my solution :a :b :c
works @seancorfield
What I mean is that rich4clojure isn't working the same way as 4clojure used to. It looks like 4clojure used to just do string replacement on __
so you could enter a solution of :a :b :c
and it would work. You can't def __
to that in Clojure (as you have observed) so this is a case where the rich4clojure translation is not working the same way.
See https://github.com/4clojure/4clojure/blob/master/src/foreclojure/problems.clj#L188-L202 /cc @pez
user-forms
is a string built from the forms in the solution box -- so when you type :a :b :c
into the solution box, it reads three forms (`:a`, :b
, and :c
) and then turns them back into strings, joins them with spaces so it has ":a :b :c"
, and then it just substitutes that for the string "__"
in the test code (a string), and then reads the result and evaluates it...
Thanks! I’ll probably need to change some of the problems to adapt for how the tests now work.
Problem 4 is definitely a bit weird. I don't know how many others assume multiple input forms...
@pez 4 issues I made already and I stop now because Im going on holidays for 2/ 3 weeks
we hope, as we look at the weather expectations we get 2 weeks rain. and that is not fun with camping with a tent
@pez thanks for solving the first issues. I will test them after im back from the holidays
I think for the other issues it is more about that the user needs to read the README a bit careful. I have pushed an update to the readme where it is a bit more clearly stressed that all problems cannot be solved by redefining __
,
Hello I am using shadow cljs and I’m importing an npm library. For some reason, the import works on the node-repl, but when I import in the namespace using (:require [“…” :as …]) and try to use it I get that it’s not a function
You did npm install ...
and it works on the REPL but not in a file?
Correct. It works in shadows repl but not the file.
For the file, I get a JS object when importing but I can’t run the same functions on it- ie I get a “not a function” error
This — (:require ["…" :as …])
will work only within the (ns …)
block.
Notice that :require
is not a function that can import dependencies on its own, but a keyword - the ns
form understands it.
In standalone mode, you need to use require
(notice - not a keyword). Again, I don’t do CLJS much so there may be quirks, but that is the idea.
Right yeah so in the repl I did the function (require ‘[“…” :as x] ) and then in the file i did (:require [“…” :as x]). They should import the same thing but they did not
Yes the repl one worked and I can call the appropriate api functions, but the file one did not. While it imported a JS object, I cannot call the same functions on it.
The file version - where are you calling (:require…)
? Inside the top-level (ns… (:require ["…" :as …])
or by itself?
Yeah it’s inside the namespace declaration
Got it. Is there any more context you can provide? More code in the context of evaluation, or relevant parts of the error you see in the logs?
Yeah sure. So in the shadow node-repl, I write (require '["@babajidemm/african-countries-api" :as x])
Then I write (.. x (byName "Algeria") -body toString) and get the proper body response
In the file namespace, I write: (ns african-countries.data (:require ["@babajidemm/african-countries-api" :as africanCountriesAPI])) (defn getCountryByName [] (let [info (.. africanCountriesAPI (byName "Algeria") -body toString)] (js/console.log info)))
I call this function, get this error twice: Uncaught TypeError: module$node_modules$$babajidemm$african_countries_api$index.byName is not a function at Object.african_countries$data$getCountryByName [as getCountryByName] (data.cljs:9) at eval (views.cljs:24)
Lastly, this is important: It works in the node-repl but not in the browser-repl. In the browser-repl I get an error that says: "Execution error: "Module not provided: ./v1/lib/CountriesService"
Ok - I tried something and I don’t think I have a good answer for you. But the library you mention did not work for me in the “browser” REPL, and worked fine in “node”. Node was fine both repl and file
Ah - posted at the same time. It could be that the module format of the @babajidemm/african-countries-api isn’t supported in browsers and needs some special handling for browsers. You may find better support in the #clojurescript channel I think - a more focused group for cljs.
Thank you @U06KGH6LB, I think you're right. I think the difference is the module is build for a backend node process
Is there a difference in importing in the repl vs the namespace besides the syntax?
the namespace :import
clause is just a syntax for what import
does at the top level, both work in a file or a repl (though for obvious reasons you are more likely to have a carefully crafted ns
clause in a file)
in fact the list of things that are different between file and repl in clojure are extremely small (unless you count conventions / coding style differences, that's a much bigger list)
I find myself pretty frequently writing a predicate, receiving some trues, nils, and falses, and then wanting to get the values that returned one of those values. Is there an easy way to consistently do that? My hacky solution is to grab the indexes of those values and then the nth function on the results of the query but maybe there’s a better way
Awesome, thank you so much!
I'd like to use a namespace in the https://github.com/zk/clojuredocs/blob/master/src/clj/clojuredocs/data/import.clj source code, but its not exactly a library (there is no maven/artifactID or version number). Is it possible to use their repo as a dependency anyways? Or should I just borrow/extract the code I want and turn it into a library?
@deleted-user I had it before that I wanted them both at the same time - truthy and falsy - but in a different list. I was very happy about group-by then because I didn't have to do an extra iteration.
oops yeah. didn't even notice that comment block. gonna have to pull it out...
If it weren't in a comment expression would using a source file from a non-library be possible?
@cdimara If you're using deps.edn
and the Clojure CLI (rather than lein
) then you could have a git dependency on the http://clojuredocs.org source code and then you could reference its namespaces in your code.

However, https://github.com/zk/clojuredocs is a Leiningen project so you'd have to override that in deps.edn
(`:deps/manifest :deps`) and then you would also need to explicitly specify in your deps.edn
file, the dependencies from clojuredocs' project.clj
file.
So it's possible but non-trivial for some older projects...
what would be the artifactID/version number if there's no .pom?
You use a git dependency instead.
(! 658)-> cat deps.edn
{:deps {io.github.zk/clojuredocs {:git/url "" :sha "28f5ee500f4349039ee81c70d7ac40acbb19e5d8" :deps/manifest :deps}}}

Although in this case the checked out repo doesn't have the right structure to be able to require clojuredocs.env
-- b/c it doesn't match the default (and we had to override the manifest type).
A big plus of the CLI and deps.edn
is to be able to use repos from GitHub and GitLab directly without them needing to be deployed to Clojars or Maven.
For example: https://github.com/clojure/tools.build -- it has "releases" but they are only tags on GitHub -- it doesn't exist on Maven or Clojars -- but you can see in the README how to depend on a specific tagged release from GitHub directly.
You said "the checked out repo doesn't have the right structure to be able to require clojuredocs.env
" Whats wrong with the structure?
If you make the :path
["src/clj"] the folders match the namespace.
Yes, but you shouldn't edit the checked out repo -- you should pretend it is immutable -- otherwise it won't work on someone else's machine.
got it
Thank you Sensei Corfield!
@deleted-user I could see a situation where you want to see all of your values but you don't want to produce the results.
So, say you had a bunch of input say a vector of unknown numbers.
And your predicate was even?
if you do the group-by
you get your results and they're labled by the result of your predicate.
you can do destructuring and hold on to your results forever.
yes. Thats if you don't need the other values.
But if you need them both AND you want to inspect a few, group-by allows you to do that work just once.
I'll try
I decided to go with mulog for the logging of the new application and very happy with it so far. Its been very simple to use in the repl and wire up to the application with Integrant and Integrant REPL