From: Jeff
Subject: Concatenating to a string
Date: 
Message-ID: <cdp29f$3j8@odah37.prod.google.com>
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

From: Lowell Kirsh
Subject: Re: Concatenating to a string
Date: 
Message-ID: <cdp3i1$1g8$1@mughi.cs.ubc.ca>
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
> 
From: Thomas Schilling
Subject: Re: Concatenating to a string
Date: 
Message-ID: <opsbk340nltrs3c0@news.CIS.DFN.DE>
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|   | _________________________________________________
From: Barry Margolin
Subject: Re: Concatenating to a string
Date: 
Message-ID: <barmar-9B7B44.15174822072004@comcast.dca.giganews.com>
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 ***
From: Szymon
Subject: Re: Concatenating to a string
Date: 
Message-ID: <873c3jbyau.fsf@eva.rplacd.net>
Barry Margolin <······@alum.mit.edu> writes:

> [.....]

> (defmacro my-concat (string char)
>   (setf ,string (array-push-extend ,string ,char)))

Maybe: VECTOR-PUSH-EXTEND ?

Regards, Szymon.
From: Kalle Olavi Niemitalo
Subject: Re: Concatenating to a string
Date: 
Message-ID: <874qnzak3b.fsf@Astalo.kon.iki.fi>
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?
From: Barry Margolin
Subject: Re: Concatenating to a string
Date: 
Message-ID: <barmar-4DB33E.17374822072004@comcast.dca.giganews.com>
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 ***