15.3 More Advanced Concepts
We discussed how a higher-order function can capture a pattern of recursion. If the function returned by a HOF at run-time accesses the environment in which it was created, it is called a lexical closure—a package that encapsulates an environment and an expression. Lexical closures resemble objects from object-oriented programming. Higher-order functions, the lexical closures they can return, and the style of programming both support and lead to the concept of macros—an operator that writes a program. While a higher-order function can return at run-time a function that was written before run-time, a macro can write a program at run-time. This style of programming is called metaprogramming. The homoiconic nature of ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access