December 7th, 2009, 04:12 PM
Hello, I am new to programming, I am working on an assignment I have 3/4 done and canít figure out the rest here are the requirements
The program reads the text from the named file and outputs a scrambled version of the text in which:
1. All but the first and the last letters in every word (defined as a contiguous sequence of alphabetic characters) are permuted randomly.
2. All other characters (numbers and punctuations) remain unchanged.
I have another file that has a paragraph of text with punctuationÖ I guess I canít figure out these parts
1. Create a handle-alpha function that:
a. takes a stream argument (in) and a character argument (c),
b. read more alphabetic characters from the stream until you hit a non-alphabetic character or end of file,
c. form a list from c and the alphabetic characters read,
d. if the list contains 4 or more characters, shuffle all but the first and the last characters in the list,
e. convert the list back to a string,
f. print the resulting string,
g. return the first non-alphabetic character that follows the word.
Here is my code...ThanksÖ If you canít help me thank you for reading this.
(defun scramble (test.lisp) ; my scramble function takes a string argument
(with-open-file (in test.lisp) ; open the named file
(setq c (read-char in nil)) ; read the first character from the file
(loop ; repeat until return
(setq nc ; set the next character
(cond ; depending on 3 cases of the current character
((null c) (return nil)) ; 1: end of file -> exit the loop
((alpha-char-p c) (handle-alpha in c)) ; 2: alphabetic -> call handle-alpha
(t (format t "~a" c) ; 3: non-alphabetic -> print it
(setq c (read-char in nil)) ; and read the next character
)) ; end cond and setq nc
(setq c nc) ; next character becomes current character for next iteration
) ; end loop
)) ; end with-open-file and defun