Hello there
Does anybody know how to get the length of a list ? I am implementing a
small program in emacs-lisp and i have to retrieve the last element of a
list. I have tried (length) and (safe-length) but they both return some
control-character (^A).
Is there another way of retrieving the last element of a list ?
Greeting Jakob Friis
Jakob Friis wrote:
> Does anybody know how to get the length of a list ? I am implementing a
> small program in emacs-lisp and i have to retrieve the last element of a
> list. I have tried (length) and (safe-length) but they both return some
> control-character (^A).
>
> Is there another way of retrieving the last element of a list ?
(length '(a b c d)) => 4
(first (last '(a b c d))) => d
At least on GNU Emacs.
--
________________________________________________________________
^. Martti Halminen
/ \`. Design Power Europe Oy
/ \ `. Tekniikantie 12, FIN-02150 Espoo, Finland
/\`. \ | Tel:+358 9 4354 2306, Fax:+358 9 455 8575
/__\|___\| ······················@dpe.fi http://www.dpe.fi
Jakob Friis wrote:
> Does anybody know how to get the length of a list ? I am implementing a
> small program in emacs-lisp and i have to retrieve the last element of a
> list. I have tried (length) and (safe-length) but they both return some
> control-character (^A).
Eh? When I ask my emacs for (length '(a b c)) it tells me 3,
as I'd expect. What are you doing?
> Is there another way of retrieving the last element of a list ?
The function LAST returns the last cons cell of a list, and the
last element is the CAR of that.
Incidentally, I think there's a newsgroup specifically for discussion
of emacs. It might be a better place for questions on emacs lisp.
I'm afraid I've forgotten its name...
--
Gareth McCaughan Dept. of Pure Mathematics & Mathematical Statistics,
·····@dpmms.cam.ac.uk Cambridge University, England.
Gareth McCaughan <·····@dpmms.cam.ac.uk> writes:
> Jakob Friis wrote:
> Incidentally, I think there's a newsgroup specifically for discussion
> of emacs. It might be a better place for questions on emacs lisp.
> I'm afraid I've forgotten its name...
here are some pertinent ones:
comp.emacs.xemacs
comp.emacs
gnu.emacs.sources
dave