Thou Impertinent Urchin-Faced Miscreant!
November 25, 2014
Our program takes a list of word lists and returns a list of words, one chosen randomly from each word list:
(define (buzz xss) (string-join #\space (map fortune xss)))
And here are some examples using the buzz-phrase generators on the previous page:
> (buzz broughton)
"integrated digital mobility"
> (buzz broughton)
"functional digital options"
> (buzz broughton)
"compatible policy concept"
> (buzz corporate)
"objectively cultivate cross-unit deliverables"
> (buzz corporate)
"proactively communicate fully researched markets"
> (buzz corporate)
"dynamically maintain user friendly infrastructures"
> (buzz shakespeare)
"Thou dissembling shard-borne baggage"
> (buzz shakespeare)
"Thou villainous crook-pated clack-dish"
> (buzz shakespeare)
"Thou unmuzzled toad-spotted maggot-pie"
We used string-join, fortune and the random number generator from the Standard Prelude. You can run the program at http://programmingpraxis.codepad.org/8bjUtPCW.
The real code is in the map line at the end – the rest is just loading in the definitions from the file using YAML, and then checking we have a valid key!
use strict; use YAML::Loader; my ($t,$k); { local $/ = undef; $t = YAML::Loader->new->load(<DATA>); } $k = 'shakespeare' unless exists $t->{$k = shift}; print "@{[ map { $_->[rand @{$_}] } @{$t->{$k}} ]}\n"; __END__ broughton: - - integrated - total - systematized - parallel - functional - responsive - optional - synchronized - compatible - balancedHaskell:
import System.Random import Control.Applicative bs = [["integrated", "total", "systematized", "parallel", "functional", "responsive", "optional", "synchronized", "compatible", "balanced"], ["management","organizational","monitored","reciprocal","digital", "logistical","transitional","incremental","third-generation","policy"], ["options", "flexibility", "capability", "mobility", "programming", "concept", "time-phase", "projection", "hardware", "contingency"]] main = f <$> sequence (replicate 3 (randomRIO (0,9))) <*> pure bs where f ns ws = (!!) <$> ZipList ws <*> ZipList nsOnly the code, put in whatever list of insults you fancy.