Skip to content

Instantly share code, notes, and snippets.

@lispm
Created November 14, 2018 19:42
Show Gist options
  • Save lispm/69abc3473497090c3e7e9606f661acdf to your computer and use it in GitHub Desktop.
Save lispm/69abc3473497090c3e7e9606f661acdf to your computer and use it in GitHub Desktop.
Shakesperian insults by Jerry Maguire in Lisp
;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Author: [email protected]; Coding: latin-1; Base: 10; Readtable: CL -*-
; Shakesperian insults by Jerry Maguire
; Lisp code: Rainer Joswig, 2018, [email protected]
(defparameter *insult-data*
#(#("artless" "bawdy" "beslubbering" "bootless" "churlish" "cockered" "clouted"
"craven" "currish" "dankish" "dissembling" "droning" "errant" "fawning"
"fobbing" "froward" "frothy" "gleeking" "goatish" "gorbellied"
"impertinent" "infectious" "jarring" "loggerheaded" "lumpish" "mammering"
"mangled" "mewling" "paunchy" "pribbling" "puking" "puny" "quailing" "rank"
"reeky" "roguish" "ruttish" "saucy" "spleeny" "spongy" "surly" "tottering"
"unmuzzled" "vain" "venomed" "villainous" "warped" "wayward" "weedy"
"yeasty")
#("base-court" "bat-fowling" "beef-witted" "beetle-headed" "boil-brained"
"clapper-clawed" "clay-brained" "common-kissing" "crook-pated"
"dismal-dreaming" "dizzy-eyed" "doghearted" "dread-bolted" "earth-vexing"
"elf-skinned" "fat-kidneyed" "fen-sucked" "flap-mouthed" "fly-bitten"
"folly-fallen" "fool-born" "full-gorged" "guts-griping" "half-faced"
"hasty-witted" "hedge-born" "hell-hated" "idle-headed" "ill-breeding"
"ill-nurtured" "knotty-pated" "milk-livered" "motley-minded" "onion-eyed"
"plume-plucked" "pottle-deep" "pox-marked" "reeling-ripe" "rough-hewn"
"rude-growing" "rump-fed" "shard-borne" "sheep-biting" "spur-galled"
"swag-bellied" "tardy-gaited" "tickle-brained" "toad-spotted"
"unchin-snouted" "weather-bitten")
#("apple-john" "baggage" "barnacle" "bladder" "boar-pig" "bugbear"
"bum-bailey" "canker-blossom" "clack-dish" "clotpole" "coxcomb" "codpiece"
"death-token" "dewberry" "flap-dragon" "flax-wench" "flirt-gill"
"foot-licker" "fustilarian" "giglet" "gudgeon" "haggard" "harpy"
"hedge-pig" "horn-beast" "hugger-mugger" "jolthead" "lewdster" "lout"
"maggot-pie" "malt-worm" "mammet" "measle" "minnow" "miscreant" "moldwarp"
"mumble-news" "nut-hook" "pigeon-egg" "pignut" "puttock" "pumpion"
"ratsbane" "scut" "skainsmate" "strumpet" "varlot" "vassal" "whey-face"
"wagtail")))
(defun random-insult (&optional (print-p nil))
"Generates a 'Shakesperian' insult, according to Jerry Maguire.
If PRINT-P is a stream or T, then the output will be printed, otherwise it will
be returned as a string."
(flet ((random-element (sequence)
(elt sequence (random (length sequence)))))
(or (format print-p
"Thou ~a ~a ~a!"
(random-element (aref *insult-data* 0))
(random-element (aref *insult-data* 1))
(random-element (aref *insult-data* 2)))
(values))))
;;; End of File
@phoe
Copy link

phoe commented Jun 25, 2019

This code is subtly buggy, since it treats PRINT-P as a boolean value. Actually, FORMAT accepts a format destination there, and that is not a boolean (and in Common Lisp, booleans are most often generalized, which means that every Lisp datum is a valid boolean). For example, one can pass an open stream as PRINT-P, and this function will behave in a very unexpected manner.

(Via https://www.reddit.com/r/learnlisp/comments/c590wv/what_is_the_purpose_of_values_here_shakesperian/)

@lispm
Copy link
Author

lispm commented Jun 25, 2019

That one can pass an open stream is intended behavior, see the doc string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment