Skip to content

Instantly share code, notes, and snippets.

@eigenhombre
Last active September 4, 2022 14:39
Show Gist options
  • Save eigenhombre/3b5eeb771cec684ca35dab135d06b854 to your computer and use it in GitHub Desktop.
Save eigenhombre/3b5eeb771cec684ca35dab135d06b854 to your computer and use it in GitHub Desktop.
;; Adaptation, in l1, of my Clojure adaptation[1] of Douglas
;; R. Hofstadter's humorous Lisp program published in Metamagical Themas,
;; Scientific American, 1983:
;; [1] http://johnj.com/posts/oodles/
(def recipes '((TOMATOES (TOMATOES on MACARONI (and TOMATOES only)
exquisitely SPICED))
(MACARONI (MACARONI and CHEESE (a REPAST of Naples, Italy)))
(REPAST (rather extraordinary PASTA and SAUCE, typical))
(CHEESE (cheddar, havarti, emmentaler
(especially SHARP emmenthaler)))
(SHARP (strong, hearty, and rather pungent))
(SPICED (sweetly pickled in CHEESE ENDIVE dressing))
(ENDIVE (egg NOODLES, dipped in vinegar eggnog))
(NOODLES (NOODLES (oodles of delicious LINGUINI) elegantly served))
(LINGUINI (LAMBCHOPS (including NOODLES)
gotten usually in Northern Italy))
(PASTA (PASTA and SAUCE (that is ALL!)))
(ALL! (a lucious lunch))
(SAUCE (SHAD and unusual COFFEE (excellente!)))
(SHAD (SPAGHETTI, heated al dente))
(SPAGHETTI (standard PASTA, always good, hot particularly
(twist, then ingest)))
(COFFEE (choice of fine flavors, particularly ESPRESSO))
(ESPRESSO (excellent, strong, powerful, rich ESPRESSO,
suppressing sleep outrageously))
(BASTA! (belly all stuffed (tummy ache!)))
(LAMBCHOPS (LASAGNE and meatballs, casually heaped onto PASTA SAUCE))
(LASAGNE (LINGUINI and SAUCE and GARLIC (NOODLES everywhere!)))
(RHUBARB (RAVIOLI, heated under butter and RHUBARB (BASTA!)))
(RAVIOLI (RIGATONI and vongole in oil, lavishly introduced))
(RIGATONI (rich Italian GNOCCHI and TOMATOES (or NOODLES instead)))
(GNOCCHI (GARLIC NOODLES over crisp CHEESE, heated immediately))
(GARLIC (green and red LASAGNE in CHEESE))))
(defn lower (x) (/ (* x 90) 100))
(defn acronym? (x)
(and (atom? x)
(= x (upcase x))))
(defn assoc (x pairs)
(cond ((not pairs) ())
((= x (caar pairs))
(car pairs))
(t (assoc x (cdr pairs)))))
(defn lookup (x pairs)
(second (assoc x pairs)))
(defn expand (phrase recipes probability)
(cond
((atom? phrase) phrase)
((not phrase) ())
((acronym? (car phrase))
(if (< (randint 100) probability)
(concat
(expand (lookup (car phrase) recipes) recipes (lower probability))
(expand (cdr phrase) recipes probability))
(cons (car phrase) (expand (cdr phrase) recipes probability))))
(t (cons (expand (car phrase) recipes (lower probability))
(expand (cdr phrase) recipes (lower probability))))))
(defn normalize (l)
(when l
(if (atom? l)
(downcase l)
(cons (normalize (car l))
(normalize (cdr l))))))
(printl (normalize (expand (randchoice recipes) recipes 100)))
;; => (a sample run)
;; lasagne and meatballs, casually heaped onto pasta and shad and unusual
;; coffee (excellente!) (that is all!) sauce (including noodles) gotten
;; usually in northern italy (lambchops (including noodles) gotten
;; usually in northern italy and sauce and garlic (noodles (oodles of
;; delicious linguini) elegantly served everywhere!) and meatballs,
;; casually heaped onto pasta sauce (including noodles) gotten usually in
;; northern italy and shad and unusual choice of fine flavors,
;; particularly espresso (excellente!) and green and red lasagne in
;; cheese (noodles (oodles of delicious linguini) elegantly served
;; everywhere!) and meatballs, casually heaped onto pasta and sauce (that
;; is all!) and sauce (that is all!) sauce (including noodles) gotten
;; usually in northern italy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment