Has anyone used GolfScript for a serious project aside from CodeGolf? Perhaps you could give an example. I am curious to learn it and I am wondering if its worth my time or if its just a hobby language?
When I search stackoverflow.com I can only find CodeGolf examples of the language. In some sense it reminds me when I first learned Perl. It appeared to be some mysterious and cryptic language. However, Perl has much practical and historical appeal. I especially enjoy the Regex capability built into the language. As far as I can tell by the API there is no built in Regex capability to GolfScript. Although, someone created a simple Regex parser in 256 chars.
So is GolfScript really worth learning?
GolfScript used on stackoverflow.com [11-Oct-2010]:
- http://stackoverflow.com/questions/1480023/code-golf-lasers
- http://stackoverflow.com/questions/2983161/code-golf-diamond-pattern
- http://stackoverflow.com/questions/3543811/code-golf-happy-primes
- http://stackoverflow.com/questions/1770427/code-golf-what-is-the-shortest-program-that-compiles-and-crashes
- http://stackoverflow.com/questions/1726698/code-golf-sierpinskis-triangle
- http://stackoverflow.com/questions/3478954/code-golf-xor-encryption
- http://stackoverflow.com/questions/392788/code-golf-christmas-edition-how-to-print-out-a-christmas-tree-of-height-n
- http://stackoverflow.com/questions/3858384/code-golf-playing-tetris
- http://stackoverflow.com/questions/3465392/code-golf-frobenius-number
- http://stackoverflow.com/questions/228518/palindrome-golf
- http://stackoverflow.com/questions/2634427/code-golf-numeric-equivalent-of-an-excel-column-name
- http://stackoverflow.com/questions/2199865/find-smallestint-smallest-integer-greater-than-or-equal-to-n-that-contains-exac
- http://stackoverflow.com/questions/1843182/code-golf-diamond-blackjack
- http://stackoverflow.com/questions/2388254/code-golf-collatz-conjecture
- http://stackoverflow.com/questions/237496/code-golf-factorials
- http://stackoverflow.com/questions/437/what-is-your-solution-to-the-fizzbuzz-problem
- http://stackoverflow.com/questions/1777582/turing-machine-code-golf
- http://stackoverflow.com/questions/3011389/code-golf-modulus-divide
- http://stackoverflow.com/questions/1344352/code-golf-duplicate-character-removal-in-string
- http://stackoverflow.com/questions/3836008/find-largest-number-with-all-contiguous-triples-being-unique-primes
- http://stackoverflow.com/questions/1352587/code-golf-morse-code
- http://stackoverflow.com/questions/3523323/code-golf-regex-parser
- http://stackoverflow.com/questions/1609702/code-golf-playing-cubes
- http://stackoverflow.com/questions/1646887/code-golf-spider-webs
- http://stackoverflow.com/questions/1683857/code-golf-hourglass
- http://stackoverflow.com/questions/2892126/file-fix-it-codegolf-gcj-2010-1b-a
- http://stackoverflow.com/questions/1407422/code-golf-seven-segments
- http://stackoverflow.com/questions/3364869/code-golf-who-has-the-best-poker-hand
- http://stackoverflow.com/questions/613390/code-golf-encode-decode-ascii-binary
- http://stackoverflow.com/questions/23930/factorial-algorithms-in-different-languages
- http://stackoverflow.com/questions/1263595/c-golf-spaces-in-string
- http://stackoverflow.com/questions/3230978/code-golf-four-is-magic
- http://stackoverflow.com/questions/1376077/code-golf-the-wave
- http://stackoverflow.com/questions/1749905/code-golf-fractran
- http://stackoverflow.com/questions/3190914/code-golf-pig-latin
- http://stackoverflow.com/questions/2406780/code-golf-triforce
- http://stackoverflow.com/questions/1575096/code-golf-musical-notes
- http://stackoverflow.com/questions/1636180/code-challenge-2d-array-search
- http://stackoverflow.com/questions/1078770/array-searching-code-challenge
- http://stackoverflow.com/questions/3169051/code-golf-word-frequency-chart
- http://stackoverflow.com/questions/232861/fibonacci-code-golf
- http://stackoverflow.com/questions/3034331/code-golf-rotating-maze
- http://stackoverflow.com/questions/1540030/code-golf-beehive
- http://stackoverflow.com/questions/3025595/code-golf-zigzag-pattern-scanning
- http://stackoverflow.com/questions/3472534/checking-whether-a-number-is-mathematically-a-perfect-number
- http://stackoverflow.com/questions/3324301/code-golf-digital-clock
- http://stackoverflow.com/questions/3412730/code-golf-output-multiplication-table-to-the-console
- http://stackoverflow.com/questions/1805796/code-golf-ulam-spiral
Conversion:
The source code looks fairly small. I think it would be an interesting conversion to another language. It is copyrighted by Darren Smith so with his permission of course. The token parsing seems fairly compact.
/[a-zA-Z_][a-zA-Z0-9_]*|'(?:\\.|[^'])*'?|"(?:\\.|[^"])*"?|-?[0-9]+|#[^\n\r]*|./m
{} denote inner block creation
: is a special assignment operator
Every other token is treated as a variable. Numbers and strings are variables too, just that they have a logical initial value (which you could change if you really wanted to).
' Strings and " strings are parsed using ruby's string parse, via eval. Therefore it is possible to run ruby code in GolfScript by doing something like this:
"#{Time.now}"