I was wondering if there was an in-place concatenation of a string. I
really would rather not do:
(demacro my-concat (string char)
`(setf ,string (concatenate 'string ,string (string ,char))))
Is there a better way to accomplish what I want? Thanks!
Jeff
you should check out the string tutorial at cl-cookbook.sf.net. It
explains exactly what you want.
Lowell
Jeff wrote:
> I was wondering if there was an in-place concatenation of a string. I
> really would rather not do:
>
> (demacro my-concat (string char)
> `(setf ,string (concatenate 'string ,string (string ,char))))
> Is there a better way to accomplish what I want? Thanks!
>
> Jeff
>
Am Thu, 22 Jul 2004 12:12:01 -0700 schrieb Lowell Kirsh <······@cs.ubc.ca>:
> you should check out the string tutorial at cl-cookbook.sf.net. It
> explains exactly what you want.
Oh, never took a look at this before. Nice work.
I think it's worth mentioning that the emacs clone that comes with McClim
(sorry I can't remember the name ATM) has some implementation for
Emacs-like gap-buffers, which they call Flexi-buffers. Though, it's not
ready, yet, AFAIK, but should be already be useful.
--
,,
\../ / <<< The LISP Effect
|_\\ _==__
__ | |bb| | _________________________________________________
In article <··········@odah37.prod.google.com>,
"Jeff" <···@insightbb.com> wrote:
> I was wondering if there was an in-place concatenation of a string. I
> really would rather not do:
>
> (demacro my-concat (string char)
> `(setf ,string (concatenate 'string ,string (string ,char))))
> Is there a better way to accomplish what I want? Thanks!
(defmacro my-concat (string char)
(setf ,string (array-push-extend ,string ,char)))
--
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Barry Margolin <······@alum.mit.edu> writes:
> (defmacro my-concat (string char)
> (setf ,string (array-push-extend ,string ,char)))
Array-push-extend appears to be a LispM function that roughly
corresponds to vector-push-extend in CL. If the array is too
small and not actually adjustable, vector-push-extend signals an
error. Does array-push-extend create and return a new array in
this case?
In article <··············@Astalo.kon.iki.fi>,
Kalle Olavi Niemitalo <···@iki.fi> wrote:
> Barry Margolin <······@alum.mit.edu> writes:
>
> > (defmacro my-concat (string char)
> > (setf ,string (array-push-extend ,string ,char)))
>
> Array-push-extend appears to be a LispM function that roughly
> corresponds to vector-push-extend in CL. If the array is too
> small and not actually adjustable, vector-push-extend signals an
> error. Does array-push-extend create and return a new array in
> this case?
I was actually thinking of VECTOR-PUSH-EXTEND, and I thought it also
returned a new array rather than signaling an error if the array is not
actually adjustable (like ADJUST-ARRAY does).
But I just checked, and the return value of VECTOR-PUSH(-EXTEND) is the
new element's index, not the array, which explains why it has to signal
an error.
So I think the best answer is that if you're going to be doing this alot
in your application, make sure your strings are adjustable. But if
you're writing a general purpose macro, your original version is
probably best.
--
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***