[Top][All Lists]

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

emacs lisp confusion using append

From: Balaji Venkataraman
Subject: emacs lisp confusion using append
Date: Wed, 04 Jun 2003 19:39:28 -0700
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.1 (usg-unix-v)

I was trying to write some lisp code, but am completely boggled by this.

Here's what I originally had in my ~/.emacs:
(defun append-path (elisp-path)
  "Appends ELISP-PATH path to the load-path.
Emacs will look for additional .el files there"
  (setq load-path (append load-path (list (expand-file-name elisp-path)))))

(append-path "~/usr/elisp")

This puts "~/usr/elisp" as the last elem of load-path.

Then I changed it to this:
(defun append-path (orig-path path)
  "Appends PATH to ORIG-PATH. PATH is a string and ORIG-PATH is a variable.
If ORIG-PATH is not defined, returns nil."
  (if (boundp 'orig-path)
      (setq orig-path (append orig-path (list (expand-file-name path))))

(append-path load-path "~/usr/elisp")

Now "~/usr/elisp" is *missing* from the load-path. 

I did reach for the lisp reference manual and found this footnote:
   (1) There is no strictly equivalent way to add an element to the end
of a list.  You can use `(append LISTNAME (list NEWELT))', which
creates a whole new list by copying LISTNAME and adding NEWELT to its
end.  Or you can use `(nconc LISTNAME (list NEWELT))', which modifies
LISTNAME by following all the CDRs and then replacing the terminating
`nil'.  Compare this to adding an element to the beginning of a list
with `cons', which neither copies nor modifies the list.

Also the manual says: "but the last one should usually be a list. All
arguments except the last one are copied, so none of the arguments is

I don't understand why the first one works and the second doesn't. I no lisp
expert and I realise there are many deficiencies in my code. Is listp a
better substitute for boundp? Help appreciated.

Remember 2 + 2 = 5, for large values of 2

reply via email to

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