A metasyntactic variable is a specific word or set of words identified as a placeholder in computer science and specifically computer programming. These words are commonly found in source code and are intended to be modified or substituted before real-world usage. For example, foo and bar are used in over 330 Internet Engineering Task Force Requests for Comments, the documents which define foundational internet technologies like HTTP (web), TCP/IP, and email protocols.

By mathematical analogy, a metasyntactic variable is a word that is a variable for other words, just as in algebra letters are used as variables for numbers. Two of these words, plugh and xyzzy, are taken from the game Colossal Cave Adventure.

A fuller reference can be found in The Hacker's Dictionary from MIT Press.

Japanese

In Japanese, the words (ほげ) and (ふが) are commonly used, with other common words and variants being (ぴよ), (ほげら), and (ほげほげ). The origin of as a metasyntactic variable is not known, but it is believed to date to the early 1980s.

Italian

In Italian software programming culture, it is common to encounter names of Walt Disney characters (as found in the Italian versions of the shows) being used as variables. These names often appear in pseudo-code, are referenced in software engineering classes, and are commonly employed when explaining algorithms to colleagues. Among the most frequently used are "pippo" (Goofy), "pluto", and "paperino" (Donald Duck).

Usage examples

thumb|A screenshot of a metasyntactic variable FOO assigned and echoed in an interactive shell session.

C

In the following example the function name <code>foo</code> and the variable name <code>bar</code> are both metasyntactic variables. Lines beginning with <code>//</code> are comments.

<syntaxhighlight lang="cpp">

// The function named foo

int foo(void)

{

// Declare the variable bar and set the value to 1

int bar = 1;

return bar;

}

</syntaxhighlight>

C++

Function prototypes with examples of different argument passing mechanisms:

<syntaxhighlight lang="cpp">

void Foo(Fruit bar);

void Foo(Fruit* bar);

void Foo(const Fruit& bar);

</syntaxhighlight>

Example showing the function overloading capabilities of the C++ language

<syntaxhighlight lang="cpp">

void Foo(int bar);

void Foo(int bar, int baz);

void Foo(int bar, int baz, int qux);

</syntaxhighlight>

Python

Spam, ham, and eggs are the principal metasyntactic variables used in the Python programming language. This is a reference to the famous comedy sketch, "Spam", by Monty Python, the eponym of the language.

In the following example <code>spam</code>, <code>ham</code>, and <code>eggs</code> are metasyntactic variables and lines beginning with <code>#</code> are comments.

<syntaxhighlight lang="python">

  1. Define a function named spam

def spam():

  1. Define the variable ham

ham = "Hello World!"

  1. Define the variable eggs

eggs = 1

return

</syntaxhighlight>

IETF Requests for Comments

Both the IETF RFCs and computer programming languages are rendered in plain text, making it necessary to distinguish metasyntactic variables by a naming convention, since it would not be obvious from context.

Here is an example from the official IETF document explaining the e-mail protocols (from RFC 772 - cited in RFC 3092):

All is well; now the recipients can be specified.

S: MRCP TO:<Foo@Y> <CRLF>

R: 200 OK

S: MRCP TO:<Raboof@Y> <CRLF>

R: 553 No such user here

S: MRCP TO:<bar@Y> <CRLF>

R: 200 OK

S: MRCP TO:<@Y,@X,fubar@Z> <CRLF>

R: 200 OK

Note that the failure of "Raboof" has no effect on the storage of

mail for "Foo", "bar" or the mail to be forwarded to "fubar@Z"

through host "X".

(The documentation for texinfo emphasizes the distinction between metavariables and mere variables used in a programming language being documented in some texinfo file as: "Use the @var command to indicate metasyntactic variables. A metasyntactic variable is something that stands for another piece of text. For example, you should use a metasyntactic variable in the documentation of a function to describe the arguments that are passed to that function. Do not use @var for the names of particular variables in programming languages. These are specific names from a program, so @code is correct for them.")

Another point reflected in the above example is the convention that a metavariable is to be uniformly substituted with the same instance in all its appearances in a given schema. This is in contrast with nonterminal symbols in formal grammars where the nonterminals on the right of a production can be substituted by different instances.

Example data

SQL

It is common to use the name ACME in example SQL databases and as a placeholder company-name for the purpose of teaching. The term 'ACME Database' is commonly used to mean a training or example-only set of database data used solely for training or testing.

ACME is also commonly used in documentation which shows SQL usage examples, a common practice with in many educational texts as well as technical documentation from companies such as Microsoft and Oracle.

See also

  • Metavariable (logic)
  • xyzzy
  • Alice and Bob
  • John Doe
  • Fnord
  • Free variables and bound variables
  • Gadget
  • Lorem ipsum
  • Nonce word
  • Placeholder name
  • Widget
  • Smurf

References

  • Definition of metasyntactic variable, with examples.
  • Examples of metasyntactic variables used in Commonwealth Hackish, such as wombat.
  • Variable "foo" and Other Programming Oddities