unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Indexing a vector
@ 2008-09-10 14:53 Nordlöw
  2008-09-10 15:53 ` Drew Adams
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nordlöw @ 2008-09-10 14:53 UTC (permalink / raw
  To: help-gnu-emacs

How do index an element in a vector? nth() works only for lists.

:(... 0 '[1 2])

Why on earth isn't such a basic operator compatible with both lists
and vectors (sequences)?

/Nordlöw


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

* RE: Indexing a vector
  2008-09-10 14:53 Indexing a vector Nordlöw
@ 2008-09-10 15:53 ` Drew Adams
  2008-09-10 15:57 ` Juanma Barranquero
  2008-09-10 16:52 ` Ted Zlatanov
  2 siblings, 0 replies; 4+ messages in thread
From: Drew Adams @ 2008-09-10 15:53 UTC (permalink / raw
  To: 'Nordlöw', help-gnu-emacs

> How do index an element in a vector? nth() works only for lists.
> 
> :(... 0 '[1 2])
> 
> Why on earth isn't such a basic operator compatible with both lists
> and vectors (sequences)?

`elt'

C-h i, choose Elisp manual, g Sequence Functions





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

* Re: Indexing a vector
  2008-09-10 14:53 Indexing a vector Nordlöw
  2008-09-10 15:53 ` Drew Adams
@ 2008-09-10 15:57 ` Juanma Barranquero
  2008-09-10 16:52 ` Ted Zlatanov
  2 siblings, 0 replies; 4+ messages in thread
From: Juanma Barranquero @ 2008-09-10 15:57 UTC (permalink / raw
  To: Nordlöw; +Cc: help-gnu-emacs

On Wed, Sep 10, 2008 at 16:53, Nordlöw <per.nordlow@gmail.com> wrote:

> How do index an element in a vector?

(aref [a b c d] 2)  =>  c

> nth() works only for lists.

Yes, `nth' is a list operation.

> Why on earth isn't such a basic operator compatible with both lists
> and vectors (sequences)?

Because it is a list operation. For the generic sequence operator, try `elt':

  (elt '(a b c d) 2) => c
  (elt [a b c d] 2)  => c
  (elt "abcd" 2) => 99

 Juanma

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

* Re: Indexing a vector
  2008-09-10 14:53 Indexing a vector Nordlöw
  2008-09-10 15:53 ` Drew Adams
  2008-09-10 15:57 ` Juanma Barranquero
@ 2008-09-10 16:52 ` Ted Zlatanov
  2 siblings, 0 replies; 4+ messages in thread
From: Ted Zlatanov @ 2008-09-10 16:52 UTC (permalink / raw
  To: help-gnu-emacs

On Wed, 10 Sep 2008 07:53:04 -0700 (PDT) Nordlöw <per.nordlow@gmail.com> wrote: 

N> How do index an element in a vector? nth() works only for lists.
N> :(... 0 '[1 2])

N> Why on earth isn't such a basic operator compatible with both lists
N> and vectors (sequences)?

The Emacs Lisp manual (chapter 6) covers this.  A vector is an array
which is a sequence, but not a list (so you can use the `elt' function
in addition to `aref' to look up elements).  `nth' works only on lists.

Ted


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

end of thread, other threads:[~2008-09-10 16:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-10 14:53 Indexing a vector Nordlöw
2008-09-10 15:53 ` Drew Adams
2008-09-10 15:57 ` Juanma Barranquero
2008-09-10 16:52 ` Ted Zlatanov

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).