Introspective Programs

utzoo!decvax!harpo!zeppo!wheps!eagle!cw utzoo!decvax!harpo!zeppo!wheps!eagle!cw
Wed Nov 3 18:08:22 AEST 1982

An "introspective program" is one which prints out exactly its own
source text when it executes.  No tricks like looking for a core
image or find the file and printing it are allowed.

It is a theorem of recursive function theory that all sufficiently
powerful automata have introspective programs; the definition
of "sufficiently powerful" can be made precise and all reasonable
programming languages (bar special compiler limitations) are 
powerful enough.

I have written a rather nice version in FORTRAN; the problem
is to get the required FORMAT statement out.  C requires
a similar solution because of the format string.

A well-know Turing machine solution has (if memory serves) about
1700 states; I knew somebody who wrote them all out once.

For slightly more information and many other interesting programming
problems, may I refer you to

	Etudes for Programmers
	Charles Wetherell

Feel free to buy a copy (it would be sufficient to have your company
buy a copy for you); you won't hurt my feelings.


More information about the Comp.lang.c mailing list