all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Manipulating lists somewhere in the middle (index-based)
@ 2009-06-12 20:16 florian
  2009-06-15 10:19 ` Pascal J. Bourguignon
  0 siblings, 1 reply; 2+ messages in thread
From: florian @ 2009-06-12 20:16 UTC (permalink / raw)
  To: help-gnu-emacs


I know there was a similar discussion yesterday (see
http://groups.google.de/group/gnu.emacs.help/browse_thread/thread/2fc2d1ea2229f3bc),
but that involved examining elements.

I am actually just wondering whether I reinvented the wheel in writing
two (non-destructive) functions:

(drop-nth 2 '(1 2 3 4 5))
=> (1 2 4 5)

(squeeze-in-at 2 "three" '(1 2 4 5))
=> (1 2 "three" 4 5)

My function definitions are probably not particularly interesting (if
anybody thinks they are, just let me know - they both simply work by
building a new list and returning it), but what I am wondering about
is this: when looking at the linked-paired-boxes notation the Elisp
manual uses to explain lists:

  --- ---      --- ---      --- ---
 |   |   |--> |   |   |--> |   |   |--> nil
  --- ---      --- ---      --- ---
   |            |            |
   |            |            |
    --> fir       --> oak      --> maple

[slightly modified]

it is actually very tempting to suspect there must be a way to
directly make the pointer from the cdr of "fir" point to the car of
the "maple" element and making the car of "oak" point to nil instead,
thus dropping the element from the list and getting (fir maple) as the
result.

Or, the other way round, it looks as if there could be a way to make
the pointer of the "oak" element point to a new cons cell, which has
"birch" as its car, and whose cdr we have point to the car of the
"maple" element, so as to get the list (fir oak birch maple).

Is there in fact some way to mess with these pointers, or is that a
purely didactic concept? Thanks for any input, it is really just
curiosity about Elisp!

Florian


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

end of thread, other threads:[~2009-06-15 10:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-12 20:16 Manipulating lists somewhere in the middle (index-based) florian
2009-06-15 10:19 ` Pascal J. Bourguignon

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.