Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

imrove how to ?

Name: Anonymous 2007-08-25 12:37 ID:E46Uz0+j

I write a defun in LISP because replace all SEARCHES with REPLACES e.g.

"Go kawari haku fun" '("kaw" "hak") '("hak" "kaw")
into
"Go hakari kawu fun"

This its:


(defun search-and-replace (string search[es] replace[s])
  (let ((index
         (position-if #'(lambda (search)
                          (and (> (length string) (length search))
                               (string= string search :end1 (length search))))
                      search[es])))
    (cond (index
           (concatenate 'string
                        (elt replace[s] index)
                        (search-and-replace
                         (subseq string (length (elt search[es] index)))
                         search[es] replace[s])))
          ((string/= "" string)
           (concatenate 'string
                        (subseq string 0 1)
                        (search-and-replace
                         (subseq string 1)
                         search[es] replace[s])))
          (t ""))))



And how did you improved? Thanks.

Name: Anonymous 2007-08-25 12:48 ID:Heaven

>>2
Scheme is a lisp.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List