annotate lisp/emacs-lisp/backquote.el @ 650:39f0e62a8511

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Tue, 19 May 1992 05:22:52 +0000
parents 4cd7543be581
children 8a533acedb77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
181
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;; Copyright (C) 1985 Free Software Foundation, Inc.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;; Written by Dick King (king@kestrel).
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 ;; This file is part of GNU Emacs.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; GNU Emacs is free software; you can redistribute it and/or modify
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; it under the terms of the GNU General Public License as published by
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; the Free Software Foundation; either version 1, or (at your option)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; any later version.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is distributed in the hope that it will be useful,
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; GNU General Public License for more details.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; You should have received a copy of the GNU General Public License
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;;; This is a rudimentry backquote package written by D. King,
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;;; king@kestrel, on 8/31/85. (` x) is a macro
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;;; that expands to a form that produces x. (` (a b ..)) is
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;;; a macro that expands into a form that produces a list of what a b
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;;; etc. would have produced. Any element can be of the form
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; (, <form>) in which case the resulting form evaluates
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; <form> before putting it into place, or (,@ <form>), in which
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;; case the evaluation of <form> is arranged for and each element
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;;; of the result (which must be a (possibly null) list) is inserted.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;; As an example, the immediately following macro push (v l) could
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;; have been written
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;;; (defmacro push (v l)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;; (` (setq (, l) (cons (,@ (list v l))))))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;; although
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;;; (defmacro push (v l)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;;; (` (setq (, l) (cons (, v) (, l)))))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;;; is far more natural. The magic atoms ,
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;;; and ,@ are user-settable and list-valued. We recommend that
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;;; things never be removed from this list lest you break something
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;;; someone else wrote in the dim past that comes to be recompiled in
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;;; the distant future.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;;; LIMITATIONS: tail consing is not handled correctly. Do not say
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;;; (` (a . (, b))) - say (` (a (,@ b)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;;; which works even if b is not list-valued.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;; No attempt is made to handle vectors. (` [a (, b) c]) doesn't work.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;;; Sorry, you must say things like
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;;; (` (a (,@ 'b))) to get (a . b) and
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;;; (` ((, ',) c)) to get (, c) - [(` (a , b)) will work but is a bad habit]
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;;; I haven't taught it the joys of nconc.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;;; (` atom) dies. (` (, atom)) or anything else is okay.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;;; BEWARE BEWARE BEWARE
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;;; inclusion of (,atom) rather than (, atom) or (,@atom) rather than
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;;; (,@ atom) will result in errors that will show up very late.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;;; This is so crunchy that I am considering including a check for
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;;; this or changing the syntax to ... ,(<form>). RMS: opinion?
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;;; a raft of general-purpose macros follows. See the nearest
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;;; Commonlisp manual.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (defmacro bq-push (v l)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 "Pushes evaluated first form onto second unevaluated object
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 a list-value atom"
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (list 'setq l (list 'cons v l)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (defmacro bq-caar (l)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (list 'car (list 'car l)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (defmacro bq-cadr (l)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (list 'car (list 'cdr l)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (defmacro bq-cdar (l)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (list 'cdr (list 'car l)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;;; These two advertised variables control what characters are used to
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;;; unquote things. I have included , and ,@ as the unquote and
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;;; splice operators, respectively, to give users of MIT CADR machine
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;;; derivitive machines a warm, cosy feeling.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (defconst backquote-unquote '(,)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 "*A list of all objects that stimulate unquoting in `. Memq test.")
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 (defconst backquote-splice '(,@)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 "*A list of all objects that stimulate splicing in `. Memq test.")
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ;;; This is the interface
256
7e4c7ef44243 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 181
diff changeset
91 ;;;###autoload
181
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 (defmacro ` (form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 "(` FORM) is a macro that expands to code to construct FORM.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 Note that this is very slow in interpreted code, but fast if you compile.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 FORM is one or more nested lists, which are `almost quoted':
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 They are copied recursively, with non-lists used unchanged in the copy.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (` a b) == (list 'a 'b) constructs a new list with two elements, `a' and `b'.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (` a (b c)) == (list 'a (list 'b 'c)) constructs two nested new lists.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 However, certain special lists are not copied. They specify substitution.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 Lists that look like (, EXP) are evaluated and the result is substituted.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (` a (, (+ x 5))) == (list 'a (+ x 5))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 Elements of the form (,@ EXP) are evaluated and then all the elements
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 of the result are substituted. This result must be a list; it may
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 be `nil'.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 As an example, a simple macro `push' could be written:
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 (defmacro push (v l)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 (` (setq (, l) (cons (,@ (list v l))))))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 or as
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (defmacro push (v l)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (` (setq (, l) (cons (, v) (, l)))))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 LIMITATIONS: \"dotted lists\" are not allowed in FORM.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 The ultimate cdr of each list scanned by ` must be `nil'.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 \(This does not apply to constants inside expressions to be substituted.)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 Substitution elements are not allowed as the cdr
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 of a cons cell. For example, (` (A . (, B))) does not work.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 Instead, write (` (A (,@ B))).
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 You cannot construct vectors, only lists. Vectors are treated as
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 constants.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 BEWARE BEWARE BEWARE
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 Inclusion of (,ATOM) rather than (, ATOM)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 or of (,@ATOM) rather than (,@ ATOM)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 will result in errors that will show up very late."
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (bq-make-maker form))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 ;;; We develop the method for building the desired list from
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 ;;; the end towards the beginning. The contract is that there be a
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 ;;; variable called state and a list called tailmaker, and that the form
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 ;;; (cons state tailmaker) deliver the goods. Exception - if the
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 ;;; state is quote the tailmaker is the form itself.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 ;;; This function takes a form and returns what I will call a maker in
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 ;;; what follows. Evaluating the maker would produce the form,
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 ;;; properly evaluated according to , and ,@ rules.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 ;;; I work backwards - it seemed a lot easier. The reason for this is
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 ;;; if I'm in some sort of a routine building a maker and I switch
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 ;;; gears, it seemed to me easier to jump into some other state and
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 ;;; glue what I've already done to the end, than to to prepare that
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 ;;; something and go back to put things together.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (defun bq-make-maker (form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 "Given one argument, a `mostly quoted' object, produces a maker.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 See backquote.el for details"
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (let ((tailmaker (quote nil)) (qc 0) (ec 0) (state nil))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (mapcar 'bq-iterative-list-builder (reverse form))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (and state
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (cond ((eq state 'quote)
340
36bd3a9f20e2 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 256
diff changeset
152 (list state (if (equal form tailmaker) form tailmaker)))
181
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 ((= (length tailmaker) 1)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (funcall (bq-cadr (assq state bq-singles)) tailmaker))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (t (cons state tailmaker))))))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 ;;; There are exceptions - we wouldn't want to call append of one
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 ;;; argument, for example.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (defconst bq-singles '((quote bq-quotecar)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (append car)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (list bq-make-list)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (cons bq-id)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (defun bq-id (x) x)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (defun bq-quotecar (x) (list 'quote (car x)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (defun bq-make-list (x) (cons 'list x))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 ;;; fr debugging use only
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 ;(defun funcalll (a b) (funcall a b))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 ;(defun funcalll (a b) (debug nil 'enter state tailmaker a b)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 ; (let ((ans (funcall a b))) (debug nil 'leave state tailmaker)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 ; ans))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 ;;; Given a state/tailmaker pair that already knows how to make a
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 ;;; partial tail of the desired form, this function knows how to add
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 ;;; yet another element to the burgening list. There are four cases;
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 ;;; the next item is an atom (which will certainly be quoted); a
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 ;;; (, xxx), which will be evaluated and put into the list at the top
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 ;;; level; a (,@ xxx), which will be evaluated and spliced in, or
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 ;;; some other list, in which case we first compute the form's maker,
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 ;;; and then we either launch into the quoted case if the maker's
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 ;;; top level function is quote, or into the comma case if it isn't.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 ;;; The fourth case reduces to one of the other three, so here we have
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 ;;; a choice of three ways to build tailmaker, and cit turns out we
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 ;;; use five possible values of state (although someday I'll add
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 ;;; nconcto the possible values of state).
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 ;;; This maintains the invariant that (cons state tailmaker) is the
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 ;;; maker for the elements of the tail we've eaten so far.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (defun bq-iterative-list-builder (form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 "Called by `bq-make-maker'. Adds a new item form to tailmaker,
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 changing state if need be, so tailmaker and state constitute a recipe
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 for making the list so far."
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (cond ((atom form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (funcall (bq-cadr (assq state bq-quotefns)) form))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 ((memq (car form) backquote-unquote)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (funcall (bq-cadr (assq state bq-evalfns)) (bq-cadr form)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 ((memq (car form) backquote-splice)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (funcall (bq-cadr (assq state bq-splicefns)) (bq-cadr form)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (t
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (let ((newform (bq-make-maker form)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (if (and (listp newform) (eq (car newform) 'quote))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (funcall (bq-cadr (assq state bq-quotefns)) (bq-cadr newform))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (funcall (bq-cadr (assq state bq-evalfns)) newform))))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 ))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 ;;; We do a 2-d branch on the form of splicing and the old state.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 ;;; Here's fifteen functions' names...
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (defconst bq-splicefns '((nil bq-splicenil)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (append bq-spliceappend)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (list bq-splicelist)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (quote bq-splicequote)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (cons bq-splicecons)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (defconst bq-evalfns '((nil bq-evalnil)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (append bq-evalappend)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (list bq-evallist)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (quote bq-evalquote)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (cons bq-evalcons)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (defconst bq-quotefns '((nil bq-quotenil)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (append bq-quoteappend)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (list bq-quotelist)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (quote bq-quotequote)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (cons bq-quotecons)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 ;;; The name of each function is
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 ;;; (concat 'bq- <type-of-element-addition> <old-state>)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 ;;; I'll comment the non-obvious ones before the definitions...
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 ;;; In what follows, uppercase letters and form will always be
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 ;;; metavariables that don't need commas in backquotes, and I will
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 ;;; assume the existence of something like matches that takes a
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 ;;; backquote-like form and a value, binds metavariables and returns
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 ;;; t if the pattern match is successful, returns nil otherwise. I
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 ;;; will write such a goodie someday.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 ;;; (setq tailmaker
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 ;;; (if (matches ((quote X) Y) tailmaker)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 ;;; (` ((quote (form X)) Y))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 ;;; (` ((list form (quote X)) Y))))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 ;;; (setq state 'append)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (defun bq-quotecons (form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (if (and (listp (car tailmaker))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (eq (bq-caar tailmaker) 'quote))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (setq tailmaker
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (list (list 'quote (list form (bq-cadr (car tailmaker))))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (bq-cadr tailmaker)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (setq tailmaker
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (list (list 'list
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (list 'quote form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (car tailmaker))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (bq-cadr tailmaker))))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (setq state 'append))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (defun bq-quotequote (form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (bq-push form tailmaker))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 ;;; Could be improved to convert (list 'a 'b 'c .. 'w x)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 ;;; to (append '(a b c .. w) x)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 ;;; when there are enough elements
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (defun bq-quotelist (form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (bq-push (list 'quote form) tailmaker))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 ;;; (setq tailmaker
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 ;;; (if (matches ((quote X) (,@ Y)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 ;;; (` ((quote (, (cons form X))) (,@ Y)))))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (defun bq-quoteappend (form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (cond ((and (listp tailmaker)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (listp (car tailmaker))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (eq (bq-caar tailmaker) 'quote))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (rplaca (bq-cdar tailmaker)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (cons form (car (bq-cdar tailmaker)))))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (t (bq-push (list 'quote (list form)) tailmaker))))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (defun bq-quotenil (form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (setq tailmaker (list form))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (setq state 'quote))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 ;;; (if (matches (X Y) tailmaker) ; it must
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 ;;; (` ((list form X) Y)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (defun bq-evalcons (form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (setq tailmaker
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (list (list 'list form (car tailmaker))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (bq-cadr tailmaker)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (setq state 'append))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 ;;; (if (matches (X Y Z (,@ W)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 ;;; (progn (setq state 'append)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 ;;; (` ((list form) (quote (X Y Z (,@ W))))))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 ;;; (progn (setq state 'list)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 ;;; (list form 'X 'Y .. ))) ; quote each one there is
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (defun bq-evalquote (form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (cond ((< (length tailmaker) 3)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (setq tailmaker
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (cons form
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 (mapcar (function (lambda (x)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (list 'quote x)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 tailmaker)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (setq state 'list))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 (t
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (setq tailmaker
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (list (list 'list form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (list 'quote tailmaker)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 (setq state 'append))))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (defun bq-evallist (form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 (bq-push form tailmaker))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 ;;; (cond ((matches ((list (,@ X)) (,@ Y)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 ;;; (` ((list form (,@ X)) (,@ Y))))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 ;;; ((matches (X))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 ;;; (` (form (,@ X))) (setq state 'cons))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 ;;; ((matches ((,@ X)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 ;;; (` (form (,@ X)))))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (defun bq-evalappend (form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (cond ((and (listp tailmaker)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 (listp (car tailmaker))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (eq (bq-caar tailmaker) 'list))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (rplacd (car tailmaker)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 (cons form (bq-cdar tailmaker))))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 ((= (length tailmaker) 1)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (setq tailmaker (cons form tailmaker)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 state 'cons))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (t (bq-push (list 'list form) tailmaker))))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (defun bq-evalnil (form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 (setq tailmaker (list form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 state 'list))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 ;;; (if (matches (X Y)) ; it must
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 ;;; (progn (setq state 'append)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 ;;; (` (form (cons X Y))))) ; couldn't think of anything clever
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (defun bq-splicecons (form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (setq tailmaker
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (list form
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (list 'cons (car tailmaker) (bq-cadr tailmaker)))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 state 'append))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (defun bq-splicequote (form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (setq tailmaker (list form (list 'quote tailmaker))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 state 'append))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (defun bq-splicelist (form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (setq tailmaker (list form (cons 'list tailmaker))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 state 'append))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (defun bq-spliceappend (form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (bq-push form tailmaker))
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (defun bq-splicenil (form)
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (setq state 'append
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 tailmaker (list form)))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 340
diff changeset
354
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 340
diff changeset
355 (provide 'backquote)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 340
diff changeset
356