guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: make an element last element of a list


From: tomas
Subject: Re: make an element last element of a list
Date: Wed, 22 Oct 2003 12:22:54 +0200
User-agent: Mutt/1.5.3i

On Tue, Oct 21, 2003 at 05:50:09PM +0200, address@hidden wrote:
> On Tue, Oct 21, 2003 at 05:08:42PM +0200, Laurent Marzullo wrote:
> > Hello all,
> > 
> > I've got a scheme list 
> > 
> > SCM scm_game_list;
> > 
> > and I want to add, with C API, an elements at the end of
> > the list.
> 
> If you want to destrutively modify your list you can do the
> following:
>  
>  (define my-lst (list 1 2 3 4))
>  (define new-last (list 5))
>  (set-cdr! (last my-lst) new-last)

...but you don't want to do this if the lists grow too large.
Keeping track of the last cons cell resp. maintaining a
reversed list (and reversing it once at the end, if ever
necessary) as another poster suggested is more efficient.
For short lists the solution is short and sweet, though.

Don't hesitate to ask if you need examples.

Cheers
-- tomas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]