Originally published on: Tue, 04 Aug 2009 02:47:56 +0000
I needed a little mental exercise tonight, so I chose to write a quine ( a program that produces its own source as its output ) in the Forth programming language?
Why Forth? Because I'm a novice Forth programmer at best. I don't think very well in Forth, so this took some effort. Here's the quine: ( the source for this quine is in the public domain )
I tested the above in immediate mode in Win32Forth.
The first portion:
s" ... to the ending " leaves the address and length of a counted string on the stack. By following that with swap dup 1, I was able to make a counted version of the string with a length of 1. A call to the type word then displays the letter "s" from the beginning of the string "swap".
emit 34 emit 32 causes a double-quote and a space to appear. So, the only thing I have left to do is to display the string, a dquote and the string again and I'm done.
I do that by using the remaining code over over swap type 34 emit 32 emit swap type.
Unless otherwise noted, all code and text entries are Copyright ©2009 by James K. Lawless
Save to del.icio.us
Save to StumbleUpon
Digg it
Save to Reddit
Share on Facebook
Share on Twitter
More bookmarks
Subscribe!
Auto Save Clipboard Images Redux
Extending SpiderMonkey JavaScript on Windows
Rhino JavaScript to EXE with launch4j
Compiling Rhino JavaScript to Java
Directory Traversal in Rhino JavaScript
A Command-Line MP3 Player for Windows
Auto Save Images from the Clipboard
Java in a Windows EXE with launch4j
An Interview with Tom Zimmer: Forth System Developer
Setting Windows Console Text Colors in C
Switching a Console Window to Full Screen or Windowed Mode
Internet Protocols and Rhino JavaScript
BSave and BLoad for the Commodore 64
A Lightweight Alternative to Windows Shortcuts
A Simple Associative Array Library in C
An Interview with Game Developer James Hague
An Interview with Brad Templeton
Directory Traversal in Rhino JavaScript
Changing the C64 Text Color in C
MicroISV on a Shoestring
DadHacker
The Bottom Feeder
Writin' That Code!
The Recursive ISV
The Thomsen Blog
Prototypically Speaking
The Reinvigorated Programmer