Sunday, 11 March 2012

Macro (computer science)

A macro (from the Greek μακρό for "big" or "far") in computer science is a aphorism or arrangement that specifies how a assertive ascribe arrangement (often a arrangement of characters) should be mapped to an achievement arrangement (also generally a arrangement of characters) according to a authentic procedure. The mapping action that instantiates (transforms) a macro into a specific achievement arrangement is accepted as macro expansion.

The appellation is acclimated to accomplish accessible to the programmer, a arrangement of accretion instructions as a distinct affairs statement, authoritative the programming assignment beneath annoying and beneath error-prone.12 (Thus, they are alleged "macros" because a big block of cipher can be broadcast from a baby arrangement of characters). Macros generally acquiesce positional or keyword ambit that behest what the codicillary assembler affairs generates and accept been acclimated to actualize absolute programs or affairs suites according to such variables as operating system, belvedere or added factors.

Keyboard and mouse macros

Keyboard macros and abrasion macros acquiesce abbreviate sequences of keystrokes and abrasion accomplishments to be adapted into other, usually added time-consuming, sequences of keystrokes and abrasion actions. In this way, frequently acclimated or repetitive sequences of keystrokes and abrasion movements can be automated. Separate programs for creating these macros are alleged macro recorders.

During the 1980s, macro programs – originally SmartKey, again SuperKey, KeyWorks, Prokey – were actual popular, aboriginal as a agency to automatically architecture screenplays, again for a array of user ascribe tasks. These programs were based on the TSR (Terminate and break resident) approach of operation and activated to all keyboard input, no bulk in which ambience it occurred. They accept to some admeasurement collapsed into obsolescence afterward the appearance of mouse-driven user interface and the availability of keyboard and abrasion macros in applications such as chat processors and spreadsheets, authoritative it accessible to actualize application-sensitive keyboard macros.

Keyboard macros accept in added contempo times appear to activity as a adjustment of base the abridgement of massively multiplayer online role-playing bold (MMORPG)s. By endlessly assuming a boring, repetitive, but low accident action, a amateur active a macro can acquire a ample bulk of the game's bill or resources. This aftereffect is alike beyond back a macro-using amateur operates assorted accounts simultaneously, or operates the accounts for a ample bulk of time anniversary day. As this money is generated after animal intervention, it can badly agitated the abridgement of the game. For this reason, use of macros is a abuse of the TOS or EULA of best MMORPGs, and administrators of MMORPGs action a around-the-clock war to analyze and abuse macro users.3

Text substitution macros

Languages such as C and accumulation accent accept abecedarian macro systems, implemented as preprocessors to the compiler or assembler. C preprocessor macros assignment by simple textual search-and-replace at the token, rather than the character, level. A archetypal use of macros is in the computer book arrangement TeX and its derivatives, area best of the functionality is based on macros. MacroML is an beginning arrangement that seeks to accommodate changeless accounting and macro systems. Nemerle has typed syntax macros, and one advantageous way to anticipate of these syntax macros is as a multi-stage computation. Other examples:

m4 is a sophisticated, stand-alone, macro processor.

TRAC

Macro Extension TAL, accompanying Template Attribute Language

SMX, for web pages

ML/1 Macro Accent One

The General Purpose Macroprocessor is a contextual arrangement analogous macro processor, which could be declared as a aggregate of approved expressions, EBNF and AWK

SAM76

minimac, a concatenative macro processor.

troff and nroff, for book and formatting Unix manpages.

Procedural macros

Macros in the PL/I accent are accounting in a subset of PL/I itself: the compiler executes "preprocessor statements" at accumulation time, and the achievement of this beheading forms allotment of the cipher that is compiled. The adeptness to use a accustomed procedural accent as the macro accent gives ability abundant greater than that of argument barter macros, at the amount of a beyond and slower compiler.

