무념한 문장 생성 예제 코드

; SLIME: The Superior Lisp Interaction Mode for Emacs
CL-USER> (defun sentence ()
           (append (noun-phrase) (verb-phrase)))
SENTENCE
CL-USER> (defun noun-phrase ()
           (append (Article) (Noun)))
NOUN-PHRASE
CL-USER> (defun verb-phrase ()
           (append (Verb) (noun-phrase)))
VERB-PHRASE
CL-USER> (defun Article ()
           (one-of '(the a)))
ARTICLE
CL-USER> (defun Noun ()
           (one-of '(man ball woman table)))
NOUN
CL-USER> (defun Verb ()
           (one-of '(hit took saw liked)))
VERB
CL-USER> (defun one-of (set)
           "Pick one element of set, and make a list of it"
           (list (random-elt set)))
ONE-OF
CL-USER> (defun random-elt (choices)
           "Choose an element from a list at random."
           (elt choices (random (length choices))))
RANDOM-ELT
CL-USER> (sentence)
(A BALL SAW THE WOMAN)
CL-USER> (sentence)
(A BALL TOOK THE WOMAN)
CL-USER> (sentence)
(A MAN LIKED THE MAN)
CL-USER> (sentence)
(THE TABLE SAW A MAN)


아무리 랜덤이라지만 하나같이 비정상적인 문장이 (...)
에잉; 난 context sensitive한 녀석을 원해~~

ps.
내심 THE WOMAN HIT THE TABLE이 나오길 기대했는데 (먼 산)

트랙백

이 글과 관련된 글 쓰기 (트랙백 보내기)
TrackbackURL : http://www.xeraph.com/tb/1195966 [도움말]

덧글

댓글 입력 영역