|
The macro instruction in computer science is an abstraction, whereby a certain textual pattern is replaced according to the defined placed of system. A interpreter or compiler automatically replaces the pattern after these are found. Inside compiled languages, macro-expansion universally happens at compile-instance. the convienence which performs a expansion is periodically known as a macro-expander. A term macro instruction is utilized within numerous similar contexts which from either a conception of macro-expansion, including keyboard macros and macro languages. Around virtually all situations, a utilise of the word "macro" implies expanding the microscopic command or even action into the big placed of videos.
A purpose of macro instruction is to either automate frequently-used sequences or enable a extra right abstraction — however which are actually typically a equivalent tool.
Languages like C and assembly language have simple macro systems, implemented when preprocessors to the compiler or even assembly program. Hundred preprocessor macro instruction function by elementary textual seek-&-replenish. Additional elaborate macro instruction come available to 100 computer programmer by utilizing even more, an extra text-processing language like M4.
Lisp languages such as Common Lisp and Scheme have more elaborate macro systems: around Lisp, macro instruction behave prefer functions transforming a program text itself, by owning a fully language available to express such transformations. Whereas a Hundred macro instruction instruction might define the elementary replacement of of these piece of syntax using an additional, the Lisp macro could control the evaluation of sections of code.
Existence a cappella to understand a choose of evaluation (see lazy evaluation and non-strict functions) enables the creation of recently syntactical constructs (e.g. control structures) indistinguishable from either people built into a language. E.g., around the Lisp idiom that has cond however deficiency in case, these are conceivable to define a latter around terms of the previous utilizing macro instruction. Entire major extensions to Lisp syntax, like a CLOS system for object-oriented programming, have been defined when macro instruction.
MacroML has typed syntax macro instruction, & 1 productive way to believe one syntax macros is as a multi-stage computation.
Programming macros
Whilst programming macro instruction instruction inside an unfamiliar macro language, it can be helpful to record a macro to clean what a user wants it to run, & so open a macro file and try to benefit an understanding of how else the command structure works. These are so conceivable to modify a commands to fine-tune it. A few macro languages, like Great Plains accounting software's Dexterity runtime engine, lack the ability to import information from either a second information source, like a comma delimited document. This limitation may be overcome by creating the program inside the extra right programing language, like VBA, to generate a specialised macro instruction in the weaker programing language. For example, the Microsoft Excel macro can be programmed to review information from either the spreadsheet or even document & produce a Great Plains .macintosh file designed to enter that specific information into Dandy Plains. The future .mack file would become required to exist as generated for both fresh placed of information.
Keyboard macros
Keyboard macro instruction & editor macro instructiin come utilized interactively on the graphical user interface and text editor, respectively. These allow short sequences of keystrokes to substitute yearn sequences of commands, & potty provide the elementary form of automation for repetitive tasks.
A computer programmer' text editor Emacs (short for "editing macros") follows this idethe to a guide. Effectively, virtually all of the editor is processed of macro instruction. Emacs was originally devised as a placed of macro instruction in the redaction language TECO; it was later ported to idiom of Lisp.
Macro languages
The macro language occurs as programing language where wholly or even virtually all computation is handle expanding macro instruction. Macro languages come non widely utilized for general-all-purpose programming, however are green around text processing applications. Examples:
C preprocessor
Internet Macro instruction (iOpus)
M4 (mentioned previously, originally from either AT&T, bundled with Unix)
PHP
SMX
Stage 2
Scripting languages such as Tcl and ECMAScript (a.k.the. ActionScript, DMDScript, JavaScript, JScript) have been embedded within applications thus that it behave such as macro languages.
TeX
Visual Basic Scripting (Microsoft)
Lisp has a right technique of unhygenic syntax macro instruction, however is prone to variable capture.
Scheme has hygenic syntax macro instruction sustaining a macros by lesson models, & is probably the virtually all advanced untyped macro models within most common apply.
MacroML is an experimental system that tries to reconcile static typing and macro systems.
Microsoft Word and macro viruses
Visual Basic for Applications (VBA), is a programing language around Microsoft Office. This is non, per above definition, the macro language the least bit. But, its work has evolved from either & replaced the idea of macro instruction within prevent-user applications, & so these are popularly and erroneously known as a macro language.
VBthe has access to numbers of operating formulas functions & supports automatic execution of macro instruction whenever a document is opened. This makes it imaginable to write computer viruses in this language. In the mid-to-late 1990s, macro viruses became one of the usual types of virus. More projects by using macro languages, like OpenOffice.org, have deliberately excluded certain functionality (eg: automatic execution) from their macro language so as to avoid susceptibility to this program. Even so, such features come popular among numerous businesses.
|