Frame Technology's anatomy macros accept their own command syntax but can additionally accommodate argument in any language. Each anatomy is both a all-encompassing basic in a bureaucracy of nested subassemblies, and a action for amalgam itself with its subassembly frames (a recursive action that resolves affiliation conflicts in favor of college akin subassemblies). The outputs are custom documents, about compilable antecedent modules. Anatomy Technology can abstain the admeasurement of agnate but cautiously altered components, an affair that has bedeviledcomputer application development back the apparatus of macros and subroutines.

Most accumulation languages accept beneath able procedural macro facilities, for archetype acceptance a block of cipher to be again N times for bend unrolling; but these accept a absolutely altered syntax from the absolute accumulation language.

Lisp / S-expression macros

Lisp's uniform, parenthesized syntax (known as S-Expressions) works abnormally able-bodied with macros. Languages of the Lisp family, such as Common Lisp, Clojure, Scheme, ISLISP and Racket, accept able macro systems because the syntax is simple abundant to be parsed easily, authoritative it accessible to attention programs as ascribe and achievement abstracts for affairs transformers. Lisp macros transform the affairs anatomy itself, with the abounding accent accessible to accurate such transformations.

The ancient Lisp macros took the anatomy of FEXPRs, function-like operators whose inputs were not the ethics computed by the arguments but rather the syntactic forms of the arguments, and whose achievement were syntactic bits to be acclimated in abode of the FEXPR's use.

In after Lisps, FEXPRs were replaced by DEFMACRO, a arrangement that accustomed programmers to specify source-to-source transformations that were activated afore the affairs is run.

In the mid-eighties, a cardinal of papers67 alien the angle of aseptic macro amplification (syntax-rules), a pattern-based arrangement area the syntactic environments of the macro analogue and the macro use are distinct, acceptance macro definers and users not to anguish about careless capricious abduction (cf. Referential transparency).

Macro systems accept a ambit of uses. Being able to accept the adjustment of appraisal (see apathetic appraisal and non-strict functions) enables the conception of fresh syntactic constructs (e.g. ascendancy structures) duplicate from those congenital into the language. For instance, in a Lisp accent that has cond but lacks if, it is accessible to ascertain the closing in agreement of the above appliance macros.

Next, macros accomplish it accessible to ascertain abstracts languages that are anon aggregate into code, which agency that constructs such as accompaniment machines can be implemented in a way that is both accustomed and efficient.8

Macros can additionally be acclimated to acquaint fresh bounden constructs. The best acclaimed archetype is the transformation of let into the appliance of a action to a set of arguments.

Felleisen conjectures9 that these three categories accomplish up the primary accepted uses of macros in such a system.

The Racket accent extends the angle of a macro arrangement to a syntactic tower, area macros can be accounting in languages including macros, appliance hygiene to ensure that syntactic layers are audible and acceptance modules to consign macros to added modules.

Macros for machine-independent software

Macros are commonly acclimated to map a abbreviate cord (macro invocation) to a best arrangement of instructions. Another, beneath common, use of macros is to do the reverse: to map a arrangement of instructions to a macro string. This was the access taken by the STAGE2 Mobile Programming System, which acclimated a abecedarian macro compiler (called SIMCMP) to map the specific apprenticeship set of a accustomed computer to analogue machine-independent macros. Applications (notably compilers) accounting in these machine-independent macros can again be run after change on any computer able with the abecedarian macro compiler. The aboriginal appliance run in such a ambience is a added adult and able macro compiler, accounting in the machine-independent macro language. This macro compiler is activated to itself, in a bootstrap fashion, to aftermath a aggregate and abundant added able adaptation of itself. The advantage of this access is that circuitous applications can be ported from one computer to a actual altered computer with actual little accomplishment (for anniversary ambition apparatus architecture, aloof the autograph of the abecedarian macro compiler).1011 The appearance of avant-garde programming languages, conspicuously C, for which compilers are accessible on around all computers, has rendered such an access superfluous. This was, however, one of the aboriginal instances (if not the first) of compiler bootstrapping.

Macro library

A macro library is a accumulating of macros. The library allows users to download activating macros that will assignment on any acceptable computer. By application the macros in the library, the user can automate activity on his computer. Disk defragmentation, virus scan, can be accomplished automatically.