From: John D. Burger
Subject: Re: String to List function
Date: 
Message-ID: <1991May28.141443.7677@linus.mitre.org>
Concerning my STRING-TO-LIST functions, Larry Masinter
<········@parc.xerox.com> made the following comment via email:

  Are you sure you're "here's one that's not a memory hog" is faster
  or smaller?

Some quick tests in Allegro 4.0 seem to show that it is in fact slower
and bigger.  My reasoning went something like this: If nothing else,
the following, which several other people posted,

  (defun cheesy-string-to-list (string)
    (values (read-from-string (concatenate 'string "(" string ")"))))

copies the string, which wastes time and memory.

On the other hand, READ et al. seem to have a substantial memory
overhead, so the repeated calls to READ in the "better" version:

  (defun string-to-list (string)
    (with-input-from-string (stream string)
      (let ((eof stream)
            (result '()))
        (loop
          (let ((object (read stream nil eof)))
            (if (eq object eof)
                (return (nreverse result))
                (push object result)))))))

run into that overhead repeatedly.  Moreover, I'm sure setting up the
stream in the latter version has a big penalty, although a version
which uses READ-FROM-STRING and manages the string index explicitly
runs even slower.

The moral of the story is something like:

  The Lisp implementors almost certainly did it better than I can
--
John Burger                                               ····@mitre.org

"You ever think about .signature files? I mean, do we really need them?"
  - alt.andy.rooney