Skip to content

Instantly share code, notes, and snippets.

@pascalc
Created December 9, 2013 17:51
Show Gist options
  • Save pascalc/7876720 to your computer and use it in GitHub Desktop.
Save pascalc/7876720 to your computer and use it in GitHub Desktop.
knock-knock
(clear!)
(defparser
["Knock ?knock"])
(defresponse
(and* (known ["?knock"]) (unknown ["?whosthere"]))
(fn [?knock]
(remember! {"?whosthere" true})
"Who's there?"))
(defparser
["?word"]
(fn [{?word "?word"}]
(let [?whosthere
(first (extract-knowledge "?whosthere"))
?who
(first (extract-knowledge "?who"))
?askedwho
(first (extract-knowledge "?askedwho"))
?punchlined
(first (extract-knowledge "?punchlined"))]
(cond
(and ?whosthere (not ?who))
(remember! {"?who" ?word})
(and ?askedwho (not ?punchlined))
(remember! {"?punchlined" true})))))
(defresponse
(and* (known ["?who"]) (unknown ["?askedwho"]))
(fn [?who]
(remember! {"?askedwho" true})
"?who who?"))
(defresponse
(known ["?punchlined"])
(fn [?punchlined]
"Hahaha!"))
(start-conversation!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment