Skip to content

Instantly share code, notes, and snippets.

@xumingming
Last active December 11, 2015 17:08
Show Gist options
  • Save xumingming/4631933 to your computer and use it in GitHub Desktop.
Save xumingming/4631933 to your computer and use it in GitHub Desktop.
How ring's autoload works?
<rationalrevolt> With ring, can some one help me understand why passing a var
to run-jetty allows me to reload code and have it reflect
immediately? (run-jetty #'handler {:port 8080 :join? false})
[12:58]
<nDuff> rationalrevolt: passing the var object means it's involved in the
lookup, and can be substituted/replaced. [12:59]
*** bobbrahms1 (~Adium@pool-71-251-206-14.nwrknj.fios.verizon.net) has joined
channel #clojure [13:01]
*** bobbrahms (~Adium@pool-71-251-206-14.nwrknj.fios.verizon.net) has quit:
Read error: Connection reset by peer
<tomoj> &(#'+ 1 2)
<lazybot> ⇒ 3
*** mattmoss (~mattmoss@71.11.98.68) has quit: Ping timeout: 244 seconds
[13:02]
<rationalrevolt> Doing (+ 1 2) or (#'+ 1 2) gives the same result - but, i'm
not seeing whats different
<rationalrevolt> (+ 1 2) would look up the symbol to obtain the var and then
invoke it with the arguments [13:03]
*** mudphone (~koba@72.234.205.107) has joined channel #clojure
*** ecmendenhall (~connormen@ip70-162-229-226.ph.ph.cox.net) has quit: Quit:
ecmendenhall [13:04]
*** mattmoss (~mattmoss@71.11.98.68) has joined channel #clojure
*** kofno (~kofno@cpe-24-165-210-251.neo.res.rr.com) has joined channel
#clojure
<tomoj> yes, but if you do e.g. (run-jetty handler ...), handler is resolved
to #'handler, but the var's value, your handler fn, is passed to
run-jetty
<tomoj> if you redef #'handler later, run-jetty will still have the old fn
<rationalrevolt> (#'+ 1 2) expands to ((var +) 1 2) and (var +) is doing a
lookup of + each time (#'+ 1 2) is eval'd - is this correct?
[13:05]
*** reiddraper (~reid@c-66-31-46-203.hsd1.ma.comcast.net) has joined channel
#clojure
*** kofno (~kofno@cpe-24-165-210-251.neo.res.rr.com) has quit: Read error:
Connection reset by peer
*** kofno (~kofno@cpe-24-165-210-251.neo.res.rr.com) has joined channel
#clojure [13:06]
<tomoj> when you (run-jetty #'handler ...), the thing passed to run-jetty is
the var, not the fn it points to. when the var is invoked as a
function it just invokes whichever fn the var currently points to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment