Last active
September 20, 2019 19:18
-
-
Save suspectpart/154e5e197d257f5395c08e87f17abc93 to your computer and use it in GitHub Desktop.
A beer name generator, written in LISP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Helpers | |
(defun last-letter (str) | |
(char str (- (length str) 1)) | |
) | |
(defun ends-with (str letter) | |
(char= (last-letter str) letter) | |
) | |
(defun random-choice (coll) | |
(nth (random (length coll)) coll) | |
) | |
;; Data | |
(defvar nobles | |
(list "prinzessin" "könig" "schloss") | |
) | |
(defvar waters | |
(list "quell" "see" "bach") | |
) | |
(defvar random_noise | |
(list "gold" "silber" "schlonz" "fusel" "premium") | |
) | |
(defvar kind | |
(list "radler" "maibock" "alkoholfrei" "graprefruit" "starkbier") | |
) | |
;; Program | |
(defun random-beer-name () | |
(let* ( | |
(left (random-choice (append nobles waters random_noise))) | |
(right (random-choice (append nobles waters))) | |
(middle (cond | |
((ends-with left #\g) "s") | |
((ends-with left #\l) "en") | |
((ends-with left #\n) "en") | |
))) | |
(concatenate 'string left middle right " " (random-choice kind)) | |
) | |
) | |
;; "Main" | |
(print (string-capitalize (random-beer-name))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment