I’m completely new to lisp programming. I need to write a program for a class that reads words out of an xml doc. Anyway, I wrote this function that takes an array (word) and a file stream (in). I want it to loop until it reaches a #\space in the stream while adding each collected character to the word. I then want the word returned. I’m sure I’m doing many things wrong, but here’s the method I have. I’m fairly certain that the return function at the end is completely out of place:
(defun get-string (in word)
(loop for char = (read-char in nil)
while (not (char= char #\space))
do(vector-push-extend char word))
(return word))
Now I have anther issue. The loop keeps on looking for characters after it finds a space and I get a bunch of nils. Also, I need to stop on newlines, but am not sure how to. I tied this, but it just reads every character.
(defun get-string (in word)
(loop for char = (read-char in nil)
while (not (or (char= char #\space)
(char= char #\newline)))
do(print char))
word)
The print char is in there because I’m not very good at understanding the debugger and want to see what characters I’m reading.
wordis a variable and a variable evaluates to its value. In aDEFUNbody, the last expression’s value is returned. So the return aroundwordis not needed, if you want to return the value ofword.