Looking for better replace-regexp in CLISP
Jean Louis <[email protected]>
| Newsgroups | gmane.lisp.clisp.general |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I have come up with this dirty solution to replace the string, by
using CLISP's builtin regexp: search.
Is there any other nicer, simpler, solution for the (replace-string
var1 var2 string) below?
Jean Louis
(defun replace-string (var1 var2 string)
(let ((split (regexp:regexp-split var1 string))) ; regexp-split is in CLISP implementation
(format nil "~{~a~}" (butlast (flatten (map 'list #'(lambda (x) (cons x var2)) split))))))
(defun flatten (obj)
"From Rosetta code: https://rosettacode.org/wiki/Flatten_a_list#Common_Lisp"
(do* ((result (list obj))
(node result))
((null node) (delete nil result))
(cond ((consp (car node))
(when (cdar node) (push (cdar node) (cdr node)))
(setf (car node) (caar node)))
(t (setf node (cdr node))))))
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
clisp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/clisp-list