all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* setcdr question
@ 2013-07-01 22:46 drain
  2013-07-02  2:12 ` Pierre Lorenzon
  2013-07-02  9:06 ` Nicolas Richard
  0 siblings, 2 replies; 9+ messages in thread
From: drain @ 2013-07-01 22:46 UTC (permalink / raw)
  To: Help-gnu-emacs

(setq list '(Trevor Jason John Alex Max))

(setcdr (nthcdr (1- 4) list) 'Christina)

list

"list" is now set to:

(Trevor Jason John Alex . Christina)

Why is the dot there?



--
View this message in context: http://emacs.1067599.n5.nabble.com/setcdr-question-tp290941.html
Sent from the Emacs - Help mailing list archive at Nabble.com.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: setcdr question
  2013-07-01 22:46 setcdr question drain
@ 2013-07-02  2:12 ` Pierre Lorenzon
  2013-07-02  9:06 ` Nicolas Richard
  1 sibling, 0 replies; 9+ messages in thread
From: Pierre Lorenzon @ 2013-07-02  2:12 UTC (permalink / raw)
  To: aeuster; +Cc: Help-gnu-emacs

From: drain <aeuster@gmail.com>
Subject: setcdr question
Date: Mon, 1 Jul 2013 15:46:10 -0700 (PDT)

> (setq list '(Trevor Jason John Alex Max))
> 
> (setcdr (nthcdr (1- 4) list) 'Christina)
> 
> list
> 
> "list" is now set to:
> 
> (Trevor Jason John Alex . Christina)
> 
> Why is the dot there?
  Because you should have issued :
  (setcdr (nthcdr (1- 4) list) '(Christina)) 

  See how lists are made from cons cell. The cdr should always
  be a list itself or nil at the end.

  Regards 

  Pierre



> 
> 
> 
> --
> View this message in context: http://emacs.1067599.n5.nabble.com/setcdr-question-tp290941.html
> Sent from the Emacs - Help mailing list archive at Nabble.com.
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: setcdr question
  2013-07-01 22:46 setcdr question drain
  2013-07-02  2:12 ` Pierre Lorenzon
@ 2013-07-02  9:06 ` Nicolas Richard
  2013-07-02  9:17   ` Teemu Likonen
  1 sibling, 1 reply; 9+ messages in thread
From: Nicolas Richard @ 2013-07-02  9:06 UTC (permalink / raw)
  To: drain; +Cc: Help-gnu-emacs

drain <aeuster@gmail.com> writes:

> (setq list '(Trevor Jason John Alex Max))
> (setcdr (nthcdr (1- 4) list) 'Christina)

As your question was already answered, I allow me to digress slightly
in suggesting that you may like setf for such operations:

(let ((list '(Trevor Jason John Alex Max)))
  (setf (nth (1- 4) list) 'Christina)
  list)
=> (Trevor Jason John Christina Max)

-- 
Nico.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: setcdr question
  2013-07-02  9:06 ` Nicolas Richard
@ 2013-07-02  9:17   ` Teemu Likonen
  2013-07-02 22:17     ` drain
  0 siblings, 1 reply; 9+ messages in thread
From: Teemu Likonen @ 2013-07-02  9:17 UTC (permalink / raw)
  To: Nicolas Richard; +Cc: drain, Help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 553 bytes --]

Nicolas Richard [2013-07-02 11:06:58 +02:00] wrote:

> drain <aeuster@gmail.com> writes:
>> (setq list '(Trevor Jason John Alex Max))
>> (setcdr (nthcdr (1- 4) list) 'Christina)

> (let ((list '(Trevor Jason John Alex Max)))
>   (setf (nth (1- 4) list) 'Christina)
>   list)

In Common Lisp a literal data shouldn't be edited. I suggest adopting
the same practice in Emacs Lisp too. So, create your list with LIST

    (list 'Trevor 'Jason 'John 'Alex 'Max)

or copy a literal sequence before editing:

    (copy-sequence '(Trevor Jason John Alex Max))

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: setcdr question
  2013-07-02  9:17   ` Teemu Likonen
@ 2013-07-02 22:17     ` drain
  2013-07-02 22:26       ` drain
                         ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: drain @ 2013-07-02 22:17 UTC (permalink / raw)
  To: Help-gnu-emacs

Appreciate the answers.

However, where is the dot coming from? What is that supposed to represent?



--
View this message in context: http://emacs.1067599.n5.nabble.com/setcdr-question-tp290941p291014.html
Sent from the Emacs - Help mailing list archive at Nabble.com.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: setcdr question
  2013-07-02 22:17     ` drain
@ 2013-07-02 22:26       ` drain
  2013-07-03  9:13       ` Pierre Lorenzon
       [not found]       ` <mailman.90.1372804018.12400.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 9+ messages in thread
From: drain @ 2013-07-02 22:26 UTC (permalink / raw)
  To: Help-gnu-emacs

Ignore. Figured out.

That was pure laziness; apologies.



--
View this message in context: http://emacs.1067599.n5.nabble.com/setcdr-question-tp290941p291016.html
Sent from the Emacs - Help mailing list archive at Nabble.com.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: setcdr question
  2013-07-02 22:17     ` drain
  2013-07-02 22:26       ` drain
@ 2013-07-03  9:13       ` Pierre Lorenzon
       [not found]       ` <mailman.90.1372804018.12400.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 9+ messages in thread
From: Pierre Lorenzon @ 2013-07-03  9:13 UTC (permalink / raw)
  To: aeuster; +Cc: Help-gnu-emacs

From: drain <aeuster@gmail.com>
Subject: Re: setcdr question
Date: Tue, 2 Jul 2013 15:17:11 -0700 (PDT)

> Appreciate the answers.
> 
> However, where is the dot coming from? What is that supposed to represent?
  A cons cell : (cons 'a 'b) => (a . b)

  Regards 

  Pierre



> 
> 
> 
> --
> View this message in context: http://emacs.1067599.n5.nabble.com/setcdr-question-tp290941p291014.html
> Sent from the Emacs - Help mailing list archive at Nabble.com.
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: setcdr question
       [not found]       ` <mailman.90.1372804018.12400.help-gnu-emacs@gnu.org>
@ 2013-07-03 13:04         ` Rustom Mody
  2013-07-04 19:19           ` drain
  0 siblings, 1 reply; 9+ messages in thread
From: Rustom Mody @ 2013-07-03 13:04 UTC (permalink / raw)
  To: help-gnu-emacs

On Wednesday, July 3, 2013 3:56:54 AM UTC+5:30, drain wrote:
> Ignore. Figured out.
> That was pure laziness; apologies.

Asking this question is the initiatory rite of starting lisp :-)


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: setcdr question
  2013-07-03 13:04         ` Rustom Mody
@ 2013-07-04 19:19           ` drain
  0 siblings, 0 replies; 9+ messages in thread
From: drain @ 2013-07-04 19:19 UTC (permalink / raw)
  To: Help-gnu-emacs

Things really open up once car / cons / cdr / nth / nthcdr are properly
understood.

I had so much inefficient code before!

Emacs über alles.



--
View this message in context: http://emacs.1067599.n5.nabble.com/setcdr-question-tp290941p291234.html
Sent from the Emacs - Help mailing list archive at Nabble.com.



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-07-04 19:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-01 22:46 setcdr question drain
2013-07-02  2:12 ` Pierre Lorenzon
2013-07-02  9:06 ` Nicolas Richard
2013-07-02  9:17   ` Teemu Likonen
2013-07-02 22:17     ` drain
2013-07-02 22:26       ` drain
2013-07-03  9:13       ` Pierre Lorenzon
     [not found]       ` <mailman.90.1372804018.12400.help-gnu-emacs@gnu.org>
2013-07-03 13:04         ` Rustom Mody
2013-07-04 19:19           ` drain

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.