Clojure which means # '

I follow this guide to build a Clojure backend and I am not very good at 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 #' mean? I somehow know the meaning of routes , but why can't you just say

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

Is #' symbolic syntax? Could not find good resources on this.

+5
source share
1 answer

#'sym expands to (var sym) .

A var can be used interchangeably as a function associated with it. However, by calling var, it dynamically resolves a specific function and then calls it.

In this case, it serves development purposes. Instead of passing the routes handler function by value, the variable with which it is associated is passed so that Jetty does not need to be restarted after changing and re-evaluating shouter.web/routes .

+6
source

All Articles