This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-10
Channels
- # announcements (1)
- # apache-kafka (1)
- # beginners (61)
- # bigdata (1)
- # brompton (3)
- # buddy (1)
- # calva (18)
- # clara (2)
- # clj-commons (1)
- # clj-kondo (21)
- # cljs-dev (2)
- # clojure (32)
- # clojure-europe (10)
- # clojure-filipino (4)
- # clojure-france (2)
- # clojure-italy (5)
- # clojure-nl (4)
- # clojure-spec (28)
- # clojure-uk (14)
- # clojurescript (6)
- # conjure (1)
- # cursive (5)
- # data-science (1)
- # datahike (2)
- # datomic (9)
- # emacs (4)
- # esprit (17)
- # fulcro (14)
- # jobs (1)
- # jobs-discuss (18)
- # lsp (1)
- # malli (27)
- # msfs2020 (22)
- # off-topic (7)
- # pathom (3)
- # portal (1)
- # re-frame (23)
- # reagent (4)
- # reitit (1)
- # remote-jobs (1)
- # shadow-cljs (5)
- # sql (11)
- # tools-deps (77)
- # vim (19)
So I'm starting a server with lein ring server-headless
but there's something going wrong when I connect to the accompanying nREPL server via lein repl :connect localhost:<port>
I'm getting this error:
$ lein repl localhost:38875
Connecting to nREPL at localhost:38875
Syntax error (ClassNotFoundException) compiling at (form-init5283084375133054559.clj:1:82).
nrepl.core
#object[clojure.lang.Namespace 0x2d4efbbb "user"]
Error loading namespace; falling back to user
nil
user=>
What's happening here?
For reference, here's my project.clj file:
(defproject hello-compojure "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url ""
:min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.10.0"]
[org.clojure/tools.nrepl "0.2.13"]
[nrepl/drawbridge "0.2.1"]
[compojure "1.6.2"]
[ring/ring-defaults "0.3.2"]]
:plugins [[lein-ring "0.12.5"]]
:ring {:handler hello-compojure.handler/app
:nrepl {:start? true}}
:profiles
{:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
[ring/ring-mock "0.3.2"]]}})
can you create a git repo and push the whole project somewhere (eg github) and post a link to it?
To be fair, I literally just ran the default compojure template
But maybe I'm missing something here
Fixed
have you tried squinting your eyes and looking at the terminal with your head slightly turned away?
I mean, try doing a defroute
It's not being found is what i'm saying
so i think compojure isn't being loaded properly
so the sequence is: 0. lein ring server-headless
1. lein repl :connect localhost:PORT
? where does PORT come from? i was expecting to find it in the output of step 0
thanks
I'm thinking it could be an unresolved issue or something but my google-fu is failing me
Yes, but it just starts another nREPL server
The problem is that lein-ring
uses an older version of nREPL (`org.clojure/tools.nrepl "0.2.3"` per https://github.com/weavejester/lein-ring/blob/master/src/leiningen/ring/server.clj#L45) which is not compatible with modern nREPL (which is nrepl/nrepl "0.6.0"
at this point).
My advice: do not use lein-ring
. Learn to start your server via the -main
function and from a regular lein repl
.
(seriously, most of these plugins meant to "make life easier" just end up making life harder)
And it is compounded here because the compojure
template for Leiningen doesn't give you a proper "application" with a -main
function 😞
I see. Thanks @seancorfield
@signup867 Here's the Compojure template project updated with a proper -main
and updated project.clj
and handler.clj
files: https://github.com/seancorfield/hello-compojure
See the README for how to start a server from the REPL, and how to run the project without a REPL.
I removed lein-ring
, added the full ring/ring
dependency, added a :main
entry point (that's all project.clj
). In handler.clj
I added a -main
function.
The key is ring.adapter.jetty
and the run-jetty
function. Calling it with just {:port 3000}
will block -- until the server exits, i.e., until you kill the process. Calling it with {:port 3000 :join? false}
will kick off the server in a background thread.
See https://github.com/ring-clojure/ring/wiki/Getting-Started for some details about that.
Oh wow. Thank you so much @seancorfield!
I love this community so much
LMK if you have any Qs about the changes or the process.
You may also find https://github.com/seancorfield/usermanager-example helpful as a way to explore Compojure/Ring with Component, Selmer, and next.jdbc
to have a full but small web app with a database.
Worth mentioning here for everyone curious about REPL-Driven Development: Eric Normand has made two of the lessons in his excellent RDD course free for a short time (in addition to the overview which was always free): * https://purelyfunctional.tv/lesson/all-about-flow/ -- what is "flow" and why it is important * https://purelyfunctional.tv/lesson/a-map-of-the-repl-driven-development-territory/ -- a look at an idealized development workflow and how it maps onto RDD I highly recommend his paid course (there are several others that make it worth having a monthly membership, even if you only sign up for a month).
thanks for sharing this, Sean! this is the course i really wanted out of his subscription. would you recommend this particular course for one who already knows a thing or two about repl-aided development and already established a workflow of his own?
I'm probably going to take the three property-based testing courses at some point.
(making sure you have a smooth, fast REPL workflow is the best investment you can make in becoming an effective Clojure programmer)
I’ve edited my REPL session to make things simpler, so don’t mind the pointlessness of my code or usage of ->>
(->>
[132 132]
(reduce +)
(mod 11))
This produces 264 which. (mod 264 11) => 0
which is expected, but I was wondering if it were possible to use mod in the thread-last macro?
For instance, I can do:
(->>
[132 132]
(reduce +)
(= 264)) => true
But mod doesn’t seem to work that way. Is that truee?@skendrick366 Thread last would put 264 as last argument so you would end up with (mod 11 264)
You can use an anonymous function in the threading though: #(mod % 11)
I have a spec that uses a generator referred from another library for testing. Is there a simple way to disclude the generator from our production build (short of having a test-spec and prod-spec for the same entity) so that we can use spec for validation without having to pull in the generator's dependency?
you set the generator to be something like (fn [] ((resolving-require 'some.other.lib.namespace/generator))))
The latter.
the way I remember it is if the verb were require
, the thing to resolve
would be ambiguous or undecidable
when the verb is resolve
, the rest is trivial to determine
does anybody do tutoring here? I am confused about the build chain for a template.
I'm trying to work out how to wrap a common layout around page content using hiccup and don't understand what I'm doing wrong. A working example would really help, but I haven't found one yet. Here are stripped down versions of the handler functions.
(ns telo.request-handler
(:require [ring.util.response :refer [response]]
[hiccup.core :refer [html]]
[hiccup.page :refer [html5 include-js include-css]]
[hiccup.element :refer [link-to]])
(defn layout
[content]
(html5
[:head]
[:body
content
]))
(defn home
[request]
(response
(layout[(html [:div.container
[:h1.display3 "Hello there!"]])
])))
Here's the html this is returning, the intended content is missing:
<html><head></head><body><></></body></html>