From: Nils Goesche
Subject: How to concatenate with a String with fill-pointer
Date: 
Message-ID: <lkbsurhkqe.fsf@pc022.xcs.local>
Hi!

Consider the following code:

(defun nstrcat (str1 str2)
  (dotimes (i (length str2))
    (vector-push-extend (schar str2 i) str1))
  str1)

(defun check ()
  (let ((foo (make-array 3 :element-type 'character
			 :fill-pointer t
			 :adjustable t
			 :initial-contents "foo"))
	(bar "bar"))
    (vector-push-extend #\a (nstrcat foo bar))
    foo))

Isn't there some kind of a built-in (and hopefully faster) function to
replace nstrcat?  Note that something like (concatenate (type-of str1)
str1 str2) doesn't work (at least not in CMUCL), because the resulting
string doesn't have a fill pointer anymore; also, I am not sure
whether this operation would be destructive, anyway :-)

Any ideas?
-- 
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

From: Erik Naggum
Subject: Re: How to concatenate with a String with fill-pointer
Date: 
Message-ID: <3184969521992515@naggum.net>
* Nils Goesche <············@anylinx.de>
| Isn't there some kind of a built-in (and hopefully faster) function to
| replace nstrcat?  Note that something like (concatenate (type-of str1)
| str1 str2) doesn't work (at least not in CMUCL), because the resulting
| string doesn't have a fill pointer anymore; also, I am not sure
| whether this operation would be destructive, anyway :-)
| 
| Any ideas?

  Move the fill-pointer and perhaps extend the array far enough that you
  have room for the new string, and then use (setf (subseq ...) ...) to
  store into the string.  This modifies the target string, of course.

#:Erik
-- 
  "When you are having a bad day and it seems like everybody is trying
   to piss you off, remember that it takes 42 muscles to produce a
   frown, but only 4 muscles to work the trigger of a good sniper rifle."
								-- Unknown
From: Nils Goesche
Subject: Re: How to concatenate with a String with fill-pointer
Date: 
Message-ID: <lk3dg2hncf.fsf@pc022.xcs.local>
Erik Naggum <····@naggum.net> writes:

>   (setf (subseq ...) ...)

Doh!  Exactly what I was looking for.  Thanks!
-- 
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."