# Self-validating quine [closed]

Quines have been around forever. It's a fun challenge: write a program that, when executed, generates its own source code as output. But how do you know it's actually producing its own source code? Generally, you have to look at it and compare it, but with quines generally being composed of tricky and intricate code, this is not always easy.

Comparing two strings, though, is something a computer does very well, so why not make the program validate itself? Your task is to create a program that:

• produces its own source code as output
• compares its output to its own source code
• raises some sort of error, appropriate to the language used, if the output does not match
• If the output does match, it's acceptable to terminate without further output
• it can be hard-coded to know where to look to find its own source code for purposes of comparison. Using this knowledge to actually produce the output in the first place, however, is cheating.

Popularity contest; whoever gets the most upvotes wins. No standard loopholes, etc, you know the drill.

Enjoy!

• I find this challenge confusing. If I understand correctly, I should write a source S for a program that produces output O such that O == S, and if O != S, then an error should be raised. But since O == S, I know that the output matches and no error should be raised, so the program doesn't need to check anything. – Zgarb Oct 6 '15 at 18:42
• @Zgarb: But how do you know that O == S if you don't compare it? – Mason Wheeler Oct 6 '15 at 18:46
• Because that's a necessary condition for being a valid answer. So if my answer is valid, I don't need to check the output. – Zgarb Oct 6 '15 at 18:52
• @MasonWheeler You can create a quine in any language which is able to execute any code - also known as dynamic quine (or quine template). It's not difficult. || On a different note, you might want to include an example of what you expect in your task. – mınxomaτ Oct 6 '15 at 19:08
• How do we validate the validation? That's the real question. – The_Basset_Hound Oct 6 '15 at 19:24