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