- Metasyntactic variable
-
For the term as used in formal logic, see Metavariable (logic).
In computer science, programmers use metasyntactic variables to describe a placeholder name or an alias term commonly used to denote the subject matter under discussion or an arbitrary member of a class of things under discussion. The use of a metasyntactic variable is helpful in freeing a programmer from creating a logically named variable, which is often useful when creating or teaching examples of an algorithm. The word foo is the principal example.[1]
The term "metasyntactic variable" is primarily found in informal literature. It is sometimes also used as a synonym for metavariable.
Any symbol or word which does not violate the rules of the language can be used as a metasyntactic variable, but nonsense words are commonly used. The same concept is employed in other fields where it is expressed by terms such as schematic variable (see logical form).
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.[1]
Contents
Construction
- meta- means providing information about, or transcending,
- syntax denotes the grammatical arrangement of words or the grammatical rules of a programming language, and
- a variable is something that can assume a value, or something likely to vary.
So metasyntactic variable denotes a word that "transcends grammar and can assume a value" or one that is "more comprehensive than suggested by its grammatical arrangement and is likely to vary".
Words commonly used as metasyntactic variables
A "standard list of metasyntactic variables used in syntax examples" often used in the United States is: foo, bar, baz, qux, quux, corge, grault, garply, waldo, fred, plugh, xyzzy, thud.[1] The word foo occurs in over 330 RFCs and bar occurs in over 290.[2] Wibble, wobble, wubble, Fred and flob are often used in the UK.[3]
In standard, non-computerese English, the usual metasyntactic variables are: whatever, whoever, whenever, et cetera.
Japanese
In Japanese, the words hoge and pakeratta are commonly used, with other common words and variants being piyo, fuga, hogera, and hogehoge.[4] 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.[4]
Israeli Hebrew
In Hebrew, the words chupchick and stam are commonly used.
Italian
In Italian, the word pippo is commonly used. Strangely enough, besides being an abbreviation of the first name Filippo (Philip), pippo is the Italian name of the Disney character Goofy, but it is probably used just because of its sound which is quite strange.
Portuguese
In Portuguese, the words fulano, ciclano and beltrano are commonly used. These words have the constraint that they can only be used to refer to people.
Programming language examples
C
In the following example of the C programming language the function name foo and the variable name bar are both metasyntactic variables. Lines beginning with // are comments.
// The function named foo int foo(void) { // Declare the variable bar and set the value to 1 int bar = 1; return bar; }
Python
Spam, ham, and eggs are the principal metasyntactic variables used in the Python programming language.[5] This is a reference to the famous comedy sketch, Spam, by Monty Python, the eponym of the language.[6] In the following example spam, ham, and eggs are metasyntactic variables and lines beginning with # are comments.
# Define a function named spam def spam(): # define the variable ham ham = "Hello World!" #define the variable eggs eggs = 1 return
Ruby
In the following example the baz, foo, and bar are metasyntactic variables and lines beginning with # are comments.
# Declare the variable foo and set equal to 1 foo = 1 # Declare the variable bar and set equal to 2 bar = 2 # Declare the method (function) named baz, which prints the text 'Hello world' def baz puts 'Hello world' end
See also
- Metavariable (logic)
- Alice and Bob
- John Doe
- Fnord
- Free variables and bound variables
- Gadget
- Hello World
- Lorem Ipsum
- Nonce word
- Placeholder name
- Widget
References
- ^ a b c RFC 3092 (rfc3092) - Etymology of "Foo"
- ^ RFC-Editor.org
- ^ wibble. (n.d.). Jargon File 4.4.7. Retrieved February 23, 2010, from [1]
- ^ a b メタ構文変数 (Japanese)
- ^ Python Tutorial
- ^ General Python FAQ
External links
- Definition of metasyntactic variable, with examples.
- Examples of metasyntactic variables used in Commonwealth Hackish, such as wombat.
- Variable "foo" and Other Programming Oddities
Categories:- Placeholder names
- Metalogic
- Variable (computer programming)
- Logical syntax
Wikimedia Foundation. 2010.