unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Balaji Venkataraman <bvenkata+nospam@sm.intel.com>
Subject: emacs lisp confusion using append
Date: Wed, 04 Jun 2003 19:39:28 -0700	[thread overview]
Message-ID: <8a8yshqmcf.fsf@sm.intel.com> (raw)

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

Here's what I originally had in my ~/.emacs:
--WAS WORKING--
(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")
--WAS WORKING--

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

Then I changed it to this:
--NOT WORKING--
(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))))
    nil))

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

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
altered."

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.

Thanks!
-- 
Remember 2 + 2 = 5, for large values of 2

             reply	other threads:[~2003-06-05  2:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-05  2:39 Balaji Venkataraman [this message]
2003-06-05  6:53 ` emacs lisp confusion using append David Kastrup
2003-06-05 14:20 ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8a8yshqmcf.fsf@sm.intel.com \
    --to=bvenkata+nospam@sm.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).