Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure what does #' mean

Tags:

clojure

ring

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.

like image 776
Chris Edwards Avatar asked May 11 '16 09:05

Chris Edwards


1 Answers

#'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.

like image 195
Leon Grapenthin Avatar answered Nov 10 '22 05:11

Leon Grapenthin