I think this might be a classic question but I am not aware of an answer. Can a program output a copy of itself, and, if so, is there a short program that does this?
I assume you allow interpreted languages. (At some level, all languages are interpreted.) Somebody writes the interpreter, and if you are writing it, you can add to it any built-in functions you like, such as a (lispy) function (foo)
that does nothing except print "(foo)
".
Or you can add a more complex macro-type function (printMeAndMyArgs ...)
.
So the trick is in how you define the problem.