A Self-Reproducing Program
February 20, 2009
Write a program that takes no input and generates a copy of its own source text as its complete output.
Advertisement
Pages: 1 2
A collection of etudes, updated weekly, for the education and enjoyment of the savvy programmer
Write a program that takes no input and generates a copy of its own source text as its complete output.
Pages: 1 2
I can’t believe I’d never actually tried to write a quine before. Here’s what I came up with:
http://pastebin.com/f1c8575a1
I think my C background is showing, as this may not be particularly Schemish.
I really wanted the output to be formatted like the original program, though. That proved more difficult than I expected. Perhaps there’s an easier way that I missed.
http://pastebin.com/f3706d30d
I used fold to create a q&d add-between function when translating it from PLT Scheme to R6RS. I’m not sure it’s a good implementation or not.
File "J:\python\reproducing.py", line 1 File "J:\python\reproducing.py", line 1 ^ IndentationError: unexpected indentI do believe g wins the Internet.
print open(__file__).read(),
In perl I did:
system(“type $0″);
It can’t be that easy, what am I missing??