unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: tomas@fabula.de
Subject: Re: make an element last element of a list
Date: Wed, 22 Oct 2003 12:22:54 +0200	[thread overview]
Message-ID: <20031022102254.GA23380@www> (raw)
In-Reply-To: <20031021155009.GC18423@www>

On Tue, Oct 21, 2003 at 05:50:09PM +0200, rm@fabula.de 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


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


  reply	other threads:[~2003-10-22 10:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-21 15:08 make an element last element of a list Laurent Marzullo
2003-10-21 15:42 ` Stephen Compall
2003-10-21 15:50 ` rm
2003-10-22 10:22   ` tomas [this message]
2003-10-22 10:40     ` rm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20031022102254.GA23380@www \
    --to=tomas@fabula.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).