Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!das-news.harvard.edu!news2.near.net!MathWorks.Com!europa.eng.gtefsd.com!news.umbc.edu!haven.umd.edu!ames!kronos.arc.nasa.gov!kepler.arc.nasa.gov!philpot
From: philpot@kepler.arc.nasa.gov (Andrew Philpot)
Subject: Re: Can you better write this string manipulation function?
Message-ID: <1994Sep7.231741.22231@ptolemy-ethernet.arc.nasa.gov>
Sender: usenet@ptolemy-ethernet.arc.nasa.gov (usenet@ptolemy.arc.nasa.gov)
Nntp-Posting-Host: kepler.arc.nasa.gov
Organization: NASA/ARC Information Sciences Division
References: <34l75h$1sm@engr.orst.edu> <34lfvb$jr7@anaxagoras.ils.nwu.edu>
Date: Wed, 7 Sep 1994 23:17:41 GMT
Lines: 37

In article <34lfvb$jr7@anaxagoras.ils.nwu.edu>, will@aristotle.ils.nwu.edu (William Fitzgerald) writes:
|> (defun remove-curly-brace-comments (string)
|>   (let ((collecting t))
|>     (coerce
|>      (loop for ch across string 
|>            when (char= ch #\{)
|>            do (setf collecting nil)
|>            when collecting
|>            collect ch
|>            when (char= ch #\})
|>            do (setf collecting t))
|>      'string)))
|> 

Shamelessly appropriating from the above,

(defun remove-curly-brace-comments (in)
  (let ((collecting t))
    (with-output-to-string (out)
      (loop for ch across in
	  when (char= ch #\{)
	  do (setq collecting nil)
	  when collecting
	  do (write-char ch out)
	  when (char= ch #\})
	  do (setq collecting t)))))

Perhaps a little more efficient, as it doesn't produce and then discard a list.

But what about embedded {} comments?


-- 
Andrew Philpot	 		
Recom Tech/NASA Ames 		
philpot@ptolemy.arc.nasa.gov	
			        
