Navigation
  • Home
  • Recent
  • Most Active
  • Popular
  • Blog
  • Credits
  • RSS
  •   Interaction
  • Register
  • Statistics
  •   Help
  • Suggestions
  • Contact Us
  • How to Edit
  • Help



  • [Edit]


    In computing, a quine is a program (a form of metaprogram) that produces its complete source code as its only output. For amusement, programmers sometimes attempt to develop the shortest possible quine in any given programming language.
    Note that programs which take input are not considered quines. This would allow the source code to be fed to the program via keyboard input, opening the source file of the program, and similar mechanisms. Also, a quine which contains no code is ruled out as trivial; in many programming languages executing such a program will output the code (i.e. nothing). Such an empty program once won the "worst abuse of the rules" prize in the Obfuscated C contest.

    Quines are named after philosopher Willard Van Orman Quine (1908–2000), who made an extensive study of indirect self-reference. He coined, among others, the following paradox-producing expression, known as Quine's paradox: "'Yields falsehood when preceded by its quotation' yields falsehood when preceded by its quotation."


        Quine (computing)
            History
            Examples
                C programming language|C
                Scheme programming language|Scheme (also correct Common Lisp)
                JavaScript
            Philosophical usage
            See also
            Further reading

    top

    History
    A quine exists in any programming language with the ability to output any computable string, as a direct consequence of Kleene's recursion theorem. The specific idea of quines first appeared in Bratley, Paul and Jean Millo. "Computer Recreations; Self-Reproducing Automata", Software -- Practice & Experience, Vol. 2 (1972). pp. 397-400. Bratley first became interested in self-reproducing programs after seeing the first known such program written in Atlas Autocode at Edinburgh in the 1960s by the University of Edinburgh lecturer and researcher Hamish Dewar. This program appears below:

    %BEGIN
    !THIS IS A SELF-REPRODUCING PROGRAM
    %ROUTINESPEC R
    R
    PRINT SYMBOL(39)
    R
    PRINT SYMBOL(39)
    NEWLINE
    %CAPTION %END~
    %CAPTION %ENDOFPROGRAM~
    %ROUTINE R
    %PRINTTEXT '
    %BEGIN
    !THIS IS A SELF-REPRODUCING PROGRAM
    %ROUTINESPEC R
    R
    PRINT SYMBOL(39)
    R
    PRINT SYMBOL(39)
    NEWLINE
    %CAPTION %END~
    %CAPTION %ENDOFPROGRAM~
    %ROUTINE R
    %PRINTTEXT '
    %END
    %ENDOFPROGRAM

    top

    Examples

    top

    C programming language|C

    /
      A simple quine (self-printing program), in standard C.
        /

    /
      Note: in designing this quine, we have tried to make the code clear
      and readable, not concise and obscure as many quines are, so that
      the general principle can be made clear at the expense of length.
      In a nutshell: use the same data structure (called "progdata"
      below) to output the program code (which it represents) and its own
      textual representation.
        /

      include

    void quote(const char
      s)
    /
      This function takes a character string s and prints the
      textual representation of s as it might appear formatted in C
      code.
        /


    /
      What follows is a string representation of the program code, from
      beginning to end (formated as per quote() function, above), except
      that the string _itself_ is coded as two consecutive '@'
      characters.
        /
    const char progdata =
    "/
      A simple quine (self-printing program), in st"
    "andard C.
      /

    /
      Note: in designing this quine, "
    "we have tried to make the code clear
      and read"
    "able, not concise and obscure as many quines are"
    ", so that
      the general principle can be made c"
    "lear at the expense of length.
      In a nutshell:"
    " use the same data structure (called "progdata"
    "
    "
      below) to output the program code (which it r"
    "epresents) and its own
      textual representation"
    ".
      /

      include

    void quote(const char "
    "
      s)
    /
      This function takes a character stri"
    "ng s and prints the
      textual representati"
    "on of s as it might appear formatted in C
    "
    "
      code.
        /


    /
      What "
    "follows is a string representation of the progra"
    "m code, from
      beginning to end (formated as pe"
    "r quote() function, above), except
      that the s"
    "tring _itself_ is coded as two consecutive '@'
    "
    "
      characters.
        /
    const char progdata =
    @@;

    in"
    "t main(void)
    /
      The program itself...
        /

    ";

    int main(void)
    /
      The program itself...
        /


    top

    Scheme programming language|Scheme (also correct Common Lisp)
    ((lambda (x)
    (list x (list (quote quote) x)))
    (quote
    (lambda (x)
    (list x (list (quote quote) x)))))

    top

    JavaScript
    function a()
    a();


    top

    Philosophical usage
    In the satirical dictionary The Philosophical Lexicon, the word was used in jest to mean "To deny resolutely the existence or importance of something real or significant." Since then, the word has been used seriously in many papers to denote the proposed elimination (or reduction) of a thing or concept.

    top

    See also

    top

    Further reading
     
    Search more:
     

       
    Source Privacy License Download Contact Us Atlas
    Scientus.org Dictionary (Yet Another Wiki) RC : 1.39
    This article is licensed under the GNU Free Documentation License [copyleft]. It uses material from the Wikipedia article "Quine (computing)". link