Forth Golf

Someone had written this in a presumed attempt to be funny, or perhaps in an attempt to vilify ForthLanguage. It's amusing, however, because this code uses words which simply don't exist in most Forths these days (e.g., ") or at all ever (e.g., >>A). In fact, looking at this code, it is trivial to see that the program would crash due to data stack overflow.

 hex 4666 dup negate do i 4000 dup 2* negate do " *" 0 dup 2dup 1e 0 do
 2swap * e >>a 2* 5 pick + -rot - j + dup dup * e >>a rot dup dup * e >>a 
 rot swap 2dup + 10000 > if 3drop 3drop "  " 0 dup 2dup leave then loop 
 2drop 2drop type 268 +loop cr drop 5de +loop

As was mentioned, this is OpenFirmware, a dialect of AnsForth with many extensions. In this example: Nonetheless, it would be interesting to see otherwise legitimate examples of ForthGolf here. Any takers?

A prime example is the InternationalObfuscatedCeeCodeContest entry of many years back, which was itself a Forth system in a few K of compressed C code.

Since everything in Forth can be redefined, and no symbols are off limits, a quick golfing method is to redefine common longer words to single characters. FalseLanguage lies in that direction.


CategoryForth CategoryGolf?


EditText of this page (last edited June 4, 2008) or FindPage with title or text search