This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-07-24
Channels
- # announcements (5)
- # beginners (184)
- # calva (32)
- # cider (29)
- # clj-kondo (1)
- # cljdoc (29)
- # cljsrn (6)
- # clojure (44)
- # clojure-dev (36)
- # clojure-europe (9)
- # clojure-italy (18)
- # clojure-losangeles (1)
- # clojure-nl (3)
- # clojure-spec (7)
- # clojure-uk (30)
- # clojure-ukraine (1)
- # clojuredesign-podcast (8)
- # clojurescript (65)
- # code-reviews (21)
- # core-async (25)
- # cursive (51)
- # data-science (3)
- # datascript (2)
- # datomic (25)
- # emacs (14)
- # events (1)
- # figwheel-main (3)
- # fulcro (3)
- # graalvm (5)
- # jackdaw (17)
- # kaocha (14)
- # luminus (5)
- # off-topic (17)
- # pathom (7)
- # pedestal (2)
- # re-frame (71)
- # reagent (25)
- # shadow-cljs (83)
- # spacemacs (31)
- # sql (92)
- # tools-deps (23)
- # vim (102)
- # xtdb (5)
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 (https://repo1.maven.org/maven2/): 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
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
thanks, i did not have much luck googling it.
@sova See if this helps https://stackoverflow.com/questions/50946420/could-not-transfer-artifact-https-repo-maven-apache-org-maven2-received-fat
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
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
Oh no, I can see my front end easily, but it's just seperate from my backend
just trying to make the hello-world of an app with a backend
and when you lein uberjar
it will build a release version, minified, that is all bundled into a single jar for deployment
http://www.luminusweb.net/docs/profiles.html has more options for the starting template
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.
would people recommend working with clj-http
or ring
?
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)
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)
now I'm trying to get it all working in a vm with vagrant and ansible
I’d vote for ring, it’s widely used and has been around for a long time. Very stable.
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.
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
yeah, that's the "rule of thumb" as i understand it. (and i saw that quote in a SO question .) 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.
conj and cons are not seq functions
they are collection functions and have different polymorphic behavior based on the collection type
you might find some of these similar faq questions helpful https://clojure.org/guides/faq#conj
please do! Most of the questions were added from questions like yours in these forums, so keep asking questions! :)
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 🙂
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?
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
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.
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.
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])
:
(ns server.space.core
(:gen-class)
(: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})
;(jetty.run-jetty app-handler {:port 8080})
The command run-jetty
is the problem as it cannot be found.use
is require
+ refer-all
That's what I read, I just didn't use /
, I used .
instead when doing jetty/run-jetty
whoops
Oh, my bad!
oh gosh that feels dumb 😛
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?
generally, yes you have to restart your repl
however, there are various plugins or ways to get this to work in a limited way
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 clojure.java-time
Is there a reason I can't get this to work with clojure.java-time
: (require '[jave-time :as time])
Well...
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](https://github.com/gigasquid/wonderland-clojure-katas/tree/master/card-game-war): 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.
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.
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.
https://github.com/clojure/data.finger-tree as well. although i've looked and never found of an example of this used in production
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! 🙂
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.
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
Ahh...so 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)
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: https://github.com/weavejester/compojure 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: https://pastebin.com/2xddrrGz 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
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
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
ooooohhhh!
Okay!
One second
and some route(s) would call app-handler to generate a result
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
okay, learning. Sorry for being so slow with this stuff
its my first time encountering it
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: http://timothypratley.blogspot.com/2016/07/reacting-to-changes-with-firebase-and.html. 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 http://mediakar.org/wp-content/uploads/2014/07/d181d0bdd0b8d0bcd0bed0ba-d18dd0bad180d0b0d0bdd0b0-2014-07-12-d0b2-16-32-16.png). The binary tree is the knockout stage, the group stage is the tables. I have found some very nice react libraries such as: https://bkrem.github.io/react-d3-tree-demo/ 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.
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
@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
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
@noisesmith found a lib example: https://github.com/ztellman/aleph/blob/master/src/aleph/http.clj#L29
pretty good practice imo for something where you want to say “this namespace is the api”
amusingly, this almost works
user=> (defn foo "a doc string" [])
#'user/foo
user=> (def bar foo)
#'user/bar
user=> (doc bar)
-------------------------
user/bar
nil
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)
-------------------------
user/foo
([])
a doc string
nil
I wonder when nrepl started putting source forms in the .Trash directory