The so-called macro is a series of commands that are organized together and used as a single command to complete a specific task; Microsoft Word defines macros as "A macro is a series of word commands that can be organized together and used as an independent command. , it makes everyday tasks easier”.
The operating environment of this tutorial: Windows 7 system, Dell G3 computer.
What is a macro
The so-called macro is a group of commands organized together to complete a specific task as a single command. The definition of macro in Microsoft Word is: "A macro is a series of word commands that can be organized together as an independent command to make daily work easier." Word uses the macro language Visual Basic to write macros as a series of instructions.
A macro in computer science is an abstraction that replaces a certain text pattern according to a series of predefined rules. The Excel office software automatically integrates the "VBA" high-level programming language, and the program compiled in this language is called a "macro". Using "VBA" requires a certain programming foundation and consumes a lot of time. Therefore, the vast majority of users only use the general tabulation function of Excel and rarely use "VBA".
The interpreter or compiler will automatically perform this pattern replacement when encountering a macro. For compiled languages, macro expansion occurs at compile time, and the tool that performs macro expansion is often called a macro expander. The term macro is often used in many similar contexts, derived from the concept of macro expansion, including keyboard macros and macro languages. Most of the time, the use of the word "macro" implies the conversion of small commands or actions into a series of instructions.
The purpose of macros is to automate frequently used sequences or to gain a more powerful abstraction capability - but this is often the same thing.
Computer languages such as C or assembly language have simple macro systems, which are implemented by the preprocessor of the compiler or assembler. The job of C's macro preprocessor is just simple text search and replacement. Using additional text processing languages such as M4, C programmers can obtain more sophisticated macros.
Lisp-like languages such as Common Lisp and Scheme have more sophisticated macro systems: macros behave like functions that transform their own program text, and all languages can be used to express this transformation. A C macro can define a grammatical replacement, but a Lisp macro can control the calculation of a section of code. Gained the ability to control the order of execution of code (see lazy evaluation and unrestricted functions), making newly created syntax constructs indistinguishable from the language's built-in syntax constructs.
For example, if a Lisp dialect has cond but not if, you can use macros to define the latter from the former. Major extensions to Lisp syntax, such as the object-oriented CLOS system, can be defined by macros.
Typical applications of macros
Speed up daily editing and formatting. Combine multiple commands to make options in dialog boxes more accessible and automate a range of complex tasks.
Applications can also use a system similar to macros to allow users to customize a series of (usually the most commonly used operations) into a step. That is, the user performs a series of operations and lets the application "remember" these operations and their order. More advanced users can directly access the functionality of those applications through built-in macro programming. When programming in an unfamiliar macro language, a more effective method is to record a series of operations that the user hopes to obtain, and then understand the structure of the macro commands by reading the macro file recorded by the application.
Recommended courses: PHP Tutorial.
The above is the detailed content of what is macro. For more information, please follow other related articles on the PHP Chinese website!