Neha Patil (Editor)

Metasyntactic variable

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

A metasyntactic variable is a meaningless word used as a placeholder in computer science, intended to be substituted by some objects pertaining to the context where it is used. The word foo as used in IETF Requests for Comments is a good example.

Contents

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.

"A standard convention is that any file with 'foo' in its name is temporary and can be deleted on sight." The names of these consecrated "metasyntactic variables" are also commonly used as actual identifiers (for variables, functions, etc.) in tutorial programming examples when their purpose is to emphasize syntax.

The term

The term metasyntactic variable is an amalgamation of three components:

  • meta, meaning providing information about, or transcending
  • syntactic, denoting the grammatical arrangement of words or the grammatical rules of a programming language
  • variable, something that can assume a value, or a thing likely to vary
  • Examples

    Both the IETF RFCs and computer programming languages are rendered in plain text, making it necessary to distinguish metasyntactic variables by a naming convention, more or less obvious from context. If rich text formatting is available, e.g. as in the HTML produced from texinfo sources, then a typographical convention may be used, as done for the example in the GNU Fortran manual:

    Plain text example:

    RFC 772 (cited in RFC 3092) contains for instance:

    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.

    A third example of the use of the "metasyntactic variables" foo and bar, this time as actual identifiers in a programming (interview) example is contrasting the following C++ function prototypes for their different argument passing mechanisms:

    English

    Metasyntactic variables used in the United States include foobar, foo, bar, baz, qux, quux, quuz, corge, grault, garply, waldo, fred, plugh, xyzzy, and thud. Wibble, wobble, wubble, and flob are used in the UK. And there are a reported blep, blah, and boop from Australia.

    Due to English being the foundation-language, or lingua franca, of most computer programming languages these variables are also commonly seen even in programs and examples of programs written for other spoken-language audiences.

    The typical names may depend however on the subculture that has developed around a given programming language. For example, spam, ham, and eggs are the principal metasyntactic variables used in the Python programming language. This is a reference to the comedy sketch Spam by Monty Python, the eponym of the language.

    The R programming language often adds norf to the list.

    Japanese

    In Japanese, the words hoge and piyo are commonly used, with other common words and variants being fuga, hogera, and hogehoge. Note that -ra is a pluralizing ending in Japanese, and reduplication is also used for pluralizing. The origin of hoge as a metasyntactic variable is not known, but it is believed to date to the early 1980s.

    Portuguese

    In Portuguese, the words fulano, sicrano and beltrano are commonly used to refer to people.

    Spanish

    In Spanish, the words fulano, mengano perengano, and zutano are commonly used, often followed by de tal ("of such"), mocking a lastname in Spanish form (e.g. Fulano de Tal).

    French

    In French, the words are toto and its derivatives, replacing o by other vowels: tata, titi, tutu... It may come from Toto who is the main character in many french jokes.

    References

    Metasyntactic variable Wikipedia