Re: useful string utility

From: Ken Anderson <kanderso_at_bbn.com>
Date: Fri, 19 Sep 1997 17:33:01 -0400

  
  Scheme is a wonderful language, but I agree with you that
  character manipulation in it is very painful.
  
Why is it painful? The loops in your C code become tail recursive
functions, right? Something like this in Common Lisp:

  
(defun string-split (string delimiters)
  (string-split-1 string 0 (length string) delimiters '()))

(defun string-split-1 (string start end delimiters sofar)
  (let ((pos (string-position string start end delimiters)))
    (if (not (null pos))
        (string-split-1 string (+ pos 1) end delimiters
                        (cons (subseq string start pos) sofar))
      (reverse (cons (subseq string start end) sofar)))))


(defun string-position (string start end delimiters)
  (if (< start end)
      (if (member (aref string start) delimiters) start
        (string-position string (+ start 1) end delimiters))
    nil))
  
Using local functions would give it the same structure as the C code.
 
Received on Fri Sep 19 1997 - 23:31:08 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST