User:Kf4yfd/msv
In computer programming, a metasyntactic variable is a variable whose name is arbitrary and subject to change at the discretion of the programmer. This is in contrast to a metavariable, whose name is unchangable within the given programming language.
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]
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]
Etymology
[edit]- 'Meta' means providing information about, or transcending.
- 'Syntax' means the grammatical arrangement of words or the grammatical rules of a programming language.
- 'Variable' means something that can assume a value, or something likely to vary.
So we have a word that
- transcends grammar and can assume a value
or one that
- is more comprehensive than grammatical arrangement and is likely to vary.
Words commonly used as metasyntactic variables
[edit]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 and flob are often used in the UK.[3]
Programming language examples
[edit]The C programming language: In the following example 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;
}
The Python programming language:
Spam, ham, and eggs are the principal metasyntactic variables used in the Python programming language.[4] This is a reference to the famous comedy sketch, Spam, by Monty Python, the eponym of the language.[5]
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
The Ruby programming language: 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
[edit]- Alice and Bob
- John Doe
- Fnord
- Free variables and bound variables
- gadget
- Hello World
- Lorem Ipsum
- Placeholder name
- Widget
References
[edit]- ^ 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]
- ^ Python Tutorial
- ^ General Python FAQ
External links
[edit]- Definition of metasyntactic variable, with examples.
- Examples of metasyntactic variables used in Commonwealth Hackish, such as wombat.
- Variable "foo" and Other Programming Oddities