annotate lisp/emacs-lisp/backquote.el @ 814:38b2499cb3e9

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