Mercurial > emacs
comparison lisp/emacs-lisp/backquote.el @ 54494:3c18d4160cc6
(backquote-list*-macro): Use nreverse.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 22 Mar 2004 15:17:01 +0000 |
parents | 695cf19ef79e |
children | 18a818a2ee7c |
comparison
equal
deleted
inserted
replaced
54493:d8586f19729a | 54494:3c18d4160cc6 |
---|---|
1 ;;; backquote.el --- implement the ` Lisp construct | 1 ;;; backquote.el --- implement the ` Lisp construct |
2 | 2 |
3 ;;; Copyright (C) 1990, 1992, 1994, 2001 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1990, 92, 1994, 2001, 2004 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Rick Sladkey <jrs@world.std.com> | 5 ;; Author: Rick Sladkey <jrs@world.std.com> |
6 ;; Maintainer: FSF | 6 ;; Maintainer: FSF |
7 ;; Keywords: extensions, internal | 7 ;; Keywords: extensions, internal |
8 | 8 |
42 | 42 |
43 (defun backquote-list*-function (first &rest list) | 43 (defun backquote-list*-function (first &rest list) |
44 "Like `list' but the last argument is the tail of the new list. | 44 "Like `list' but the last argument is the tail of the new list. |
45 | 45 |
46 For example (backquote-list* 'a 'b 'c) => (a b . c)" | 46 For example (backquote-list* 'a 'b 'c) => (a b . c)" |
47 ;; The recursive solution is much nicer: | |
48 ;; (if list (cons first (apply 'backquote-list*-function list)) first)) | |
49 ;; but Emacs is not very good at efficiently processing recursion. | |
47 (if list | 50 (if list |
48 (let* ((rest list) (newlist (cons first nil)) (last newlist)) | 51 (let* ((rest list) (newlist (cons first nil)) (last newlist)) |
49 (while (cdr rest) | 52 (while (cdr rest) |
50 (setcdr last (cons (car rest) nil)) | 53 (setcdr last (cons (car rest) nil)) |
51 (setq last (cdr last) | 54 (setq last (cdr last) |
56 | 59 |
57 (defmacro backquote-list*-macro (first &rest list) | 60 (defmacro backquote-list*-macro (first &rest list) |
58 "Like `list' but the last argument is the tail of the new list. | 61 "Like `list' but the last argument is the tail of the new list. |
59 | 62 |
60 For example (backquote-list* 'a 'b 'c) => (a b . c)" | 63 For example (backquote-list* 'a 'b 'c) => (a b . c)" |
61 (setq list (reverse (cons first list)) | 64 ;; The recursive solution is much nicer: |
65 ;; (if list (list 'cons first (cons 'backquote-list*-macro list)) first)) | |
66 ;; but Emacs is not very good at efficiently processing such things. | |
67 (setq list (nreverse (cons first list)) | |
62 first (car list) | 68 first (car list) |
63 list (cdr list)) | 69 list (cdr list)) |
64 (if list | 70 (if list |
65 (let* ((second (car list)) | 71 (let* ((second (car list)) |
66 (rest (cdr list)) | 72 (rest (cdr list)) |