forked from norvig/paip-lisp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auxfns.lisp
702 lines (586 loc) · 23.2 KB
/
auxfns.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
;;; -*- Mode: Lisp; Syntax: Common-Lisp -*-
;;; Code from Paradigms of AI Programming
;;; Copyright (c) 1991 Peter Norvig
;;; File auxfns.lisp: Auxiliary functions used by all other programs
;;; Load this file before running any other programs.
;;;; Implementation-Specific Details
(eval-when (eval compile load)
;; Make it ok to place a function definition on a built-in LISP symbol.
#+(or Allegro EXCL)
(dolist (pkg '(excl common-lisp common-lisp-user))
(setf (excl:package-definition-lock (find-package pkg)) nil))
;; Don't warn if a function is defined in multiple files --
;; this happens often since we refine several programs.
#+Lispworks
(setq *PACKAGES-FOR-WARN-ON-REDEFINITION* nil)
#+LCL
(compiler-options :warnings nil)
#+sbcl
(progn
(sb-ext:unlock-package '#:common-lisp)
(sb-ext:unlock-package '#:common-lisp-user)))
;;;; REQUIRES
;;; The function REQUIRES is used in subsequent files to state dependencies
;;; between files. The current definition just loads the required files when it has not yet
;;; been loaded, assumming they match the pathname specified in *PAIP-DIRECTORY*.
;;; You should change that to match where you have stored the files.
;;; A more sophisticated REQUIRES would search in different directories if needed.
(defvar *paip-modules* '())
(defvar *paip-files*
`("auxfns" "tutor" "examples"
"intro" "simple" "overview" "gps1" "gps" "eliza1" "eliza" "patmatch"
"eliza-pm" "search" "gps-srch" "student" "macsyma" "macsymar" "unify"
"prolog1" "prolog" "prologc1" "prologc2" "prologc" "prologcp"
"clos" "krep1" "krep2" "krep" "cmacsyma" "mycin" "mycin-r" "waltz"
"othello" "othello2" "syntax1" "syntax2" "syntax3" "unifgram"
"grammar" "lexicon" "interp1" "interp2" "interp3"
"compile1" "compile2" "compile3" "compopt"))
(defun requires (&rest files)
"The arguments are files that are required to run an application."
(loop for file in files
for name = (string-downcase file)
unless (find name *paip-modules* :test 'equal)
collect (progn
(push name *paip-modules*)
(load-paip-file name))))
(defparameter *paip-directory*
(make-pathname :name nil :type nil
:defaults (or #.(and (boundp '*compile-file-truename*) *compile-file-truename*)
(and (boundp '*load-truename*) *load-truename*)
(truename ""))) ;;??? Maybe Change this
"The location of the source files for this book. If things don't work,
change it to reflect the location of the files on your computer.")
(defparameter *paip-source*
(make-pathname :name nil :type "lisp" ;;??? Maybe Change this
:defaults *paip-directory*))
(defparameter *paip-binary*
(make-pathname
:name nil
:type (first (list #+LCL (first *load-binary-pathname-types*)
#+Lispworks system::*binary-file-type*
#+MCL "fasl"
#+Allegro excl:*fasl-default-type*
#+(or AKCL KCL) "o"
#+CMU "sparcf"
#+CLISP "fas"
"bin")) ;;??? Maybe Change this
:directory (append (pathname-directory *paip-source*) '("bin"))
:defaults *paip-directory*))
(defun paip-pathname (name &optional (type :lisp))
(make-pathname :name name
:defaults (ecase type
((:lisp :source) *paip-source*)
((:binary :bin) *paip-binary*))))
(defun compile-all-paip-files ()
(mapc #'compile-paip-file *paip-files*))
(defun compile-paip-file (name)
(let ((path (paip-pathname name :lisp)))
(load path)
(compile-file path :output-file (ensure-directories-exist (paip-pathname name :binary)))))
(defun load-paip-file (file)
"Load the binary file if it exists and is newer, else load the source."
(let* ((src (paip-pathname file :lisp))
(src-date (file-write-date src))
(bin (paip-pathname file :binary))
(bin-date (ignore-errors (file-write-date bin)))
(*package* (or (find-package :paip)
*package*)))
(load (if (and (probe-file bin) src-date bin-date (>= bin-date src-date))
bin
src))))
;;;; Macros (formerly in auxmacs.lisp: that file no longer needed)
(eval-when (load eval compile)
(defmacro once-only (variables &rest body)
"Returns the code built by BODY. If any of VARIABLES
might have side effects, they are evaluated once and stored
in temporary variables that are then passed to BODY."
(assert (every #'symbolp variables))
(let ((temps nil))
(dotimes (i (length variables)) (push (gensym) temps))
`(if (every #'side-effect-free? (list .,variables))
(progn .,body)
(list 'let
,`(list ,@(mapcar #'(lambda (tmp var)
`(list ',tmp ,var))
temps variables))
(let ,(mapcar #'(lambda (var tmp) `(,var ',tmp))
variables temps)
.,body)))))
(defun side-effect-free? (exp)
"Is exp a constant, variable, or function,
or of the form (THE type x) where x is side-effect-free?"
(or (atom exp) (constantp exp)
(starts-with exp 'function)
(and (starts-with exp 'the)
(side-effect-free? (third exp)))))
(defmacro funcall-if (fn arg)
(once-only (fn)
`(if ,fn (funcall ,fn ,arg) ,arg)))
(defmacro read-time-case (first-case &rest other-cases)
"Do the first case, where normally cases are
specified with #+ or possibly #- marks."
(declare (ignore other-cases))
first-case)
(defun rest2 (x)
"The rest of a list after the first TWO elements."
(rest (rest x)))
(defun find-anywhere (item tree)
"Does item occur anywhere in tree?"
(if (atom tree)
(if (eql item tree) tree)
(or (find-anywhere item (first tree))
(find-anywhere item (rest tree)))))
(defun starts-with (list x)
"Is x a list whose first element is x?"
(and (consp list) (eql (first list) x)))
)
;;;; Auxiliary Functions
(setf (symbol-function 'find-all-if) #'remove-if-not)
(defun find-all (item sequence &rest keyword-args
&key (test #'eql) test-not &allow-other-keys)
"Find all those elements of sequence that match item,
according to the keywords. Doesn't alter sequence."
(if test-not
(apply #'remove item sequence
:test-not (complement test-not) keyword-args)
(apply #'remove item sequence
:test (complement test) keyword-args)))
(defun partition-if (pred list)
"Return 2 values: elements of list that satisfy pred,
and elements that don't."
(let ((yes-list nil)
(no-list nil))
(dolist (item list)
(if (funcall pred item)
(push item yes-list)
(push item no-list)))
(values (nreverse yes-list) (nreverse no-list))))
(defun maybe-add (op exps &optional if-nil)
"For example, (maybe-add 'and exps t) returns
t if exps is nil, exps if there is only one,
and (and exp1 exp2...) if there are several exps."
(cond ((null exps) if-nil)
((length=1 exps) (first exps))
(t (cons op exps))))
;;; ==============================
(defun seq-ref (seq index)
"Return code that indexes into a sequence, using
the pop-lists/aref-vectors strategy."
`(if (listp ,seq)
(prog1 (first ,seq)
(setq ,seq (the list (rest ,seq))))
(aref ,seq ,index)))
(defun maybe-set-fill-pointer (array new-length)
"If this is an array with a fill pointer, set it to
new-length, if that is longer than the current length."
(if (and (arrayp array)
(array-has-fill-pointer-p array))
(setf (fill-pointer array)
(max (fill-pointer array) new-length))))
;;; ==============================
;;; NOTE: In ANSI Common Lisp, the effects of adding a definition (or most
;;; anything else) to a symbol in the common-lisp package is undefined.
;;; Therefore, it would be best to rename the function SYMBOL to something
;;; else. This has not been done (for compatibility with the book).
(defun symbol (&rest args)
"Concatenate symbols or strings to form an interned symbol"
(intern (format nil "~{~a~}" args)))
(defun new-symbol (&rest args)
"Concatenate symbols or strings to form an uninterned symbol"
(make-symbol (format nil "~{~a~}" args)))
(defun last1 (list)
"Return the last element (not last cons cell) of list"
(first (last list)))
;;; ==============================
(defun mappend (fn list)
"Append the results of calling fn on each element of list.
Like mapcon, but uses append instead of nconc."
(apply #'append (mapcar fn list)))
(defun mklist (x)
"If x is a list return it, otherwise return the list of x"
(if (listp x) x (list x)))
(defun flatten (exp)
"Get rid of imbedded lists (to one level only)."
(mappend #'mklist exp))
(defun random-elt (seq)
"Pick a random element out of a sequence."
(elt seq (random (length seq))))
;;; ==============================
(defun member-equal (item list)
(member item list :test #'equal))
;;; ==============================
(defun compose (&rest functions)
#'(lambda (x)
(reduce #'funcall functions :from-end t :initial-value x)))
;;;; The Debugging Output Facility:
(defvar *dbg-ids* nil "Identifiers used by dbg")
(defun dbg (id format-string &rest args)
"Print debugging info if (DEBUG ID) has been specified."
(when (member id *dbg-ids*)
(fresh-line *debug-io*)
(apply #'format *debug-io* format-string args)))
(defun debug (&rest ids)
"Start dbg output on the given ids."
(setf *dbg-ids* (union ids *dbg-ids*)))
(defun undebug (&rest ids)
"Stop dbg on the ids. With no ids, stop dbg altogether."
(setf *dbg-ids* (if (null ids) nil
(set-difference *dbg-ids* ids))))
;;; ==============================
(defun dbg-indent (id indent format-string &rest args)
"Print indented debugging info if (DEBUG ID) has been specified."
(when (member id *dbg-ids*)
(fresh-line *debug-io*)
(dotimes (i indent) (princ " " *debug-io*))
(apply #'format *debug-io* format-string args)))
;;;; PATTERN MATCHING FACILITY
(defconstant fail nil)
(defconstant no-bindings '((t . t)))
(defun pat-match (pattern input &optional (bindings no-bindings))
"Match pattern against input in the context of the bindings"
(cond ((eq bindings fail) fail)
((variable-p pattern) (match-variable pattern input bindings))
((eql pattern input) bindings)
((and (consp pattern) (consp input))
(pat-match (rest pattern) (rest input)
(pat-match (first pattern) (first input) bindings)))
(t fail)))
(defun match-variable (var input bindings)
"Does VAR match input? Uses (or updates) and returns bindings."
(let ((binding (get-binding var bindings)))
(cond ((not binding) (extend-bindings var input bindings))
((equal input (binding-val binding)) bindings)
(t fail))))
(defun make-binding (var val) (cons var val))
(defun binding-var (binding)
"Get the variable part of a single binding."
(car binding))
(defun binding-val (binding)
"Get the value part of a single binding."
(cdr binding))
(defun get-binding (var bindings)
"Find a (variable . value) pair in a binding list."
(assoc var bindings))
(defun lookup (var bindings)
"Get the value part (for var) from a binding list."
(binding-val (get-binding var bindings)))
(defun extend-bindings (var val bindings)
"Add a (var . value) pair to a binding list."
(cons (cons var val)
;; Once we add a "real" binding,
;; we can get rid of the dummy no-bindings
(if (eq bindings no-bindings)
nil
bindings)))
(defun variable-p (x)
"Is x a variable (a symbol beginning with `?')?"
(and (symbolp x) (equal (elt (symbol-name x) 0) #\?)))
;;; ==============================
;;;; The Memoization facility:
(defmacro defun-memo (fn args &body body)
"Define a memoized function."
`(memoize (defun ,fn ,args . ,body)))
(defun memo (fn &key (key #'first) (test #'eql) name)
"Return a memo-function of fn."
(let ((table (make-hash-table :test test)))
(setf (get name 'memo) table)
#'(lambda (&rest args)
(let ((k (funcall key args)))
(multiple-value-bind (val found-p)
(gethash k table)
(if found-p val
(setf (gethash k table) (apply fn args))))))))
(defun memoize (fn-name &key (key #'first) (test #'eql))
"Replace fn-name's global definition with a memoized version."
(clear-memoize fn-name)
(setf (symbol-function fn-name)
(memo (symbol-function fn-name)
:name fn-name :key key :test test)))
(defun clear-memoize (fn-name)
"Clear the hash table from a memo function."
(let ((table (get fn-name 'memo)))
(when table (clrhash table))))
;;;; Delayed computation:
(defstruct delay value (computed? nil))
(defmacro delay (&rest body)
"A computation that can be executed later by FORCE."
`(make-delay :value #'(lambda () . ,body)))
(defun force (delay)
"Do a delayed computation, or fetch its previously-computed value."
(if (delay-computed? delay)
(delay-value delay)
(prog1 (setf (delay-value delay) (funcall (delay-value delay)))
(setf (delay-computed? delay) t))))
;;;; Defresource:
(defmacro defresource (name &key constructor (initial-copies 0)
(size (max initial-copies 10)))
(let ((resource (symbol '* (symbol name '-resource*)))
(deallocate (symbol 'deallocate- name))
(allocate (symbol 'allocate- name)))
`(progn
(defparameter ,resource (make-array ,size :fill-pointer 0))
(defun ,allocate ()
"Get an element from the resource pool, or make one."
(if (= (fill-pointer ,resource) 0)
,constructor
(vector-pop ,resource)))
(defun ,deallocate (,name)
"Place a no-longer-needed element back in the pool."
(vector-push-extend ,name ,resource))
,(if (> initial-copies 0)
`(mapc #',deallocate (loop repeat ,initial-copies
collect (,allocate))))
',name)))
(defmacro with-resource ((var resource &optional protect) &rest body)
"Execute body with VAR bound to an instance of RESOURCE."
(let ((allocate (symbol 'allocate- resource))
(deallocate (symbol 'deallocate- resource)))
(if protect
`(let ((,var nil))
(unwind-protect (progn (setf ,var (,allocate)) ,@body)
(unless (null ,var) (,deallocate ,var))))
`(let ((,var (,allocate)))
,@body
(,deallocate var)))))
;;;; Queues:
;;; A queue is a (last . contents) pair
(defun queue-contents (q) (cdr q))
(defun make-queue ()
"Build a new queue, with no elements."
(let ((q (cons nil nil)))
(setf (car q) q)))
(defun enqueue (item q)
"Insert item at the end of the queue."
(setf (car q)
(setf (rest (car q))
(cons item nil)))
q)
(defun dequeue (q)
"Remove an item from the front of the queue."
(pop (cdr q))
(if (null (cdr q)) (setf (car q) q))
q)
(defun front (q) (first (queue-contents q)))
(defun empty-queue-p (q) (null (queue-contents q)))
(defun queue-nconc (q list)
"Add the elements of LIST to the end of the queue."
(setf (car q)
(last (setf (rest (car q)) list))))
;;;; Other:
(defun sort* (seq pred &key key)
"Sort without altering the sequence"
(sort (copy-seq seq) pred :key key))
(defun reuse-cons (x y x-y)
"Return (cons x y), or reuse x-y if it is equal to (cons x y)"
(if (and (eql x (car x-y)) (eql y (cdr x-y)))
x-y
(cons x y)))
;;; ==============================
(defun length=1 (x)
"Is x a list of length 1?"
(and (consp x) (null (cdr x))))
(defun rest3 (list)
"The rest of a list after the first THREE elements."
(cdddr list))
;;; ==============================
(defun unique-find-if-anywhere (predicate tree
&optional found-so-far)
"Return a list of leaves of tree satisfying predicate,
with duplicates removed."
(if (atom tree)
(if (funcall predicate tree)
(adjoin tree found-so-far)
found-so-far)
(unique-find-if-anywhere
predicate
(first tree)
(unique-find-if-anywhere predicate (rest tree)
found-so-far))))
(defun find-if-anywhere (predicate tree)
"Does predicate apply to any atom in the tree?"
(if (atom tree)
(funcall predicate tree)
(or (find-if-anywhere predicate (first tree))
(find-if-anywhere predicate (rest tree)))))
;;; ==============================
(defmacro define-enumerated-type (type &rest elements)
"Represent an enumerated type with integers 0-n."
`(progn
(deftype ,type () '(integer 0 ,(- (length elements) 1)))
(defun ,(symbol type '->symbol) (,type)
(elt ',elements ,type))
(defun ,(symbol 'symbol-> type) (symbol)
(position symbol ',elements))
,@(loop for element in elements
for i from 0
collect `(defconstant ,element ,i))))
;;; ==============================
(defun not-null (x) (not (null x)))
(defun first-or-nil (x)
"The first element of x if it is a list; else nil."
(if (consp x) (first x) nil))
(defun first-or-self (x)
"The first element of x, if it is a list; else x itself."
(if (consp x) (first x) x))
;;; ==============================
;;;; CLtL2 and ANSI CL Compatibility
(unless (fboundp 'defmethod)
(defmacro defmethod (name args &rest body)
`(defun ',name ',args ,@body))
)
(unless (fboundp 'map-into)
(defun map-into (result-sequence function &rest sequences)
"Destructively set elements of RESULT-SEQUENCE to the results
of applying FUNCTION to respective elements of SEQUENCES."
(let ((arglist (make-list (length sequences)))
(n (if (listp result-sequence)
most-positive-fixnum
(array-dimension result-sequence 0))))
;; arglist is made into a list of args for each call
;; n is the length of the longest vector
(when sequences
(setf n (min n (loop for seq in sequences
minimize (length seq)))))
;; Define some shared functions:
(flet
((do-one-call (i)
(loop for seq on sequences
for arg on arglist
do (if (listp (first seq))
(setf (first arg)
(pop (first seq)))
(setf (first arg)
(aref (first seq) i))))
(apply function arglist))
(do-result (i)
(if (and (vectorp result-sequence)
(array-has-fill-pointer-p result-sequence))
(setf (fill-pointer result-sequence)
(max i (fill-pointer result-sequence))))))
(declare (inline do-one-call))
;; Decide if the result is a list or vector,
;; and loop through each element
(if (listp result-sequence)
(loop for i from 0 to (- n 1)
for r on result-sequence
do (setf (first r)
(do-one-call i))
finally (do-result i))
(loop for i from 0 to (- n 1)
do (setf (aref result-sequence i)
(do-one-call i))
finally (do-result i))))
result-sequence))
)
(unless (fboundp 'complement)
(defun complement (fn)
"If FN returns y, then (complement FN) returns (not y)."
#'(lambda (&rest args) (not (apply fn args))))
)
(unless (fboundp 'with-compilation-unit)
(defmacro with-compilation-unit (options &body body)
"Do the body, but delay compiler warnings until the end."
;; That way, undefined function warnings that are really
;; just forward references will not be printed at all.
;; This is defined in Common Lisp the Language, 2nd ed.
(declare (ignore options))
`(,(read-time-case
#+Lispm 'compiler:compiler-warnings-context-bind
#+Lucid 'with-deferred-warnings
'progn)
.,body))
)
;;;; Reduce
(when nil ;; Change this to T if you need REDUCE with :key keyword.
(defun reduce* (fn seq from-end start end key init init-p)
(funcall (if (listp seq) #'reduce-list #'reduce-vect)
fn seq from-end (or start 0) end key init init-p))
(defun reduce (function sequence &key from-end start end key
(initial-value nil initial-value-p))
(reduce* function sequence from-end start end
key initial-value initial-value-p))
(defun reduce-vect (fn seq from-end start end key init init-p)
(if (null end) (setf end (length seq)))
(assert (<= 0 start end (length seq)) (start end)
"Illegal subsequence of ~a --- :start ~d :end ~d"
seq start end)
(case (- end start)
(1 (if init-p
(funcall fn init (funcall-if key (aref seq start)))
(funcall-if key (aref seq start))))
(0 (if init-p init (funcall fn)))
(t (if (not from-end)
(let ((result
(if init-p
(funcall
fn init
(funcall-if key (aref seq start)))
(funcall
fn
(funcall-if key (aref seq start))
(funcall-if key (aref seq (+ start 1)))))))
(loop for i from (+ start (if init-p 1 2))
to (- end 1)
do (setf result
(funcall
fn result
(funcall-if key (aref seq i)))))
result)
(let ((result
(if init-p
(funcall
fn
(funcall-if key (aref seq (- end 1)))
init)
(funcall
fn
(funcall-if key (aref seq (- end 2)))
(funcall-if key (aref seq (- end 1)))))))
(loop for i from (- end (if init-p 2 3)) downto start
do (setf result
(funcall
fn
(funcall-if key (aref seq i))
result)))
result)))))
(defun reduce-list (fn seq from-end start end key init init-p)
(if (null end) (setf end (length seq)))
(cond ((> start 0)
(reduce-list fn (nthcdr start seq) from-end 0
(- end start) key init init-p))
((or (null seq) (eql start end))
(if init-p init (funcall fn)))
((= (- end start) 1)
(if init-p
(funcall fn init (funcall-if key (first seq)))
(funcall-if key (first seq))))
(from-end
(reduce-vect fn (coerce seq 'vector) t start end
key init init-p))
((null (rest seq))
(if init-p
(funcall fn init (funcall-if key (first seq)))
(funcall-if key (first seq))))
(t (let ((result
(if init-p
(funcall
fn init
(funcall-if key (pop seq)))
(funcall
fn
(funcall-if key (pop seq))
(funcall-if key (pop seq))))))
(if end
(loop repeat (- end (if init-p 1 2)) while seq
do (setf result
(funcall
fn result
(funcall-if key (pop seq)))))
(loop while seq
do (setf result
(funcall
fn result
(funcall-if key (pop seq))))))
result))))
)
(pushnew "auxfns" *paip-modules* :test 'equal)