Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.lisp
Re: Can you better write this string manipulation function?
William James
5/2/2015 12:57:00 PM
Andrew Philpot wrote:
> |> (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.
Gauche Scheme:
gosh> (regexp-replace-all #/{[^}]*}?/ "{.}a {!} b" "")
"a b"
gosh> (regexp-replace-all #/{[^}]*}?/ "{.}a {! b" "")
"a "
--
According to some estimates, the rapidly growing Muslim immigrant population
may turn Malmo into a Muslim majority city within about ten years.... Native
Swedes are leaving the city in droves, as crime is rampant and the police
publicly admit they don't control all parts of the city. There are now gangs in
Malmo specialized in assaulting old people visiting the graves of relatives.
http://fjordman.blogspot.ca/2005/05/is-swedish-democracy-colla...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: Can you better write this string manipulation function?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password