Fork me on GitHub

how can i get lein to reload things? i'm using the reload middleware with ring but i edit the clj file and no change..


the reload middleware only acts when new requests come in, you can use (require 'some.ns :reload) in a repl (this works with clojure alone, not a lein feature)


there's also :reload-all to recursively reload


it's working, with reload/wrap-reload


thanks many for your help.


I'm getting a weird message on my serverbox


v@n1:~/cushion/resources$ lein run Could not transfer artifact org.clojure:core.unify:pom:0.5.7 from/to central ( Received fatal alert: protocol_version This could be due to a typo i


can there please be a neural net trained on working PROJECT.CLJ? lol


unmatched delimiter ) and there is only one open paren and one close paren in the whole damn file


It isn't a typo


Lein is guessing that if it has an error fetching a dependency it is because you mistyped the dependency


But in this case the error is due to using an old jvm that defaults to a version of tls that most servers have stopped acceptting


You can Google the error message and read all about it


thanks, i did not have much luck googling it.


Those were the first two search results for me from Could not transfer artifact maven: Received fatal alert: protocol_version using Bing.


@hiredman @seancorfield thanks, updating java worked even though it seemed to not work.


Now i'm getting a "Exception in thread "main" Syntax error compiling at (compojure/response.clj:64:9)."


"Caused by: java.lang.RuntimeException: No such var: response/url-response"


okay I just had to make sure every dep was up to date


thanks, lesson learned / noted

Ashley Smith11:07:24

Hey everyone, this sounds a little vague but.. I have a trivial hello world backend and a reagent cljs front end. How do I actually go about connecting them? For something as simple as retrieving the string 'hello world' from the backend and then showing it in my front end app? Is there some sort of package I need to use? I'm using Vagrant and ansible, so the backend is running on a vm that I need to connect to through my front end. Can somepone point me in the right direction - is 'Luminus' what I'm looking for?


if you're asking about how to get data from your backend: There's many ways (most commonly http requests). If you're asking how to see your frontend in your browser: Then it could be through an entry-point from your backend (so basically an endpoint that gives back the html with the javascript (reagent-frontend) and css. or hosting that entrypoint somewhere else, or opening it locally.


if you start a new project with something like lein new luminus my-proj +reagent +postgres (or +mysql) and then have a look at how the project is laid out that should give you a good starting point

Ashley Smith11:07:48

Oh no, I can see my front end easily, but it's just seperate from my backend

Ashley Smith11:07:26

just trying to make the hello-world of an app with a backend


I don't really understand then, maybe follow crispin's advice?


that should give you a project with backend and frontend and database


it has a dev mode with hotloading


and when you lein uberjar it will build a release version, minified, that is all bundled into a single jar for deployment


any problems you can ask in the #luminus channel on this slack

Crispin12:07:26 has more options for the starting template

Ashley Smith12:07:08

Thank you! I'm thinking about using re-frame as that looks like it handles some of that stuff anyway


An alternative to luminus is Juxt's edge. Based on stuff like yada, integrant, tools.deps. And an (arguably simpler) alternative to reframe is fulcro. You can also look at pedestal's interceptor (which yada also uses) for a more expressive abstraction than middleware (ring). Just pointing out some stuff that expanded my mind when learning Clojure.

Ashley Smith15:07:38

Thank you! I'm going for reframe, ring and compojure ๐Ÿ™‚

๐Ÿป 4
Ashley Smith14:07:55

would people recommend working with clj-http or ring?


what are you trying to achieve?


they are different - you use ring for building an http server (more or less) and clj-http for communicating with servers/APIs from a client (perhaps calling other backend services from your server code)

Ashley Smith21:07:01

oops sorry I'm still a little new to slack I didn't realise I had this thread! I found ring and compojure (I think that's how you spell it)

Ashley Smith21:07:13

now I'm trying to get it all working in a vm with vagrant and ansible


Vagrant and Ansible are really unrelated to this question I believe ๐Ÿ™‚


Iโ€™d vote for ring, itโ€™s widely used and has been around for a long time. Very stable.

Ashley Smith14:07:40

it does seem like it. Okay, so ring will be sitting on the server, do I need another package for the client to talk to it?


Youโ€™ll want something on the server side to manage your routes for you, probably compojure would be a good start.


The compojure lib will set up the server side so it knows how to respond to requests. Then youโ€™ll use something (probably re-frame-http-fx) on the browser side to send requests to the server, and handle the responses when they come back.

Ashley Smith14:07:07

thank you!

๐Ÿ‘ 4

i'm having trouble figuring out how to use lists/vectors. i understand the implementation differences between them (linked list vs array list) and what that implies, and i've read a few different "should i use lists or vectors?" blog posts/SO questions. i guess the part that's confusing me is why they have different semantics when used with seq functions (conj, cons, etc). isn't that counter to clojure's "code to abstractions" principle?


[12:22] <Raynes>    When would you want to use a list over a vector?
[12:22] <rhickey>   when generating code, when generating back-to-front
[12:23] <rhickey>   not too often in Clojure


Personally I always use vectors

๐Ÿ‘ 4

yep. agree. Use vectors unless theres a special reason you want a list.

โœ”๏ธ 4

yeah, that's the "rule of thumb" as i understand it. (and i saw that quote in a SO question simple_smile.) applying that, though, i found myself stumbling over the semantics a few times, and that got me thinking that i'm misunderstanding something.


as it is, it means that i need to by very aware of the concrete type of the seq i'm working with, to know what effect a conj will have. it feels like i'm just missing something, and would appreciate being pointed in the right direction.

Alex Miller (Clojure team)14:07:43

conj and cons are not seq functions

Alex Miller (Clojure team)14:07:09

they are collection functions and have different polymorphic behavior based on the collection type

๐Ÿ‘† 12
Alex Miller (Clojure team)14:07:39

you might find some of these similar faq questions helpful


that FAQ is very good! i guess i'll just have to read all of it ๐Ÿ™‚

Alex Miller (Clojure team)14:07:15

please do! Most of the questions were added from questions like yours in these forums, so keep asking questions! :)

๐Ÿ’ฏ 4

they are consistent in their time behavoir (is that the term)? For example conj always places in the optimal position (head of a list, tail of a vector). cons is for constructing cons cells, so doesn't apply to vectors.


that makes a lot of sense. thanks @alexmiller, @crispin. i'm off to read those links ๐Ÿ™‚

๐Ÿป 4

There is a lot of deep thought behind the design decisions. Like when I first saw (contains? [:a :b] 1) => true I thought it was wrong. But then when it was explained, my mind was blown at how correct it was ๐Ÿคฏ


Yup. The way most fns in core depend on well thought out abstractions and not concrete DS impls is amazing, and pleasantly surprises me repeatedly. It "just works" while doing close to no magic.


there's a lot of thought for sure, but that's just an implementation detail in this case right?


and a misleading one in my opinion


I doubt that many people use contains? to find out whether an index is in range for a vector or an array in Clojure, given that is not very often a useful thing to do (or at least I haven't wanted to use contains? for that), but that behavior is part of the official doc string of contains?. Not sure whether that affects your categorization of it as an implementation detail or not.


I don't think it is an impl detail. contains? tells whether a key is present in an associative thing.


And a vector is an associative thing

Alex Miller (Clojure team)15:07:44

it's mostly useful when using something like get-in to dive through a structure that is a mix of vectors and maps


Yep. vectors are keyed by their index, not their contents. Sets are keyed by their contents, and so (contains? #{:a :b} :a) => true. Its actually completely consistent.


its certainly consistent and helpful in some situations.


i think the "mind blown at how correct it was" is a bit more enthusiasm than i have


Small things impress small minds, I suppose. ๐Ÿ˜‹ I had only thought about it shallowly, and its another example of the deep thought behind the design of clojure.

Ashley Smith15:07:09

Hello, I have a question about use vs require. I've read that use is basically the same as require, but you can use all the name spaces functions. I wanted to use require with :as, but for some reason the following snippet won't work if I try (:require [ring.adapter.jetty :as jetty]):

  (:use ring.adapter.jetty))
; (:require [ring.adapter.jetty :as jetty]))

(defn app-handler [request]
  {:status 200
   :headers {"Content-Type" "text/html"}
   :body "Hello from Ring"})

(defn -main
  [& _]
  (run-jetty app-handler {:port 8080})
  ;( app-handler {:port 8080})
The command run-jetty is the problem as it cannot be found.

Alex Miller (Clojure team)15:07:38

use is require + refer-all

Ashley Smith15:07:08

That's what I read, I just didn't use /, I used . instead when doing jetty/run-jetty



Ashley Smith15:07:31

oh gosh that feels dumb ๐Ÿ˜›


not dumb. this is the channel for it.


I have my repl up and running, then I add a package to my project.clj dependencies. Do I have to restart my repl to get that package available?


Or is there some slick way to do that?

Alex Miller (Clojure team)16:07:19

generally, yes you have to restart your repl

Alex Miller (Clojure team)16:07:43

however, there are various plugins or ways to get this to work in a limited way

Alex Miller (Clojure team)16:07:30

but they are fiddly enough, and adding new deps is infrequent enough, that imo they are not with using


Fair. I tried to compare java.time with standard operators, and it got mad. So I need to add


Is there a reason I can't get this to work with (require '[jave-time :as time])


maybe jave -> java ?

๐Ÿ˜ซ 4
๐Ÿ˜ 4

what is the "Right Way" to prepend 2 values to a vector (vec (cons 1 (cons 2 [3 4 5]))), (-> [3 4 5] (cons 2) (cons 1) vec), (into [1 2] [3 4 5]), (vec (concat [1 2] [3 4 5])), or something else?


@clojurians-slack100 The first thing to realize is that for Clojure's built-in vector, if you want the result to be a vector, it takes linear time to prepend an element, which is fine if you do it rarely, but a performance-killer if you do it commonly.


Given that, I don't think there is a "right way", because people rarely do it. As long as you don't actually choose a way that is slower than linear time, I'd say go for what is clear to you.


to give some context, this is part of [this kata]( i'm taking pop-ing the "top" card from each player's deck, and putting it on the "bottom" of the deck of the player with the highest card. i'm using vectors for the decks, and that may very well be wrong.


Raising up a level, if you do want to do this as a frequent operation during run-time, it is worth asking what set of operations you want out of a data structure, and perhaps pick a different one that supports them more efficiently.


i think that is exactly what i'm struggling with ๐Ÿ™‚


If the operations you are referring to are limited to a few operations per second, for human reaction times, and to vectors limited to card hand sizes, I doubt you will ever notice a performance issue.


If you are trying to simulate billions of card games per minute, then it could be a performance issue.


i understand, thanks ๐Ÿ˜ฌ ๐Ÿ‘


then i guess (into [1 2] [3 4 5]) it is ๐Ÿ™‚


If you ever do get into a situation where you want a persistent data structure like a vector with efficient add and remove operations at both ends, the core.rrb-vector library may be worth looking into. If you need remove-from-front, add-to-back only to be efficient, Clojure has the PersistentQueue type.


i'll look into those, thanks

dpsutton16:07:41 as well. although i've looked and never found of an example of this used in production

๐Ÿ‘ 4

but now you're also touching on part of the modelling problem that i'm struggling with: i chose the back of a vector to represent the top of the deck, simply because that is the value that pop gives me. i.e. it was a very naive choice. was it "ok", though?


I know that core.rrb-vector has some outstanding bugs that have been found via its production use in the fipp pretty-printing library. I don't have performance numbers handy, but I believe the constant factors in the run-time efficiency are better for core.rrb-vector's data structure, vs. finger trees. That said, I do believe they both have good big-O run-time performance.


If the common operations are add-card-to-top, remove-card-from-top, and it is an uncommon operation to access the bottom of a deck, then top=end-of-vector is a good choice for Clojure vectors, to keep the frequent operations efficient.


afaict it's only the one case where cards are added to the bottom of the deck (front of the vector), so it's probably fine. thanks, @andy.fingerhut! ๐Ÿ™‚

Anik Chowhdury17:07:44

Can anyone know how to render same page using selmer in luminus?


@anikchy.cuet93 you would invoke the rendering function to generate the return value of a route handler


NB it's a back end only library, it doesn't do client side rendering


Hello all! I could use help getting Cursive setup. I'm trying to debug some tests in the leiningen generated test folder and I don't know how to get a debugger (repl or otherwise) to tie into 'lein test' code execution.


Someone here may be more familiar with Cursive than I am, and could help you. I only wanted to mention that there is also a #cursive channel on Clojurians Slack that you may wish to ask there.


ty! I'll try there.


Is it clojure esque to make tests for every function, or at least important ones? i see in many templates a simple test, but not lots of tests for various namespaces.


Follow up question, is it normal to write tests for cljc files?


@david.folkner I think Clojure devs write a lot fewer tests than you might see in some other languages since they "test" everything as they write it in the REPL (or at least they should ๐Ÿ™‚ ).


So test usage will vary a lot. I tend to use tests pretty heavily -- probably more than the average Clojure dev? At work, we have about 80K lines of code and 20K of that is tests.


I get that, I got into the habbit of writing tests for things, so that way its repeatable.


I have a validation function and struct in my cljc. Where does that test go?


Since CLJC is kinda both. I have folders in my template for CLJS and CLJ testing.


I don't use .cljc enough to have an opinion. I don't do any ClojureScript at all.


@david.folkner I don't think you can claim cljc has test coverage unless it has tests that run under both clj and cljs


especially because of reader conditionals

eskemojoe00717:07:50 make tests in both locations? That actually makes sense to me.


a test can require a cljc file


Current project is simple one, but I have some big plans for CLJC validation that will need really robust tests.


that is, you can have a function, calling test/is, that is loaded in clj and cljs


so it is written once, and exercised under both vms


So make a test>cljc>appname>validation.cljc. Then in each other tests absorb that?


Is that absorbtion done in the project.clj or within a actual file within each test>clj and test>cljs folders?


if a deftest calls a function that calls is, that is works as a test assertion


so you can require the ns from each side, and call the function that makes assertions


That makes sense to me, but then I'm writing tests on both sides of clj and cljs, not a single test right?


each deftest only calls a single function


Yes, but multiple deftest.


right - but they are stubs


Which is fine, I just thought I understood that I could write a single deftest and run it both places.


maybe there's a way to make leiningen do that, I'm really not sure


leiningen's test running is its own thing - it does a tree walk and loads every ns under some directory


as opposed to the clojure.test machinery, that runs every function with the magic test metadata


So you say, make a test file for my cljc tests, then create standard functions (`defn`) that call test/is and/or other test functions I need. Then make simple wrapper deftests in each clj and cljs files. That makes sense to me.


right - that's likely the simplest thing, unless lein knows how to load cljc files for tests (and load tests from multiple directories)

Ashley Smith18:07:08

hello.. its me again.. :'D I've been learning about compojure and ring today, but one thing is confusing me and their IRC is dead. On this page: it shows a small webserver serving different pieces of content per route. However, that snippet has no main function, and so if I place that into my core.clj file, it doesn't work. If I was to put a main function in there, surely I need the program to not end straight away, so I need to stall it right? What's really going on here, what is the way forward? I currently have this: but the app-handler handles everything and ignores the other routes. Anyone with experience?


it's odd to me that nothing in app calls app-handler


and it's also odd that jetty is run with a specific handler, rather than the app which does routing

Ashley Smith18:07:49

They don't have an app-handler function in their snippet, thats just on there from their docs. I was going to get rid of it when I got this defroute stuff working

Ashley Smith18:07:15

don't look at my paste that's just what I have. What's confusing me is that their snippet seems like it doesn't do anything?


OK - then app should be an arg to run-jetty, or your router would never get used


and some route(s) would call app-handler to generate a result

Ashley Smith18:07:20

so in terms of my website, will my front end make calls using these routes? Is that what they're for?


ring accepts multiple kinds of values - a string (implicitly code 200), a stream (same) or a hash-map describing result code, headers, body


your frontend would make requests for those routes, yes


usually using the AJAX object

Ashley Smith18:07:31

okay, learning. Sorry for being so slow with this stuff

Ashley Smith18:07:36

its my first time encountering it

Ashley Smith18:07:29

okay! So that looks like it's working! thank you

๐Ÿป 4
Owen M20:07:41

So I really wanna use clojurescript for my project, but the further I look into it, I think it might not be the right tool for my use case. Essentially I have a Web app using Firebase firestore as a datastore. It implements a realtime database, I'll have to do some manual configuration to ensure the realtime aspect is respected by Cljs. I read this to get an idea of how: That's the first hurdle. My data is in the form of a bunch of tables & a binary tree. I am trying to transform that into a tournament bracket visualization, think of the world cup (kind of like this The binary tree is the knockout stage, the group stage is the tables. I have found some very nice react libraries such as: which provide toggleable, zoomable tree visualizations. And I would look to implement something similar in Cljs. But I haven't seen anything similar in Cljs, is there any tooling or resources that could teach me how to implement my own interactive bracket? (zoomable + toggleable) Is Cljs the right language for my use case? I could really use some guidance, thanks.

Justin Duncan21:07:51

Is om-next still an active project? I am having a difficult time finding recent resources(<2years)


I think om-next is pretty much in maintenance-only mode. I would look at Fulcro as a modern edition of Om

โœ”๏ธ 4

@owenmonagan you can use React and libraries in CLJS, or use d3 directly. firebase has a fairly straight forward JS API that should be usable from CLJS as well


itโ€™s not going to be completely clear-cut, though, as you will probably end up translating a lot of JS into CLJS, which requires some familiarity with both languages

Owen M21:07:12

thank you!

Justin Duncan21:07:37

Thanks a ton, luckily I am a pro in JS ๐Ÿ˜„


Is it common/good practice to wrap functions under the same name in a new namespace to "centralized" the API ? for ex: (defn do-foo [x] (ns.common/do-foo x...)


it depends on why do-foo is even in another ns


but no, it's not something you see a lot


if anything I've seen (def do-foo ns.common/do-foo)


for cases where our idea of doing foo matches what ns.common defines


do-foo is a function that serves as util for other namespaces but also an api for that part of the app


yeah, more like your example


another option is code duplication


guess its not a bad trade-off


pretty good practice imo for something where you want to say โ€œthis namespace is the apiโ€


I guess it might mess up api doc generation though?


the (def foo x) form. the (defn foo [y] (x y)) form will generate fine


amusingly, this almost works

user=> (defn foo "a doc string" [])
user=> (def bar foo)
user=> (doc bar)
user=> (alter-meta! #'bar merge (meta #'foo))
{:line 1, :column 1, :file "/Users/justin.smith/.Trash/finops-recon/target/e0c97b7b414aee8746db4bdaacde369a3807c0c2-init.clj", :name foo, :ns #object[clojure.lang.Namespace 0x4a3cef67 "user"], :arglists ([]), :doc "a doc string"}
user=> (doc bar)
  a doc string


I wonder when nrepl started putting source forms in the .Trash directory


that might even be better. as any other useful stuff (docstrings, specs etc) only needs to get defined in one place then