Subject: Re: Substring?
From: Erik Naggum <>
Date: Fri, 10 Aug 2001 18:18:04 GMT
Newsgroups: comp.lang.lisp
Message-ID: <>

* (glauber)
> I really hoped that there would be a function to copy an "array slice"
> that would map in a low level to a memcpy, but there doesn't seem to
> be anything in the arrays dictionary in the spec.

  You can do better than that.  An adjustable, displaced array may be your
  answer.  Suppose you have a string and need to compute a hash value of a
  substring and the hash function does not take :start and :end arguments.
  You could wrap the call to the hash function in something like this:

(defun funcall-with-substring (function string &key (start 0) end)
  (let ((substring (load-time-value (make-array 0 :element-type 'character :adjustable t))))
    (funcall function (adjust-array substring (- (or end (length string)) start)
				    :displaced-to string
				    :displaced-index-offset start))))