Is it possible to create a quine in every turing-complete language?

后端 未结 4 903
清歌不尽
清歌不尽 2020-12-24 12:31

I just wanted to know if it is 100% possible, if my language is turing-complete, to write a program in it that prints itself out (of course not using a file reading function

4条回答
  •  清歌不尽
    2020-12-24 12:51

    Well, technically, not always. According to the proof on Wikipedia, the programming language has to be an admissible numbering. Practical and sane Turing-complate programming languages are all admissible numberings. And a Turing-complate programming language is an admissible numbering if it's possible to translate between that and another admissible numbering.

    An example Turing-complete programming language that is not an admissible numbering:

    The source code always contains one or two doublequoted escaped strings. If the input is empty, output the first string if there are two strings, or loop forever if there is one. Otherwise, evaluate the last string in Python, using the original input as input.

    It's not an admissible numbering because, given a Python program, we have to know its behavior when the input is empty, to translate it into this language. But we may never know if it is an infinite loop, as we cannot solve the halting problem. We know a translation always exists, though.

    It's impossible to write quines in this language.

提交回复
热议问题