In some languages such as Common Lisp, Scheme and others of the Lisp language family, macros provide a powerful means of extending the language. Here the lack of hygiene in conventional macros is resolved by several strategies.
- If the programmer needs to use temporary storage during the expansion of a macro, he can use one with an unusual name and hope that the same name will never be used in a program that uses his macro. Of course any programmer knowing of gensym won't do this. (See next point)
- Temporary symbol creation
- In some programming languages, it is possible for a new variable name, or symbol, to be generated and bound to a temporary location. The language processing system ensures that this never clashes with another name or location in the execution environment. The responsibility for choosing to use this feature within the body of a macro definition is left to the programmer. This method was used in MacLisp, where a function named
gensymcould be used to generate a new symbol name. Similar functions (usually named
gensymas well) exist in many Lisp-like languages, including the widely implemented Common Lisp standard.
- Read-time Uninterned Symbol
- This is similar to the first solution in that a single name is shared by multiple expansions of the same macro. Unlike an unusual name, however, a read time uninterned symbol is used (denoted by the
#:notation), for which it is impossible to occur outside of the macro.
- Instead of an unusual name or an uninterned symbol, the macro simply uses a private symbol from the package in which the macro is defined. The symbol will not accidentally occur in user code. User code would have to reach inside the package using the double colon (
::) notation to give itself permission to use the private symbol, for instance
cool-macros::secret-sym. At that point, the issue of accidental lack of hygiene is moot. Thus the Lisp package system provide a viable, complete solution to the macro hygiene problem, which can be regarded as an instance of name clashing.
- Hygienic transformation
- The processor responsible for transforming the patterns of the input form into an output form detects symbol clashes and resolves them by temporarily changing the names of symbols. This kind of processing is supported by Scheme's
define-syntaxmacro creation systems. The basic strategy is to identify bindings in the macro definition and replace those names with gensyms, and to identify free variables in the macro definition and make sure those names are looked up in the scope of the macro definition instead of the scope where the macro was used.
Read more about this topic: Hygienic Macro
Other articles related to "strategies":
... Many strategies are involved in Spank Pankis, the most common being playing cards very fast ... More useful strategies such as layering, and save prevention are included ...
... is the President of 259 Strategies, LLC. 259 Strategies, LLC is a management consulting firm that provides development services, strategic advice, and technical assistance to non-profit organizations in Philadelphia, New York, and ...
... it is not available fresh from a local source is one approach some locavores include in their strategies ...
... The firm’s control strategies are characterized by its controlling or active participation in distressed companies and their restructurings require a long-term investment outlook ... MatlinPatterson’s liquid trading strategies seek to generate profits from changes in the price of securities or claims, with the firm remaining largely uninvolved in a restructuring process or distressed ... approximately $6 billion across 380 passive and active non-control strategies ...
... Not all eco-strategies can be incorporated into a company's Eco-portfolio immediately ... The widely practiced strategies include Innovation, Collaboration, Process Improvement and Sustainability reporting ...
Famous quotes containing the word strategies:
“By intervening in the Vietnamese struggle the United States was attempting to fit its global strategies into a world of hillocks and hamlets, to reduce its majestic concerns for the containment of communism and the security of the Free World to a dimension where governments rose and fell as a result of arguments between two colonels wives.”
—Frances Fitzgerald (b. 1940)