Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6634801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:58:21+00:00 2026-05-25T22:58:21+00:00

A Clojure-based project of mine uses the netty (required by aleph ) web server.

  • 0

A Clojure-based project of mine uses the netty (required by aleph) web server. I start the server, along with other components, in a web.clj file like this:

(ns myproject.web)

(def server (atom nil))

(defn initialize []
  (if @server
    (println "Warning: already initialized")
    (let [port 8001]
      (println (format "Starting http://localhost:%s/" port))
      (swap! server (fn [_] (start-http-server
                             (wrap-ring-handler app-routes)
                             {:port port}))))))

(defn shutdown []
  (when @server
    (do
      (println "Shutting down web server")
      (@server)
      (swap! server (fn [_] nil)))))

(defn reinitialize []
  "Run this on the REPL to reload web.clj and restart the web server"
  (myproject.web/shutdown)
  (use :reload-all 'myproject.web)
  (myproject.web/initialize))

The server instance is stored in a Clojure atom, so that it can be stopped later.

I use Emacs and Swank to directly launch the server on the REPL like this (after compiling web.clj with C-c C-k):

user> (myproject.web/initialize)

Whenever web.clj or other dependent modules are edited, I must

  1. remember NOT to recompile web.clj using C-c C-k because the atom holding the running instance would vanish (due to the atom from a newly compiled module) from the REPL.

  2. Run (myproject.web/reinitialize) which stops the server and then reloads the module before starting it again.

There are two problems with this:

  • Often I forget point #1 and press C-c C-k anyway. This causes the loss of server atom in REPL, leading to having to kill swank (or restart emacs) so that I can start the server at the same port number.

  • :reload-all doesn’t report compile errors as friendly as C-c C-k (ugly traceback vs concise clickable errors).

How can I best address these two problems in this edit-compile-restart workflow?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:58:21+00:00Added an answer on May 25, 2026 at 10:58 pm

    You can replace

    (def server (atom nil))
    

    with

    (defonce server (atom nil))
    

    that way when you evaluate the buffer it will not redefine server.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a big project that involves a lot of web based
I am developing a pet project with Clojure, but wonder if I can speed
Has anyone tried implementing a web application with Clojure ( using Compojure ) and
Based on the Embedding section of http://github.com/technomancy/swank-clojure , I'm using the following to test
In clojure 1.2RC1, I wish to obtain a function based on its name as
Context: I have a clojure-based crossword app whose main ui is a JTabbedPane with
I work on a large Java based web application, it has been built up
I am working on a Clojure macro to help build GridBagLayout-based JPanels. I can
I have a plain project structure: Base Dir src ;; Pile of Clojure files
I'm trying to create a text based Clojure game (inspired by Land of Lisp).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.