Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Macro (computer science)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Applications === ; Evaluation order :Macro systems have a range of uses. Being able to choose the order of evaluation (see [[lazy evaluation]] and [[Strict function|non-strict functions]]) enables the creation of new syntactic constructs (e.g. [[control structures]]) indistinguishable from those built into the language. For instance, in a Lisp dialect that has <CODE>cond</CODE> but lacks <CODE>if</CODE>, it is possible to define the latter in terms of the former using macros. For example, Scheme has both [[continuation]]s and hygienic macros, which enables a programmer to design their own control abstractions, such as looping and early exit constructs, without the need to build them into the language. ; Data sub-languages and domain-specific languages : Next, macros make it possible to define data languages that are immediately compiled into code, which means that constructs such as [[state machine]]s can be implemented in a way that is both natural and efficient.<ref>{{cite web|url=http://cs.brown.edu/~sk/Publications/Papers/Published/sk-automata-macros/|title=Automata via Macros|website=cs.brown.edu}}</ref> ; Binding constructs :Macros can also be used to introduce new binding constructs. The most well-known example is the transformation of <CODE>let</CODE> into the application of a function to a set of arguments. [[Matthias Felleisen|Felleisen]] conjectures<ref name="three-uses">[http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg01539.html], Matthias Felleisen, LL1 mailing list posting</ref> that these three categories make up the primary legitimate uses of macros in such a system. Others have proposed alternative uses of macros, such as [[anaphoric macro]]s in macro systems that are unhygienic or allow selective unhygienic transformation. The interaction of macros and other language features has been a productive area of research. For example, [[Software component|component]]s and [[Modular programming|module]]s are useful for large-scale programming, but the interaction of macros and these other constructs must be defined for their use together. Module and component-systems that can interact with macros have been proposed for Scheme and other languages with macros. For example, the [[Racket (programming language)|Racket]] language extends the notion of a macro system to a syntactic tower, where macros can be written in languages including macros, using hygiene to ensure that syntactic layers are distinct and allowing modules to export macros to other modules.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)