Log in Sign up
Back to Discover
💻

Macro (computer science)

technology Maturity 11-13 war conflict
This article covers sensitive topics: war_conflict. Parents can manage visibility in Parental Controls.

A macro is a special rule. It helps a computer do work. It can turn one small thing into a big job. This saves you a lot of time. It makes work easy.

Jedit macro recorder.png
Jedit macro recorder.png
Do you like to save time?

42 words

A macro is a special rule for computers. It turns a small input into a big output. This helps people do work faster.

Jedit macro recorder.png
Jedit macro recorder.png

Some macros record your mouse moves. They can also record your typing. This lets the computer repeat tasks for you. It makes hard work much easier.

Some macros use special parts. These parts can change how the rule works. This makes the rule even more powerful.

People use macros in many ways. Some use them to write code. Others use them in games. Using them can change how a game works.

Macros help make computer work less boring. They help people finish tasks without mistakes. It is a smart way to use a computer.

120 words

A macro is a rule for a computer. It tells the computer how to swap one thing for another. This swap is called macro expansion.

Jedit macro recorder.png
Jedit macro recorder.png

Macros can be very small. They can turn a tiny bit of text into a big block of code. This helps people write programs without making mistakes. It also makes the work less boring.

Some macros work with your keyboard and mouse. They can record your clicks and typing. Then, the computer can repeat those actions for you. This is called automation. People use these to do repetitive tasks quickly.

Some macros are even smarter. We call these parameterized macros. They can take in new information to change the result. For example, a macro might always swap the word PI for the number 3.14159. A smarter macro could change its answer based on what you give it.

In some online games, people use macros to do tasks without effort. This can change how the game economy works. Because of this, many games do not allow them. Most games have rules that say you must play by hand.

185 words

A macro is a special rule used in computer programming. It tells a computer how to swap a small input for a larger output. This process of swapping is called macro expansion.

Jedit macro recorder.png
Jedit macro recorder.png
When a programmer uses a macro, they turn a tiny bit of text into a big block of code. This makes the job of writing programs much easier. It also helps people avoid making mistakes. Because a small sequence of characters can grow into something huge, these rules are called "macros."

Macros work in many different ways depending on the software. Some macros are very simple and just swap text. For example, in the C programming language, a macro can swap the name PI for the number 3.14159. Other macros are more powerful and use parameters. A parameterized macro can take in new information to change its result. This allows the macro to act a bit like a function. In some languages like Lisp, these macros can even make decisions about what code to create.

Jedit macro recorder.png
Jedit macro recorder.png

People have used macros to automate many tasks over the years. Keyboard and mouse macros can record your clicks and typing. Then, the computer can replay those exact movements for you. This is helpful for repetitive work. In the 1980s, programs like SmartKey and SuperKey were very popular. They helped people format things like screenplays automatically. Today, many apps like word processors have these features built right in.

Jedit macro recorder.png
Jedit macro recorder.png

There is also a history of how these tools were made. In 1963, Timothy Hart proposed adding macros to the Lisp 1.5 language. This was a big step for how programmers could write code. Later, in the mid-1980s, researchers introduced the idea of hygienic macros. These are special because they prevent accidental errors when different parts of a program meet. Even text editors like Emacs are built mostly out of macros. Emacs was first made using a language called TECO before moving to Lisp.

Jedit macro recorder.png
Jedit macro recorder.png

While macros are helpful, they can sometimes cause problems. In some online games, players use macros to do repetitive tasks without any human effort. This can change how the game economy works, so many games forbid it. There are also macro viruses. These are bad programs written in languages like VBA that can hide in documents. In the mid-to-late 1990s, these were a very common type of computer virus. Today, companies like Microsoft use updates and anti-virus programs to stop them.

Jedit macro recorder.png
Jedit macro recorder.png

415 words

In computer science, a macro is a rule or a pattern. It specifies how a specific input should be mapped to a replacement output. This process of replacing the input with the output is known as macro expansion. The input and output can be many things. They might be a sequence of characters or lexical tokens. They can also be a syntax tree, which is a way of representing the structure of code. Macros are vital because they allow a programmer to turn a small sequence of characters into a big block of code. This makes programming tasks less tedious and helps prevent errors.

Jedit macro recorder.png
Jedit macro recorder.png

Macros work through a process of substitution. When a macro is triggered, the computer looks at the input and replaces it with the predefined output. Some macros are parameterless, meaning they always produce the exact same result. For example, in the C programming language, a macro might replace the name PI with the number 3.14159. Other macros are parameterized, which means they can take in specific arguments to change their output. This gives them power similar to a mathematical function. In the C language, a macro like pred(x) can take a value for x and subtract 1 from it. The final result depends entirely on what argument is passed to the macro.

There are several different types of macro systems used in computing. Text-substitution macros work at a basic level by swapping text. Languages like C and some assembly languages use these through a tool called a preprocessor. Syntactic macros are more advanced. They work at the level of abstract syntax trees rather than just simple text. This allows them to preserve the actual structure of the program more reliably. This style is very common in Lisp-like languages. These languages use a uniform, parenthesized syntax called S-expressions. This structure makes it easier for the computer to identify where a macro is being used.

Another important type is the procedural macro. In the PL/I language, these are written using a subset of the language itself. The compiler runs these statements during the compilation process. This creates a very powerful tool, though it can make the compiler larger and slower. Some macros are also designed to be "hygienic." This concept was introduced in papers during the mid-1980s. Hygienic macros use a pattern-based system to keep different parts of a program separate. This prevents "variable capture," which is when a macro accidentally interferes with a variable name used in the main program. This is now a standard feature in the Scheme programming language.

History shows how macros have evolved alongside computing. The term "macro" comes from "macro instruction." These were originally used to generate assembly language code. In 1963, Timothy Hart proposed adding macros to Lisp 1.5. This helped move the language toward more complex capabilities. In the 1980s, separate programs like SmartKey and SuperKey became very popular. These were used to automate keyboard and mouse actions. They could even format screenplays automatically. Later, as mouse-driven interfaces became common, these standalone programs mostly disappeared. Instead, macro features were built directly into applications like word processors and spreadsheets.

Macros are used in many famous software tools. The Emacs text editor is a major example. In fact, most of Emacs is actually made of macros. It was originally created using a language called TECO before being moved to Lisp. Another editor, Vim, allows users to record keyboard macros into a "register." These can then be replayed or edited. Microsoft Office also uses a language called Visual Basic for Applications, or VBA. VBA is very powerful because it can access many Windows system calls. However, this power also led to the rise of macro viruses in the mid-to-late 1990s. These viruses hide in documents and execute when the file is opened. Today, Microsoft uses updates and anti-virus software to stop these attacks.

Beyond programming, macros have a significant impact on digital environments. In massively multiplayer online role-playing games, or MMORPGs, players sometimes use keyboard macros. They use them to perform repetitive tasks to collect resources without human effort. This can actually hurt the game's economy. Because of this, most games list macro use as a violation of their terms of service. In the world of typesetting, the TeX system relies heavily on macros to function. Even the way we read manual pages on Unix systems often involves macro languages like troff or nroff. From small text swaps to building entire software suites, macros remain a fundamental tool in computing.

750 words
🖼️ Images & Media (1)
File:Jedit macro recorder.png
Jedit macro recorder.png
Up Next
💻
Function (computer programming)
Technology
More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.