This is a variant on the self-replicating program, defined here as a program that outputs its source (or a quine). Below is an example of a self-replicating program in Python:
s = 's = %r\nprint(s%%s)'
print(s%s)
When run from a file, this script should output itself.
Instead of a self-replicating program, I want you to write a mutating, replicating program. This is a program that outputs something similar to its source, but with a mutation. The mutated source must also be able to replicate, but it should change the functionality of the program in some way. Here is an example:
s = 's = %r\ns = s.replace(s[-17],str(int(s[-17])+222))\nprint(s%%s)'
s = s.replace(s[-17],str(int(s[-17])+222))
print(s%s)
When this Python script is run, it outputs the following program:
s = 's = %r\ns = s.replace(s[-17],str(int(s[-17])+224224224))\nprint(s%%s)'
s = s.replace(s[-17],str(int(s[-17])+224224224))
print(s%s)
If you repeat a number of times, you will see that it continues to mutate but remain functional.
Incorporating a raw dynamic environment variable in your code, like a comment with a timestamp, is boring. Don't do that.
Edit: For that matter, let's follow the standard quine rule of no input.
This is code-golf so the shortest in bytes wins.
Clarifications: I've been asked to clarify, but without much information I'm not sure what needs clarifying. Here's my best shot:
- Each iteration should have source code that is different from the last.
- The iteration must still run.
- The iteration must still replicate according to the same rules.
- Comments or strings can't be the only thing that changes. In dzaima's answer the operations on the string are duplicated, not just the contents of the string--so that is valid.
- Each iteration must be runnable in the same language you started in.