From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.help Subject: Re: emacs lisp confusion using append Date: 05 Jun 2003 08:53:13 +0200 Organization: Organization?!? Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: <8a8yshqmcf.fsf@sm.intel.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1054796100 30495 80.91.224.249 (5 Jun 2003 06:55:00 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 5 Jun 2003 06:55:00 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Thu Jun 05 08:54:58 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19NoeI-0007vY-00 for ; Thu, 05 Jun 2003 08:54:58 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19Noeo-0003Yi-SB for gnu-help-gnu-emacs@m.gmane.org; Thu, 05 Jun 2003 02:55:30 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!bloom-beacon.mit.edu!news.telebyte.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!news100.image.dk!feed.news.nacamar.de!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.com!t-online.de!news.t-online.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 49 Original-X-Trace: news.t-online.com 1054795993 02 17066 13AVVqvESGAGyL 030605 06:53:13 Original-X-Complaints-To: usenet-abuse@t-online.de X-ID: Ts93smZJQeZApxzaT-Xa9zs6P57dXL3GntN1fRXsZ7o0nEUGn-1hYN X-Face: 2FEFf>]>q>2iw=B6,xrUubRI>pR&Ml9=ao@P@i)L:\urd*t9M~y1^:+Y]'C0~{mAl`oQuAl \!3KEIp?*w`|bL5qr,H)LFO6Q=qx~iH4DN;i"; /yuIsqbLLCh/!U#X[S~(5eZ41to5f%E@'ELIi$t^ Vc\LWP@J5p^rst0+('>Er0=^1{]M9!p?&:\z]|;&=NP3AhB!B_bi^]Pfkw User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 Original-Xref: shelby.stanford.edu gnu.emacs.help:114159 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:10653 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:10653 Balaji Venkataraman writes: > 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-- For some definition of "working". This will not hesitate to add more and more identical copies to the path each time you call it. > 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. Well, but it _is_ in orig-path (before append-path exits). Lisp is call-by-value, not call-by-reference. You need to use a macro to achieve call-by-reference. Like (defmacro append-path (orig-path path) `(and (boundp ',orig-path) (add-to-list ',orig-path ,path t))) > 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? listp is something completely different. boundp checks whether a given name has a value. listp checks whether a given value is a list. -- David Kastrup, Kriemhildstr. 15, 44793 Bochum