Creating a Quine in QB64PE - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Programs (https://qb64phoenix.com/forum/forumdisplay.php?fid=7) +---- Thread: Creating a Quine in QB64PE (/showthread.php?tid=2636) |
Creating a Quine in QB64PE - TDarcos - 04-29-2024 A "quine" is a program that when you run it, generates a listing of itself, such that if you took its output and copied into QB64, it would produce the same thing, itself. Well, I tried writing one, yeah I could get the program to list itself, but generating the data to allow that program to display itself, and have it look exactly the same is the problem. Because you have to act one step back, meaning if you have a string, you have to enclose it in quotation marks, which means you have to show the quote mark, Chr$(34). It's still a pain. So I decided to see other ways this could be done. And one said to write a program to list itself as contents from an array. That made it trivial. What I did was write the program to list itself. But now it needs the data. So to get that, I wrote another program. This one reads a file and converts it into DATA statements containing the byte values as data statements. I copied them, added an extra 0 at the end as an end-of-file sentinel, and sure enough, it works perfectly. First, here is the program, which I call dataconvert.bas, that translates a file into data statements: Code: (Select All)
The files Common_Dialog_Prefix.bi and Common_Dialog_Suffix.bi are included in the attached archive, and simply enable the use of the Open File dialog on Windows. Now, here is the program to list itself: Code: (Select All)
For brevity, the data statements are stripped out here, but are included in the copy below. If you want to try this, be sure you include a 0 as the last data item. Writing a quine was a fun intellectual enterprise, and I'll probably do a different one soon. Doing this one gave me ideas on how to fix the other one. I hope you find looking at/exploring this one as much fun as I had writing it! Paul RE: Creating a Quine in QB64PE - SMcNeill - 04-29-2024 Save as "untitled.bas" Code: (Select All)
RE: Creating a Quine in QB64PE - SMcNeill - 04-29-2024 If you're using the newest versions of QB64PE, there's also the simple $EMBED command. Simply embed your source in the EXE and have a routine to print that to screen/file as needed/wanted. RE: Creating a Quine in QB64PE - TDarcos - 05-02-2024 (04-29-2024, 04:10 PM)SMcNeill Wrote: Save as "untitled.bas"That's cheating! Technically, the quine itself is supposed to be able to display itself without accessing an external file. |