SHARE
TWEET

Untitled

a guest Apr 18th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defun mappend (fn the-list)
  2.   "Apply fn to each element of list and append the results."
  3.   (apply #'append (mapcar fn the-list)))
  4.  
  5. (defun generate (phrase)
  6.   "Generate a random sentence or phrase"
  7.   (format t "~A " phrase)
  8.   (cond ((listp phrase)
  9.      (progn
  10.        (format t "mappend")
  11.        (mappend #'generate phrase)))
  12.     ((rewrites phrase)
  13.      (progn
  14.        (format t "generate")
  15.        (generate (random-elt (rewrites phrase)))))
  16.     (t
  17.      (progn
  18.        (format t "terminal")
  19.        (list phrase)))))
  20.  
  21. #+nil
  22. CL-USER> (generate 'sentence)
  23.   0: (GENERATE SENTENCE)
  24. SENTENCE generate    1: (GENERATE (NOUN-PHRASE VERB-PHRASE))
  25. (NOUN-PHRASE VERB-PHRASE) mappend      2: (GENERATE NOUN-PHRASE)
  26. NOUN-PHRASE generate        3: (GENERATE (ARTICLE NOUN))
  27. (ARTICLE NOUN) mappend          4: (GENERATE ARTICLE)
  28. ARTICLE generate            5: (GENERATE A)
  29. A terminal            5: GENERATE returned (A)
  30.           4: GENERATE returned (A)
  31.           4: (GENERATE NOUN)
  32. NOUN generate            5: (GENERATE WOMAN)
  33. WOMAN terminal            5: GENERATE returned (WOMAN)
  34.           4: GENERATE returned (WOMAN)
  35.         3: GENERATE returned (A WOMAN)
  36.       2: GENERATE returned (A WOMAN)
  37.       2: (GENERATE VERB-PHRASE)
  38. VERB-PHRASE generate        3: (GENERATE (VERB NOUN-PHRASE))
  39. (VERB NOUN-PHRASE) mappend          4: (GENERATE VERB)
  40. VERB generate            5: (GENERATE LIKED)
  41. LIKED terminal            5: GENERATE returned (LIKED)
  42.           4: GENERATE returned (LIKED)
  43.           4: (GENERATE NOUN-PHRASE)
  44. NOUN-PHRASE generate            5: (GENERATE (ARTICLE NOUN))
  45. (ARTICLE NOUN) mappend              6: (GENERATE ARTICLE)
  46. ARTICLE generate                7: (GENERATE THE)
  47. THE terminal                7: GENERATE returned (THE)
  48.               6: GENERATE returned (THE)
  49.               6: (GENERATE NOUN)
  50. NOUN generate                7: (GENERATE MAN)
  51. MAN terminal                7: GENERATE returned (MAN)
  52.               6: GENERATE returned (MAN)
  53.             5: GENERATE returned (THE MAN)
  54.           4: GENERATE returned (THE MAN)
  55.         3: GENERATE returned (LIKED THE MAN)
  56.       2: GENERATE returned (LIKED THE MAN)
  57.     1: GENERATE returned (A WOMAN LIKED THE MAN)
  58.   0: GENERATE returned (A WOMAN LIKED THE MAN)
  59. (A WOMAN LIKED THE MAN)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top