annotate lisp/prim/backquote.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; backquote.el --- Full backquote support for elisp. Reverse compatible too.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Keywords: extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;; Synched up with: Not synched with FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;; The bulk of the code is originally from CMU Common Lisp (original notice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; below).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;; It correctly supports nested backquotes and backquoted vectors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;; Converted to work with elisp by Miles Bader <miles@cogsci.ed.ac.uk>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; Changes by Jonathan Stigelman <Stig@hackvan.com>:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; - Documentation added
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;; - support for old-backquote-compatibility-hook nixed because the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;; old-backquote compatibility is now done in the reader...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; - nixed support for |,.| because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;; (a) it's not in CLtl2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; (b) ",.foo" is the same as ". ,foo"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; (c) because RMS isn't interested in using this version of backquote.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; wing@666.com; added ,. support back in:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; (a) yes, it is in CLtl2. Read closely on page 529.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; (b) RMS in 19.30 adds C support for ,. even if it's not really
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; handled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; **********************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; This code was written as part of the CMU Common Lisp project at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; Carnegie Mellon University, and has been placed in the public domain.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; If you want to use this code or any part of CMU Common Lisp, please contact
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; Scott Fahlman or slisp-group@cs.cmu.edu.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; **********************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; BACKQUOTE: Code Spice Lispified by Lee Schumacher.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; The flags passed back by BQ-PROCESS-2 can be interpreted as follows:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; |`,|: [a] => a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;; NIL: [a] => a ;the NIL flag is used only when a is NIL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; T: [a] => a ;the T flag is used when a is self-evaluating
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; QUOTE: [a] => (QUOTE a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;; APPEND: [a] => (APPEND . a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;; NCONC: [a] => (NCONC . a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; LIST: [a] => (LIST . a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; LIST*: [a] => (LIST* . a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;; The flags are combined according to the following set of rules:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;; ([a] means that a should be converted according to the previous table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;; \ car || otherwise | QUOTE or | |`,@| | |`,.|
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;;cdr \ || | T or NIL | |
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;;============================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;; |`,| ||LIST* ([a] [d]) |LIST* ([a] [d]) |APPEND (a [d]) |NCONC (a [d])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;; NIL ||LIST ([a]) |QUOTE (a) |<hair> a |<hair> a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;;QUOTE or T||LIST* ([a] [d]) |QUOTE (a . d) |APPEND (a [d]) |NCONC (a [d])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;; APPEND ||LIST* ([a] [d]) |LIST* ([a] [d]) |APPEND (a . d) |NCONC (a [d])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;; NCONC ||LIST* ([a] [d]) |LIST* ([a] [d]) |APPEND (a [d]) |NCONC (a . d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;; LIST ||LIST ([a] . d) |LIST ([a] . d) |APPEND (a [d]) |NCONC (a [d])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;; LIST* ||LIST* ([a] . d) |LIST* ([a] . d) |APPEND (a [d]) |NCONC (a [d])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;;<hair> involves starting over again pretending you had read ".,a)" instead
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;; of ",@a)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;; These are the forms it expects: |backquote| |`| |,| |,@| and |,.|.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (defconst bq-backquote-marker 'backquote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (defconst bq-backtick-marker '\`) ; remnant of the old lossage
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (defconst bq-comma-marker '\,)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (defconst bq-at-marker '\,@)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (defconst bq-dot-marker '\,\.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;;; ----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (fset '\` 'backquote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (defmacro backquote (template)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 "Expand the internal representation of a backquoted TEMPLATE into a lisp form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 The backquote character is like the quote character in that it prevents the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 template which follows it from being evaluated, except that backquote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 permits you to evaluate portions of the quoted template. A comma character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 inside TEMPLATE indicates that the following item should be evaluated. A
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 comma character may be followed by an at-sign, which indicates that the form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 which follows should be evaluated and inserted and \"spliced\" into the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 template. Forms following ,@ must evaluate to lists.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 Here is how to use backquotes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (setq p 'b
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 q '(c d e))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 `(a ,p ,@q) -> (a b c d e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 `(a . b) -> (a . b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 `(a . ,p) -> (a . b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 The XEmacs lisp reader expands lisp backquotes as it reads them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 Examples:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 `atom is read as (backquote atom)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 `(a ,b ,@(c d e)) is read as (backquote (a (\\, b) (\\,\\@ (c d e))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 `(a . ,p) is read as (backquote (a \\, p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 \(backquote TEMPLATE) is a macro that produces code to construct TEMPLATE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 Note that this is very slow in interpreted code, but fast if you compile.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 TEMPLATE is one or more nested lists or vectors, which are `almost quoted'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 They are copied recursively, with elements preceded by comma evaluated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (backquote (a b)) == (list 'a 'b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (backquote (a [b c])) == (list 'a (vector 'b 'c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 However, certain special lists are not copied. They specify substitution.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 Lists that look like (\\, EXP) are evaluated and the result is substituted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (backquote (a (\\, (+ x 5)))) == (list 'a (+ x 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 Elements of the form (\\,\\@ EXP) are evaluated and then all the elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 of the result are substituted. This result must be a list; it may
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 be `nil'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 Elements of the form (\\,\\. EXP) are evaluated and then all the elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 of the result are concatenated to the list of preceding elements in the list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 They must occur as the last element of a list (not a vector).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 EXP may evaluate to nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 As an example, a simple macro `push' could be written:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (defmacro push (v l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 `(setq ,l (cons ,@(list v l))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 or as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (defmacro push (v l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 `(setq ,l (cons ,v ,l)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 For backwards compatibility, old-style emacs-lisp backquotes are still read.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 OLD STYLE NEW STYLE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (` (foo (, bar) (,@ bing))) `(foo ,bar ,@bing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 Because of the old-style backquote support, you cannot use a new-style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 backquoted form as the first element of a list. Perhaps some day this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 restriction will go away, but for now you should be wary of it:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (`(this ,will ,@fail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ((` (but (, this) will (,@ work))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 This is an extremely rare thing to need to do in lisp."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (bq-process template))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;;; ----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (defconst bq-comma-flag 'unquote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (defconst bq-at-flag 'unquote-splicing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (defconst bq-dot-flag 'unquote-nconc-splicing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (defun bq-process (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (let* ((flag-result (bq-process-2 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (flag (car flag-result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (result (cdr flag-result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (cond ((eq flag bq-at-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (error ",@ after ` in form: %s" form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ((eq flag bq-dot-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (error ",. after ` in form: %s" form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (bq-process-1 flag result)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;;; ----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (defun bq-vector-contents (vec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (let ((contents nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (n (length vec)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (while (> n 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (setq n (1- n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (setq contents (cons (aref vec n) contents)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ;;; This does the expansion from table 2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (defun bq-process-2 (code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (cond ((vectorp code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (let* ((dflag-d
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (bq-process-2 (bq-vector-contents code))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (cons 'vector (bq-process-1 (car dflag-d) (cdr dflag-d)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ((atom code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (cond ((null code) (cons nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ((or (numberp code) (eq code t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (cons t code))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (t (cons 'quote code))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ((eq (car code) bq-at-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (cons bq-at-flag (nth 1 code)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ((eq (car code) bq-dot-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (cons bq-dot-flag (nth 1 code)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ((eq (car code) bq-comma-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (bq-comma (nth 1 code)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ((or (eq (car code) bq-backquote-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (eq (car code) bq-backtick-marker)) ; old lossage
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (bq-process-2 (bq-process (nth 1 code))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (t (let* ((aflag-a (bq-process-2 (car code)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (aflag (car aflag-a))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (a (cdr aflag-a)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (let* ((dflag-d (bq-process-2 (cdr code)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (dflag (car dflag-d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (d (cdr dflag-d)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (if (eq dflag bq-at-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 ;; get the errors later.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (error ",@ after dot in %s" code))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (if (eq dflag bq-dot-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (error ",. after dot in %s" code))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ((eq aflag bq-at-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (if (null dflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (bq-comma a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (cons 'append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (cond ((eq dflag 'append)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (cons a d ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (t (list a (bq-process-1 dflag d)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ((eq aflag bq-dot-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (if (null dflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (bq-comma a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (cons 'nconc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (cond ((eq dflag 'nconc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (cons a d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (t (list a (bq-process-1 dflag d)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 ((null dflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (if (memq aflag '(quote t nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (cons 'quote (list a))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (cons 'list (list (bq-process-1 aflag a)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 ((memq dflag '(quote t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (if (memq aflag '(quote t nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (cons 'quote (cons a d ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (cons 'list* (list (bq-process-1 aflag a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (bq-process-1 dflag d)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (t (setq a (bq-process-1 aflag a))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (if (memq dflag '(list list*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (cons dflag (cons a d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (cons 'list*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (list a (bq-process-1 dflag d)))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 ;;; This handles the <hair> cases
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (defun bq-comma (code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (cond ((atom code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (cond ((null code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (cons nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ((or (numberp code) (eq code 't))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (cons t code))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (t (cons bq-comma-flag code))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 ((eq (car code) 'quote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (cons (car code) (car (cdr code))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 ((memq (car code) '(append list list* nconc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (cons (car code) (cdr code)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ((eq (car code) 'cons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (cons 'list* (cdr code)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (t (cons bq-comma-flag code))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 ;;; This handles table 1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (defun bq-process-1 (flag thing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (cond ((or (eq flag bq-comma-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (memq flag '(t nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 thing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 ((eq flag 'quote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (list 'quote thing))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ((eq flag 'vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (list 'apply '(function vector) thing))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (t (cons (cdr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (assq flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 '((cons . cons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (list* . bq-list*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (list . list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (append . append)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (nconc . nconc))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 thing))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 ;;; ----------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (defmacro bq-list* (&rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 "Returns a list of its arguments with last cons a dotted pair."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (setq args (reverse args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (let ((result (car args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (setq args (cdr args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (while args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (setq result (list 'cons (car args) result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (setq args (cdr args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (provide 'backquote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287