help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Setting the nth element of a list


From: Barry Margolin
Subject: Re: Setting the nth element of a list
Date: Thu, 04 Jun 2009 22:25:19 -0400
User-agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)

In article 
<8a7c4d36-195d-4517-827e-7fbeca7ae03f@r34g2000vba.googlegroups.com>,
 Nordlöw <per.nordlow@gmail.com> wrote:

> This simple example changes the second element in the list x:
> 
> (setq x '(a nil c))
> (setcar (cdr x 'b)
> 
> How do I generalize this to a function that sets (changes) the nth
> element of a list (for side effects only)?
> 
> Thanks in advance,
> Nordlöw

(require 'cl-macs)
(setf (nth n x) 'b)

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***


reply via email to

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