August 2014
Intermediate to advanced
120 pages
2h 45m
English
The Clojure community loves lexical scoping, where the value of a symbol in an expression is solely determined by its placement in the code, not by its position on the call stack. That is, we like functions to accept arguments for each piece of data that may vary from one invocation to the next.
| context/circle_area_lexical.clj | |
| | (defn circle-area [radius] |
| | (* Math/PI (* radius radius))) |
| | |
| | (circle-area 10.0) |
| | ;=> 314.1592653589793 |
Here radius is a lexically scoped local variable: its value is determined solely by the argument passed into the function. That makes it easy to see at a glance what the dependencies are. Function parameters, along with let and loop bindings, are common examples of lexical binding.
Can you ...
Read now
Unlock full access