What might quine look like in my programming language?

I created a ready-made programming language (already proven), so it should be possible to write quine for it , right?

But all the quines that I know store the source code in a string, and then replace the special character in it, using something like chr and ord .

My tongue has only

  • Basic arithmetic
  • Int and string types
  • Variables
  • == operator
  • Conditional jumps

I have no idea how I can write quine, since I have no real string manipulations , I can only output constant strings. However, it is 100% complete.

+4
source share
3 answers

If you have integers, you can encode or decode strings (simple schemes are enough for this: A = 1, B = 2, etc.). You only need to be able to compare constant strings or compare int. Therefore, there is no fundamental problem.

You work with numbers and write things like

 if (n == 1) print "A" if (n == 2) print "B" ... 

There may be some practical difficulties. The thing with strings is not that you have characters, but that they are equivalent to very large numbers. Here you need to either access unlimited precision numbers, or some array of fixed numbers or another large data structure. An array of numbers will do for you what a string can do. But if your language is the completion of Turing, it should have a way to easily access a large chunk of memory.

The full text of Turing, limited to 32-bit tape (or where you must specify a new name for each different 32-bit memory space), would be unfortunate, not sure if you could write quine with such a restriction. By the way, it would be interesting to know how you proved that your language was Turing complete if you do not have arrays or a similar structure. The usual method that I usually use is to implement some Turing machine using my language. But for this I need some kind of array to simulate the strip.

This type of coding is basically what GΓΆdel made in him a theorem of incomplete information, to find a way to code logical expressions as integers, and then talk about it.

If you give a few more syntax elements, we could even try to do it (if you have no functions, but only gotos, this will also be a problem, but you can also imitate this). The main problem is that you need to find a way to "compress" your encoded source code. If you have a long string constant, it can help.

+2
source

If your Turing language is complete and there is one question, most likely there are infinitely many of them. Here you can build only a few of them:

  • Deploy Brainfuck (or some other simple Turing translator) in your language. Write your program in such a way that the source X1<brainfuck source>Y1 at startup interprets the Brainfuck program.
  • Write the algorithm string f(string a, string b) in any language of your choice, which, when you specify any a and b displays the Brainfuck program, which, when launched, displays the string a , all the source code for Brainfuck, then the string b . You can adapt your existing Brainfuck Kane for this.
  • Calculate f(X1, Y1) , and then paste the resulting Brainfuck program into your program from 1.

The step is one the most difficult, but you may have already done it, because one of the easiest ways to prove that something is the completion of Turing is to introduce an interpreter for another language that has already proved that it is complete. p>

Step 2, as it turned out, is already possible and does not depend on your programming language.

The third step is a simple calculation.

+3
source

Apparently, a program in your programming language is a line. The quine output file is a program.

Therefore, quine output is a string. If you do not have any string manipulations, it is impossible to write them.

You must either encode your program in numbers (instead of a simple encoding taking into account humane text), or implement string manipulation.

0
source

Source: https://habr.com/ru/post/1306625/


All Articles