Pattern Matching in Lisp: Lists Can Be Used To Represent Sentences, Relations, Tree Structures, Etc
Pattern Matching in Lisp: Lists Can Be Used To Represent Sentences, Relations, Tree Structures, Etc
(defun match3 (p s)
(cond
((null p)(null s))
((or (atom p)(atom s)) nil)
((equalp (car p) (car s))
(match3 (cdr p)(cdr s)) )
((eq (car p) '?)(match3 (cdr p)(cdr s)))
(t nil) ) )
) ) )
(string-upcase s) ; =>
”THIS IS A REAL LIVE STRING.”
CSE 341, S. Tanimoto 12
Pattern Matching -
Reading Text from the User
; Read in a line of text from the user.
(defun text-from-user ()
(format t "Enter some text: ")
(let ((user-text (read-line t)))
(format t "You entered: ~A" user-text)
'bye
) )
(defun text-from-file ()
(with-open-file (file "input.txt" :direction :input)
(let (the-line)
(loop
(setq the-line (read-line file nil 'done))
(if (eq the-line 'done) (return))
(format t "The input line was: ~A~%" the-line)
)
'bye
)
) )