in reply to Re: Self-printing program
in thread Self-printing program

You're example using eval is excellent. I attempted something similar earlier, but my recursive call wasn't correct, but looking at your example, I understand why.

The other part of this program is to make the program output and arbitrary range of program lines, and trying to duplicate that code via the method I was using earlier was a real pain. Using this method, it should be much easier, although I wish I could execute code that was in an array directly, because it would make my life easier.

UPDATE: I implemented my existing code using this method, and it works very, very well. Thank you again for your help!

Replies are listed 'Best First'.
Re: Re: Re: Self-printing program
by etcshadow (Priest) on Apr 02, 2004 at 19:23 UTC
    Well, while this method is neat, note that it is not exactly the same thing as the recursion theorem. You should really understand the recurion theorem, or you'll probably be sorry, in the end.

    The simple way to add arbitrary code to a (recursion-theorem-based) quine is like so:

    $body = ' $body = %c%s%c; foo(); bar("baz"); printf($body,39,$body,39); '; foo(); bar("baz"); printf($body,39,$body,39);
    Note that, when doing it this way (as I mentioned), you end up having to duplicate the code (once to print it, and once to do it).
    ------------ :Wq Not an editor command: Wq