Quine quine bip quine quine Write a quine that


Writes its source code to disk
Recursively executes the written source code
Produces some variation to the code the third time (so not a true Quine)
Stops recursively calling itself the fifth time


Bonus points for leaving nothing on disk after execution.
TCL 220

proc a b {
if {"$b"=="bb"} {
rename puts w
rename p puts
set b \;exit
}
puts [set q [open [incr ::i] w]] "proc a b \{[info body a]\};a b"
catch {rename puts p}
proc puts {n m} "p \$n \${m}$b"
close $q
source $::i
};a b


The code generates files 1, 2, 3 and 4. The variation is only present in 2, the others are equivalent to the original.