Reputation: 1
am really new to LISP. I am using LispWorks and having issues on how to accept string input from the keyboard. Here is my code below compiles well but when I run, it gives an error:
"End of file while reading stream #<Synonym stream to BACKGROUND-INPUT>."
(defun get-input (prompt)
(clear-input)
(write-string prompt)
(finish-output)
(let ((x (read-line)))
(write-string x)
(close x)))
(write-string (get-input "Enter a sentence: "))
(finish-output)
I have tried all sorts of codes using "read" to no avail, someone pls help.
Upvotes: 0
Views: 56
Reputation: 1
The code below solved my problems:
(defun split-by-one-space (string)
(loop for i = 0 then (1+ j)
as j = (position #\Space string :start i)
collect (subseq string i j)
while j))
(defun rev_string()
(let ((mystr (read-line *query-io* NIL "")))
(terpri)
(format t "The Original String is : ~a~%" mystr)
(terpri)
(format t "The Reversed String By Character is : ~a~%" (reverse mystr))
(terpri)
(format t "The Reversed String By Word is : ~a~%" (nreverse (split-by-one-space mystr)))))
(rev_string)
Upvotes: 0