From ... Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed1.bredband.com!bredband!uio.no!nntp.uio.no!ifi.uio.no!not-for-mail From: Erik Naggum Newsgroups: comp.lang.lisp Subject: Re: macros, &REST and REMF Date: 30 Nov 2002 19:09:25 +0000 Organization: Naggum Software, Oslo, Norway Lines: 41 Message-ID: <3247672165664225@naggum.no> References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: maud.ifi.uio.no 1038683366 7065 129.240.65.5 (30 Nov 2002 19:09:26 GMT) X-Complaints-To: abuse@ifi.uio.no NNTP-Posting-Date: 30 Nov 2002 19:09:26 GMT Mail-Copies-To: never User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.lisp:47801 * Rob Warnock | Side question for the group: What are the rules for a &REST arg in | macros? If they're the same as functions, then could you possibly get in | trouble with Sam's idiom due to REMF destructively modifying the "opts" | list? I believe that is the actual question, presented in his usual turbid way. The "idiom" is a recipe for disaster for macros and functions precisely because it may clobber a list that it does not own, but it is, of course, not a question about `remf´. The issue of ownership of the argument list, which has been answered many times over and which does not change just because of some particular operator, should be pretty clear: Do not mutate the argument list. This is close to a principle, and the answer does not change depending on the operator used to transmogrify it, obviously. (defun sans (plist &rest keys) (let ((sans ())) (loop (let ((tail (nth-value 2 (get-properties plist keys)))) ;; this is how it ends (unless tail (return (nreconc sans plist))) ;; copy all the unmatched keys (loop until (eq plist tail) do (push (pop plist) sans) (push (pop plist) sans)) ;; skip the matched key (setq plist (cddr plist)))))) I wrote this some time ago when I wanted to find a use for `nreconc´. It can be called as `(apply (sans :foo))´. Its main features are that it conses minimally and is more efficient than making multiple passes over the same list for more than one key. (It is assumed that `get-properties´ is fast.) -- Erik Naggum, Oslo, Norway Act from reason, and failure makes you rethink and study harder. Act from faith, and failure makes you blame someone and push harder.