Random Limericks

This program generates a random limerick from lists of words you provide. Although the resulting limericks probably won't win any poetry competitions, they may turn out to be hilarious, and it's fun trying to choose lists of words that work well together.

Complete listing

Choosing a word or phrase at random

First we define a function choose that will choose a word or phrase at random from a list:

(defun choose (list) (nth (random (length list)) list))

For example:

> (choose '("green" "young" "vile" "bland" "old" "wild" "grey"))
"old"

Generating the limerick

The main limerick function chooses a series of words or phrases for different parts of the limerick, and then strings them together to create the verses:

(defun limerick ()
  (let ((adjective1
         (choose
          '("sordid" "graceful" "wily" "vicious"
                   "sparkling" "really" "spiteful")))
        (adjective2
         (choose
          '("green" "young" "vile" "bland"
                   "old" "wild" "grey")))
        (person-who
         (choose
          '(("duchess" "she") ("grocer" "he") ("glutton" "he") ("flautist" "she")
            ("laundress" "she") ("sailor" "he") ("gardener" "she"))))
        (place-result
         (choose
          '(("Wembley" "and felt trembly") ("Spain" "on a train")
            ("Chad" "and went mad") ("Speke" "twice a week") 
            ("Kings" "and grew wings") ("France" "in a trance")
            ("York" "with some pork"))))
        (verb
         (choose
          '("wanted" "followed" "counted" "demolished"
            "collected" "swallowed" "painted")))
        (object
         (choose
          '("some stamps" "a stoat" "a nude" "some cakes"
            "a frog" "some mould" "a duck")))
        (adverb-object
         (choose
          '(("quick" "a brick") ("slow" "some dough") ("few" "a screw") 
            ("hard" "some lard") ("late" "a plate") ("long" "King Kong")
            ("many" "a penny"))))
        (verb2
         (choose
          '("noticed" "followed" "asked for" "looked for"
            "wanted" "longed for" "needed"))))
        
    (format t "A ~a ~a ~a from ~a,~%" adjective1 adjective2 (first person-who)
            (first place-result))
    (format t "Once ~a ~a ~a.~%" verb object (second place-result))
    (format t "~a ~a so ~a~%" (second person-who) verb (first adverb-object))
    (format t "That ~a ~a ~a,~%" (second person-who) verb2 (second adverb-object))
    (format t "That ~a ~a ~a of ~a.~%" adjective1 adjective2 (first person-who)
            (first place-result))
  nil))

The words and phrases are chosen to fit the metre of the limerick form. The lists place-result and adverb-object are special in that they are lists of pairs of phrases chosen to rhyme. The final poem uses the first element of each pair at the end of one line in the poem, and the second element at the end of the following line.

An example

Here's an example:

> (limerick)
A sparkling wild duchess from Wembley,
Once followed a stoat and felt trembly.
she followed so late
That she asked for a plate,
That sparkling wild duchess of Wembley.

Previous: Anagrams

Next: Recipes


blog comments powered by Disqus