Clojure what does #' mean
Asked Answered
G

1

7

I am following this tutorial building a Clojure backend and I'm not exactly well versed in Clojure.

The tutorial provides this source file

(ns shouter.web
  (:require [compojure.core :refer [defroutes GET]]
            [ring.adapter.jetty :as ring]))

(defroutes routes
  (GET "/" [] "<h2>Hello World</h2>"))

(defn -main []
  (ring/run-jetty #'routes {:port 8080 :join? false}))

what exactly does the #' mean? I know somehow it's getting the value of routes but why can you not just say

(ring/run-jetty routes {:port 8080 :join? false}))

Is the #' a ring specific syntax? Couldn't find any good resources on the matter.

Girt answered 11/5, 2016 at 9:9 Comment(1)
See #10945687Mccomas
I
7

#'sym expands to (var sym).

A var can be used interchangeably as the function bound to it. However, invoking a var resolves the defined function dynamically and then invokes it.

In this case it serves development purposes: Instead of passing the handler function routes by value, the var it is bound to is passed so that Jetty does not have to be restarted after you change and re-evaluate shouter.web/routes.

Insula answered 11/5, 2016 at 9:12 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.