Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Metasyntactic variable
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Usage examples == [[File:Metasyntactic Variable FOO in Shell.png|thumb|A screenshot of a metasyntactic variable FOO assigned and echoed in an interactive shell session.]] ===C=== {{See also|C programming language}} 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++=== {{See also|C++}} Function prototypes with examples of different [[Parameter (computer programming)#Argument passing|argument passing]] mechanisms:<ref name="MonganKindler2012">{{cite book|first1=John|last1=Mongan|first2=Noah|last2=Kindler|first3=Eric|last3=Giguere|title=Programming Interviews Exposed: Secrets to Landing Your Next Job|url=https://books.google.com/books?id=GQE4r2e5fAsC&pg=PA242|year=2012|publisher=John Wiley & Sons|isbn=978-1-118-28720-0|page=242}}</ref> <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 (food)|Spam]], [[ham]], and [[Egg (food)|eggs]] are the principal metasyntactic variables used in the [[Python programming language]].<ref>{{Cite web|url=https://docs.python.org/3/tutorial/|title=The Python Tutorial β Python 3.8.1 documentation|website=docs.python.org}}</ref> This is a reference to the famous comedy sketch, "[[Spam (Monty Python)|Spam]]", by [[Monty Python]], the eponym of the language.<ref>{{Cite web |date=2021-09-04 |title=General Python FAQ β Python 3.9.7 documentation |url=https://docs.python.org/3/faq/general.html |url-status=live |archive-url=https://web.archive.org/web/20210826153036/https://docs.python.org/3/faq/general.html#why-is-it-called-python |archive-date=2021-08-26 |access-date=2021-09-05 |website=docs.python.org |publisher=Python Software Foundation |at=Why is it called Python?}}</ref> 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"> # Define a function named spam def spam(): # Define the variable ham ham = "Hello World!" # Define the variable eggs eggs = 1 return </syntaxhighlight> ===IETF Requests for Comments=== Both the [[IETF]] [[Request for Comments|RFC]]s and [[computer programming language]]s 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 [[Variable (programming)|variables]] in programming languages. These are specific names from a program, so @code is correct for them."<ref>{{cite web |url=http://sunsite.ualberta.ca/Documentation/Gnu/texinfo-4.0/html_chapter/texinfo_10.html |title=Marking Words and Phrases |work=Texinfo 4.0. The GNU Documentation Format|access-date=2012-11-25 |url-status=dead |archive-url=https://web.archive.org/web/20091106004856/http://sunsite.ualberta.ca/Documentation/Gnu/texinfo-4.0/html_chapter/texinfo_10.html |archive-date=2009-11-06 }}</ref>) 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.<ref name="Tennent2002">{{cite book|author=R. D. Tennent|title=Specifying Software: A Hands-On Introduction|year=2002|publisher=Cambridge University Press|isbn=978-0-521-00401-5|pages=36β37 and 210}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)