Jump to content

Macro (computer science): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
I added a type of macro in runescape.
CJHung (talk | contribs)
rv
Line 56: Line 56:


VBA has access to most operating system functions and supports automatic execution when a document is opened. This makes it relatively easy to write [[computer virus]]es in VBA, commonly known as ''[[Macro virus (computing)|macro virus]]es''. In the mid-to-late [[1990s]], this became one of the most common types of computer virus. Some applications with macro languages, such as [[OpenOffice.org]], deliberately exclude certain functionality (e.g.: automatic execution) to avoid such susceptibility. However, such features (in particular, automatic execution) remain popular in those applications that include them.
VBA has access to most operating system functions and supports automatic execution when a document is opened. This makes it relatively easy to write [[computer virus]]es in VBA, commonly known as ''[[Macro virus (computing)|macro virus]]es''. In the mid-to-late [[1990s]], this became one of the most common types of computer virus. Some applications with macro languages, such as [[OpenOffice.org]], deliberately exclude certain functionality (e.g.: automatic execution) to avoid such susceptibility. However, such features (in particular, automatic execution) remain popular in those applications that include them.

Runescape macros-
Players using illegal programs to cheat on runescape are called macrors. This applies to rule 7 of runescape.
Made by Randy Do of Runescape.




== See also ==
== See also ==

Revision as of 23:52, 19 March 2007

A macro in computer science is an abstraction, that defines how a certain input pattern is replaced by an output pattern according to a defined set of rules.

The term originated with macro-assemblers, where the idea was to write a single statement that appeared like an instruction in the assembly language (a macro-instruction). When the program was assembled, the macro-instruction was expanded into a sequence of real instructions that would then be assembled. In this way the complexity of the sequence of real instructions would be hidden, and the abstraction of the macro simplified coding and understanding code. Complex macro-assemblers offered sophisticated ways to add parameters to macros, so that the macro would expand in different ways according to the values of the parameters.

There are three broad categories of macros, and each takes a different kind of input pattern to produce a different kind of output pattern:

Programming macros are statements in a computer program which are replaced by a longer sequence of statements. Hence, this process is called macro-expansion and the tool that does this is called a macro-expander or a preprocessor. For many programming languages, a macro expander is included in the interpreter or compiler. These macros are typically used to enable a higher level of abstraction in programming languages. A classic use of macros is in the computer typesetting system TeX and its derivatives, where most of the functionality is based on macros (there is only a small set of built-in instructions which are not macros).

Keyboard macros and application macros take a simple command as input and then output a new expanded set of commands or instructions. These macros are typically used to automate frequently-used sequences or lists of keystrokes or mouse movements.

Programming languages

M4 language is a sophisticated, stand-alone, macro processor.

Languages such as C and assembly language have simple macro systems, implemented as preprocessors to the compiler or assembler. C preprocessor macros work by simple textual search-and-replace at the token, rather than the character, level.

Lisp languages such as Common Lisp and Scheme have more elaborate macro systems: in Lisp, macros behave like functions transforming the program's structure itself, with the full language available to express such transformations. Whereas a C macro may define a simple replacement of one piece of syntax with another, a Lisp macro can control the evaluation of sections of code.

Being able to choose the order of evaluation (see lazy evaluation and 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 cond but lacks if, it is possible to define the latter in terms of the former using macros. Entire major extensions to Lisp syntax, such as the Common Lisp Object System (CLOS), for object-oriented programming, have been defined as macros. Macros also make it possible to define data languages which are immediately compiled into code, which means that constructs such as state machines can be implemented in a way that is both natural and efficient.[1]

MacroML and Nemerle have typed syntax macros, and one productive way to think of these syntax macros is as a multi-stage computation.

Application macros

Application programs can also use an analogous system of macros, which allow the user to specify a series of (oft-repeated) actions as one new procedure. These application macros are generally recorded by carrying out the sequence once and letting the application "remember" the actions. More advanced users can often make use of a built-in macro programming language which has direct access to the features of the application.

When programming macros in an unfamiliar macro language, it may be helpful to record a macro to do what the user wants it to do, and then open the macro file and try to gain an understanding of how the command structure works. It is then possible to modify the commands to fine-tune it.

Keyboard and mouse macros

Keyboard and mouse macros or definitions allow short sequences of keystrokes or mouse actions to substitute long sequences of commands, and can automate repetitive tasks. They can be created either by using an application's built-in macro features, or by means of a separate macro recorder.

During the 1980s, macro programs -- originally SmartKey, then Superkey, KeyWorks, Prokey -- were very popular, first as a means to automatically format screenplays, then for a variety of business tasks. Since the 1990s, keyboard macros are built into most popular applications, such as word processors and spreadsheets, but are more difficult to use than the older macro programs, and require knowledge of

Keyboard macros have in more recent times come to life as a method of exploiting the economy of MMORPGs. By tirelessly performing a boring, repetitive, but low risk action, a player running a macro can earn a large amount of money. This effect is even larger when a macro-using player operates multiple accounts simultaneously, or operates the accounts for a large amount of time each day. As this money is generated without human intervention, it can dramatically upset the economy of the game by causing runaway inflation. For this reason, use of macros is universally a violation of the TOS or EULA, and administrators of MMORPGs fight a continual war to identify and punish macro users.

Macro languages

A macro language is a programming language in which all or most computation is done by expanding macros. Macro languages are not widely used for general-purpose programming, but are common in text processing applications. Examples:

Visual Basic Scripting (Microsoft Office) and OpenOffice.org Basic are commonly called "macros" but this is for historical reasons; they are not macro languages as defined in this article. Scripting languages such as Tcl and ECMAScript (a.k.a. ActionScript, DMDScript, JavaScript, JScript) have been embedded in applications and are sometimes called macro languages.

Visual Basic for Applications and macro viruses

Visual Basic for Applications (VBA) is a programming language included in Microsoft Office and some other applications. It is not, by the above definition, a macro language at all. However, its function has evolved from and replaced the macro languages which were originally included in some of these applications so it is popularly and mistakenly called a macro language.

VBA has access to most operating system functions and supports automatic execution when a document is opened. This makes it relatively easy to write computer viruses in VBA, commonly known as macro viruses. In the mid-to-late 1990s, this became one of the most common types of computer virus. Some applications with macro languages, such as OpenOffice.org, deliberately exclude certain functionality (e.g.: automatic execution) to avoid such susceptibility. However, such features (in particular, automatic execution) remain popular in those applications that include them.

See also