Go language self-rewriting program

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.

Unix/go, the father of the language, Ken Thompson, in the 1983 Turing Award speech Reflections on trusting Trust, gives a C-language self-rewriting program.

The shortest C-language self-rewriting program is the version of Vlad Taeerov and Rashit Fakhreyev:

main(a){printf(a="main(a){printf(a=%c%s%c,34,a,34);}",34,a,34);}

The following go language version of the self-rewriting program is provided by RSC:

/* Go quine */package mainimport "fmt"func main() {    fmt.Printf("%s%c%s%c\n", q, 0x60, q, 0x60)}var q = `/* Go quine */package mainimport "fmt"func main() {    fmt.Printf("%s%c%s%c\n", q, 0x60, q, 0x60)}var q = `

There are also shorter versions in Golang-nuts (Aram Hăvărneanu):

package main;func main(){print(c+"\x60"+c+"\x60")};var c=`package main;func main(){print(c+"\x60"+c+"\x60")};var c=`

In fact, the <[go language published in China. The 1.3 section of the Cloud Dynamics][8]> also gives a version (similar to the RSC).

For a variety of other languages of the self-rewriting program, you can refer to this site:

  • Http://www.nyx.net/~gthompso/quine.htm
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.