From: Sam S. <sd...@gn...> - 2004-05-27 02:51:31
|
> * Chris Hall <un...@ir...g> [2004-05-26 15:45:17 -1000]: > > #S(REGEXP::REGMATCH_T :RM_SO 58 :RM_EO 255) ; > #S(REGEXP::REGMATCH_T :RM_SO 65 :RM_EO 254) > > (BTW, how do I access the second match? Lisp newbie here, I'm afraid. > I've tried all sort of things, but can't seem to figure it out. Use > 'multiple-value-something' perhaps?) yes, MULTIPLE-VALUE-BIND or MULTIPLE-VALUE-LIST > Now, I'm using this (probably very naive and newbie-like) function to > read the file containing the data to be matched against. > > (defun get-file (fname) > (let ((in-data "") > (in-name fname) > (new-ln (coerce (list #\Newline) 'string))) > (with-open-file (in-file in-name :direction :input) > (do ((cur-line > (read-line in-file nil "<<<EOF") > (read-line in-file nil "<<<EOF"))) > ((equal "<<<EOF" cur-line)) > ; (setf in-data (concatenate 'string in-data cur-line new-ln)))) > (setf in-data (concatenate 'string in-data cur-line)))) > in-data)) 1. you want to use EQ to check for EOF (this is actually a bug in your code!) 2. also, you want to pass the stream itself as the 3rd argument to READ-LINE (this is a standard idiom). 3. if you want to read the whole file into one string, you should do it like this: (defun read-whole-file (name) (with-open-file (s name) (let ((ret (make-string (file-length s)))) (read-sequence ret s) ret))) your method is extremely inefficient. -- Sam Steingold (http://www.podval.org/~sds) running w2k <http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/> <http://www.mideasttruth.com/> <http://www.honestreporting.com> Do not tell me what to do and I will not tell you where to go. |