This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-16
Channels
- # announcements (3)
- # babashka (25)
- # beginners (71)
- # calva (18)
- # clj-kondo (52)
- # cljs-dev (94)
- # cljsrn (12)
- # clojure (33)
- # clojure-europe (52)
- # clojure-nl (2)
- # clojure-uk (27)
- # clojurescript (18)
- # clojureverse-ops (4)
- # datomic (64)
- # deps-new (27)
- # depstar (5)
- # events (5)
- # fulcro (5)
- # graalvm (12)
- # graalvm-mobile (82)
- # helix (2)
- # introduce-yourself (1)
- # juxt (5)
- # lsp (10)
- # malli (7)
- # missionary (1)
- # off-topic (41)
- # pathom (69)
- # pedestal (6)
- # re-frame (4)
- # reagent (8)
- # releases (9)
- # remote-jobs (8)
- # shadow-cljs (3)
- # sql (46)
- # tools-deps (44)
- # uncomplicate (1)
- # vim (83)
I find myself using "(require '[clojure.string :as str])" in the REPL a lot. Is there a way to configure clj or lein repl to run this on startup?
I don’t know if it’s idiomatic, but this works:
$ clj -e "(require '[clojure.string :as str])" --repl
user=> (str/upper-case "a")
"A"
@U01TLNH6ULD Another option is to have a user.clj
file on your classpath (usually in a dev
folder which is only added to the classpath via an alias/profile) and have it do that require:
(! 521)-> cat dev/user.clj
(ns user (:require [clojure.string :as str]))
(! 522)-> cat deps.edn
{:paths ["src" "resources"]
:aliases
{:dev {:extra-paths ["dev"]}}}
(! 523)-> clj -A:dev
Clojure 1.10.3
user=> (str/trim " x ")
"x"
user=>
Clojure itself automatically loads the user
ns at startup, so it will load a user.clj
file if present.
How do I access the classpath on a Mac? I found these instructions: "Go ahead and open the *~/.profile* and make sure that the PATH variable is set and includes */usr/local/bin* and */usr/local/sbin*. You should have a line in the file that looks similar to the following, if not add it to the end of the file." but I'm not sure where to find ~/.profile
classpath is not related to shell path (which is what ~/.profile
and PATH
is about).
~
means "home directory". If you're in Terminal, ~/.profile
will refer to your .profile
file if it exists.
Alternatively /Users/<yourusername>/.profile
if you're after the full path (at least on the version of macOS I'm using).
Ok - I see my Home directory when I open terminal. the "~" refers to this directory?
Correct.
If I use lein, is the classpath set somewhere automatically?
Thank you for that info - I see "~" all the time, and never knew what it meant
You can type
echo $PATH
to see what is on your path by default.Which instructions are you trying to follow?
I was just using it to figure out what a classpath was
Hmm, I just installed brew
per the HomeBrew home page https://brew.sh/ and then brew install clojure/tools/[email protected]
I don't remember needing to mess with .profile
for that -- but my .profile
has a lot of additional weird stuff in already...
And this advice is definitely wrong: "Donwload and unzip Clojure" -- that tutorial is a bad one to follow. It's very outdated.
https://clojure.org/guides/getting_started is the best place to start. Lots of tutorials out there are very out of date.
Thanks! You're always so helpful
when can we use dorun
and doall
? i was going through documentation and I did not get actual use
for example map
function produces lazy sequence.
(def x (map #(prn %) (range 10)))
;; => #'user/x
;; no prints
(def x (doall (map #(prn %) (range 10))))
;; 0
;; 1
;; ...
;; #'user/x
so using doall
will force map
to perform all sideeffectsthe difference between dorun
and doall
is in the result. former will return nil but later will return collection
what if we have any custom function in map which is not producing side effect? then dorun
will be useful?
Without side effects, then dorun will be useless to you unless you want a space heater, as it discards the returned value. The purpose of dorun is to run through a side-effecting lazy sequence without consuming your memory.
doall is also going to be useless with a non-side-effecting function unless you really want the computation to happen immediately to prevent latency when looking up later elements.
doall is very useful when you want to do a for
comprehension with side effects.
I'm using figwheel-main, clj tool, and reagent and I'm unsure of how to mount the app,
(defn mount []
(d/render [home-page] (.getElementById js/document "root")))
(defn ^:after-load re-render []
(mount))
(mount)
this works but I've seen people do it in other ways, a lot of the docs show how to mount using shadow-cljs instead of figwheelmount
looks good to me.
re-render
will mount one more time after each code reload. You might also want its opposite:
(defn ^:before-load unmount []
(reagent.dom/unmount-component-at-node (.getElementById js/document "root"))
)
So you get:
• initial mount
• unmount before code reload
• re-mount after code reloadHere is the boilerplate template I use for CLJS projects: https://github.com/athomasoriginal/create-reagent-app
Maybe that can provide some guidance
is there a particular reason you use (defonce start-up (do (mount) true))
instead of just (mount)
?
I this scenario, not yet. It’s meant for writing reloadable code. You want to control your side effects and that’s what this does
I add it so that whoever uses this templ has a place to put stuff that should not re-render
Creating a project with the figwheel-main template provides a very similar approach https://github.com/bhauman/figwheel-main-template This is what I use to start my own projects. It sets up some nice build profiles too
I'm also not sure how to connect CIDER to this (`clj -M:dev` then cider-connect
doesnt work, and cider-jack-in
does not connect to the project)
Cider has to inject some dependencies. This is what cider-jack-in is for.
Open deps.edn
in your emacs then invoke cider-jack-in
, it should detect the deps.edn
file and run the clj
command for you.
I tried this, but for some reason it still connects to the user
namespace, that is how I can know that it is connected right (by seeing that it is in the project's namespace)?
but even then, if I try (.log js/console "test")
, it will say that there is no such namespace js
Ah! You are connecting to a clojure repl, not a clojurescript repl, hence the js
ns is not defined.
I don’t know how to connect to a cljs repl using deps and figwheel. I use shadow-cljs.
Thanks, I've found the answer.
I just had to do cider-jack-in-cljs
and choose figwheel-main
and it works perfectly, as per the figwheel docs on using CIDER.
hi there! I'm having the same problem connecting cider to a repl. I'm following both and , but it's not quite right! I can get a repl started from within emacs/cider by running cider-jack-in-cljs, but I can't evaluate forms within the .cljs files which is my main goal. Any advice?
Try to evaluate (type 1)
. If it returns object[Number]
you have a cljs REPL. If it returns java.lang.Long
, it's a clojure REPL.
If it works but you can't evaluate from the source buffer, look at how sesman
works with cider. Especially sesman-link-with-buffer
https://docs.cider.mx/cider/usage/managing_connections.html
Also remember that a cljs REPL has to be connect to a JavaScript runtime (browser or node)
@U2DART3HA many thanks! My repl does open correctly and links to the browser, with (type 1) returning #object[Number]; also entering (println "test") is reflected in the browser console.log.
This narrowed the problem down to evaluating forms from the buffer holding my .cljs files. This wasn't working. I checked the sesman pages and it helped my understanding, however my brief checks didn't reveal anything obvious.
Next I noticed a warning was showing when I opened .cljs files -- "[warning] something in your configuration activated 'clojure-mode' instead of 'clojurescript-mode' for this buffer. This could cause problems." My emacs configuration is unchanged from the excellent Daniel Higginbotham's https://github.com/flyingmachine/emacs-for-clojure/. I browsed through the config files in my .emacs.d dir (I'm a very basic emacs user so this is a stretch for me!!) and couldn't see any obvious culprits although I imagine there needs to be a clojurescript specific addition.
Embarressingly, all I needed to do in the end was enter m-x clojurescript-mode. I can now evaluate (type 1) in the .cljs file buffer. This works, so even though not "perfect" it will keep me right for now. I'm sure I'll make the minor amendments needed to my emacs config when I become more familiar with emacs. Thanks for your help!
Cider has three modes:
- clojure-mode (clj)
- clojurescript-mode (cljs)
- clojurec-mode (cljc)
The default configuration should map each file extension to the corresponding mode. If it doesn’t then probably something is overriding it.
If your editor misaligns file extensions and repl types, you might also want to look at cider-set-repl-type
. I havent found it in cider doc, but M-x describe-function RET cider-set-repl-type
says
Set REPL TYPE to clj or cljs.
Assume that the current buffer is a REPL.
So if you have a cljs repl but your editor thinks it’s a clj repl: cider-set-repl-type RET cljs RET
Thanks @U2DART3HA really helpful to know about cider-set-repl-type. Yes, I think I will need to get my default configuration properly set up for clojurescript as well as clojure files. I imagine it could get very complex very fast if I keep using a manual approach, ie entering clojurescript-mode
for each and every .cljs file I have open.
Cider has to inject some dependencies. This is what cider-jack-in is for.
Open deps.edn
in your emacs then invoke cider-jack-in
, it should detect the deps.edn
file and run the clj
command for you.
I wonder if there is a study group for clojure and/or for learning to use react with clojure ?
Does anyone know why this isn’t working?
(def note-processing-sheet (spreadsheet/load-workbook "note-processing-sheet.xlsx"))
Execution error (NoClassDefFoundError) at org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream/<init> (ZipArchiveThresholdInputStream.java:63).org/apache/commons/compress/utils/InputStreamStatistics
I’m using Docjure
(ns functions-for-processing-notes.core
(:require [dk.ative.docjure.spreadsheet :as spreadsheet]
[com.rpl.specter :refer :all]
[clojure.data :refer :all]
[ :as io]
[me.raynes.fs :as fs]))
I’m really confused because the code was literally working a few days ago and it’s unchanged
have you changed your deps since then? you could compare the output of lein cp
before and after the breaking change, I'd suspect some transitive dep issue or accidentally removed dependency
Huh, thanks for the heads up. I removed me.raynes.fs dependency and it started working again… any idea why that would be a problem?
because transitive deps are tricky, it could be that the fs dep is old and pulls in a version ofcommons/compress that doesn't have the right class present
in general anything from me.raynes is likely old and undermaintained (he was a productive member of the community RIP)
it's likely there's a way to use fs, but use :exclusions or an explicit dep on commons/compress to make the right version come in
there is a community maintained version i believe. i i think they maintain the same namespaces even though the coordinates have changed
Awesome, that makes sense, thank you
I’ll play with the current community version
Would anyone have tips on setting up cache-control
for static assets? also, using Reagent if that matters
https://web.dev/uses-long-cache-ttl
cache-control
is part of the server response and reagent is a client side library. How are you serving your website?
We’re using firebase, I guess the config is in there, Thank you
A lot of website hosting options already have a recommended way to serve static assets that should (hopefully) use best practices