DEV Community

Cover image for Intron: Junk or not Junk, that is the quine-tion
Darshan A S
Darshan A S

Posted on • Updated on • Originally published at darshan.hashnode.dev

Intron: Junk or not Junk, that is the quine-tion

Last time, we cracked the code of Quines, those clever programs that echo their own source code. We crafted them with surgical precision, including only the bare essentials for self-replication.

But here's a question: Can we sneak in some extra, even useless, bits of data into an existing Quine without breaking it?

Enter the world of Introns, those sneaky bits of data that can hitch a ride within a Quine. Just like the non-coding regions of DNA in biology, these introns are extra passengers that don't directly contribute to the Quine's function, but they get copied along for the ride nonetheless.

In the world of biology, Introns are often called "Junk DNA". Only ~2.5% of the genome encodes sequences that make proteins. The functions for the remaining >90% of our genome is not well understood, but seem to play a crucial role in evolution and gene regulation.

"Introns are the dark matter of the eukaryotic genome."

Similarly, in the world of programming, introns might seem like a useless thing to do, but the possible existence of introns will be the key feature in making QuineRelays and MultiQuines possible. (some things we will talk about in the upcoming posts)


Writing your own Intron

Let's take our Python Quine from last time and see how to inject an intron.

Original Python Quine: Try it online!

data = "print('data =', repr(data)); print(data)"
print('data =', repr(data)); print(data)
Enter fullscreen mode Exit fullscreen mode

Let's introduce a variable called intron and set it to a seemingly junk string, such as 'wubbalubbadubdub'. We'll add it to the data portion of our Quine.

Python:

intron = 'wubbalubbadubdub'
data = "print('data =', repr(data)); print(data)"
print('data =', repr(data)); print(data)
Enter fullscreen mode Exit fullscreen mode

To maintain the Quine's integrity, we need to mirror this addition in the code portion. We'll use the repr(intron) technique to ensure the intron is replicated accurately
Python:

intron = 'wubbalubbadubdub'
data = "print('data =', repr(data)); print(data)"
print('intron =', repr(intron)); print('data =', repr(data)); print(data)
Enter fullscreen mode Exit fullscreen mode

Finally, we update the data variable to hold the latest code section.
Python: Try it online!

intron = 'wubbalubbadubdub'
data = "print('intron =', repr(intron)); print('data =', repr(data)); print(data)"
print('intron =', repr(intron)); print('data =', repr(data)); print(data)
Enter fullscreen mode Exit fullscreen mode

It's still a valid Quine. And now it's an IntronQuine!


Imagine a year with only ten months! That's how the Romans initially rolled, with January and February being late additions to the party. Romans were also the reason we have the seemingly random leap days thrown around every few years. And to top it all off, did you know that in 1752, India skipped 11 whole days from its calendar?


Run the above IntronQuine and notice how the value of the intron variable is faithfully reproduced in the output. Try setting intron = 'your name here' The program will still work flawlessly, replicating itself along with your custom message.

The key takeaway is that, quite obviously, an intron can be modified with great ease without breaking the existing Quine; it is a kind of subliminal information that is reproduced with the Quine, although it is not necessary to the Quine. You can change the value of the variable intron to any arbitrary string (as long as it's syntactically right) and the program continues to be a Quine!

This also means, in principle, you can convert any arbitrary program into a Quine, by just encoding its source code as an intron!


Oh, and why was the above calendar bit relevant, you might ask? It wasn't. (Or was it?) Much like those seemingly "junk" leap days in a calendar, this is a seemingly "junk" paragraph just hitching a ride on this blog. Sounds familiar? One might even call it an Intron of this very blog! To learn more about the fascinating and quirky story behind it, checkout Leap days, and the quest for the perfect Calendar.

Like I said, Introns might seem like a useless thing to do, but the possible existence of them will open the doors to mind-blowing interactions between several Quines.

Stay tuned for the next post on QuineRelays!


Sources and references:

Top comments (0)