File: defaggregate.lisp

package info (click to toggle)
acl2 8.3dfsg-2
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 309,408 kB
  • sloc: lisp: 3,311,842; javascript: 22,569; cpp: 9,029; ansic: 7,872; perl: 6,501; xml: 3,838; java: 3,738; makefile: 3,383; ruby: 2,633; sh: 2,489; ml: 763; python: 741; yacc: 721; awk: 260; csh: 186; php: 171; lex: 154; tcl: 49; asm: 23; haskell: 17
file content (683 lines) | stat: -rw-r--r-- 22,030 bytes parent folder | download
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
; Standard Utilities Library
; Copyright (C) 2008-2014 Centaur Technology
;
; Contact:
;   Centaur Technology Formal Verification Group
;   7600-C N. Capital of Texas Highway, Suite 300, Austin, TX 78731, USA.
;   http://www.centtech.com/
;
; License: (An MIT/X11-style license)
;
;   Permission is hereby granted, free of charge, to any person obtaining a
;   copy of this software and associated documentation files (the "Software"),
;   to deal in the Software without restriction, including without limitation
;   the rights to use, copy, modify, merge, publish, distribute, sublicense,
;   and/or sell copies of the Software, and to permit persons to whom the
;   Software is furnished to do so, subject to the following conditions:
;
;   The above copyright notice and this permission notice shall be included in
;   all copies or substantial portions of the Software.
;
;   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
;   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;   DEALINGS IN THE SOFTWARE.
;
; Original author: Jared Davis <jared@centtech.com>

; Tests for defaggregate utility.  Consider moving tests from the bottom of
; defaggregate.lisp into this file.

(in-package "STD")

(include-book "../defaggregate")
(include-book "../deflist")
(include-book "std/testing/assert" :dir :system)

(encapsulate
 ()
 (defun foof-p (x)
   (declare (xargs :guard t))
   (keywordp x))

 (defmacro foom-p (x)
   `(keywordp ,x))

 (defaggregate containerf
   (thing)
   :require ((foof-p-of-containerf->thing
              (foof-p thing)))
   :tag :containerf)

 (defaggregate containerm
   (thing)
   :require ((foom-p-of-containerm->thing
              (foom-p thing)))
   :tag :containerm))

(mutual-recursion
 (DEFUND FOO-P (X)
   (DECLARE (XARGS :GUARD T))
   (AND (CONSP X)
        (EQ (CAR X) :FOO)
        (ALISTP (CDR X))
        (CONSP (CDR X))
        (LET ((BAR (CDR (ASSOC 'BAR (CDR X)))))
             (DECLARE (IGNORABLE BAR))
             (AND (FOO-LIST-P BAR)))))

 (DEFUND FOO-LIST-P (X)
   (DECLARE (XARGS :GUARD T
                   :NORMALIZE NIL
                   :VERIFY-GUARDS T
                   :GUARD-DEBUG NIL
                   :GUARD-HINTS NIL))
   (IF (CONSP X)
       (AND (FOO-P (CAR X))
            (FOO-LIST-P (CDR X)))
       (NULL X))))

(std::defaggregate foo
  (bar)
  :require ((foo-list-p-of-foo->bar
             (foo-list-p bar)))
  :already-definedp t
  :tag :foo)

(std::deflist foo-list-p (x)
  (foo-p x)
  :elementp-of-nil nil
  :already-definedp t
  :true-listp t)

(std::defaggregate pair-o-ints
  ((left integerp "Left part of pair")
   (right integerp "Right part of pair"))
  :tag :pair-o-ints)

(defund sum-a-pair (x)
  (declare (xargs :guard (pair-o-ints-p x)))
  (b* (((pair-o-ints x) x)
       (- (cw "left is ~x0~%" x.left))
       (- (cw "right is ~x0~%" x.right)))
    (+ x.left x.right)))

(assert! (equal (sum-a-pair (make-pair-o-ints :left 4 :right 5)) 9))

#||

(logic)

(defaggregate taco
    (shell meat cheese lettuce sauce)
    :legiblep :ordered
    :tag :taco
    :require ((integerp-of-taco->shell (integerp shell)
                                       :rule-classes ((:rewrite) (:type-prescription))))
    :long "<p>Additional documentation</p>"
    )

(defaggregate htaco
    (shell meat cheese lettuce sauce)
    :tag :taco
    :hons t
    :require ((integerp-of-htaco->shell (integerp shell)))
    :long "<p>Additional documentation</p>"
    )

(defaggregate untagged-taco
    (shell meat cheese lettuce sauce)
    :tag nil
    :hons t
    :require ((integerp-of-untagged-taco->shell (integerp shell)))
    :long "<p>Additional documentation</p>"
    )


;;  Basic binding tests

(b* ((?my-taco (make-taco :shell 5
                          :meat 'beef
                          :cheese 'swiss
                          :lettuce 'iceberg
                          :sauce 'green))
     ((taco x) my-taco)
     (five (+ 2 3)))
    (list :shell x.shell
          :lettuce x.lettuce
          :five five
          :my-taco my-taco))


;; I'd like something like this, but it looks like the b* machinery wants
;; at least one form.
;;
;; (b* ((?my-taco (make-taco :shell 5
;;                           :meat 'beef
;;                           :cheese 'swiss
;;                           :lettuce 'iceberg
;;                           :sauce 'green))
;;      ((taco my-taco))
;;      (five (+ 2 3)))
;;     (list :my-taco.shell my-taco.shell
;;           :my-taco.lettuce my-taco.lettuce
;;           :five five
;;           :my-taco my-taco))

(b* (((taco x)
      ;; Previously failed due to using keywords with the same names as
      ;; variables, but now we properly avoid keywords.
      (make-taco :shell 5
                 :meat 'beef
                 :cheese 'swiss
                 :lettuce 'iceberg
                 :sauce 'green))
     (five (+ 2 3)))
    (list :x.shell x.shell
          :x.lettuce x.lettuce
          :five five))

(b* (((taco x y)
      ;; Improper binding... fails nicely
      (make-taco :shell 5
                 :meat 'beef
                 :cheese 'swiss
                 :lettuce 'iceberg
                 :sauce 'green))
     (five (+ 2 3)))
    (list :x.shell x.shell
          :x.lettuce x.lettuce
          :five five))

(b* (((taco x)
      ;; Unused binding collapses to nothing.  Nicely creates a warning.
      (make-taco :shell 5
                 :meat 'beef
                 :cheese 'swiss
                 :lettuce 'iceberg
                 :sauce 'green))
     (five (+ 2 3)))
    five)

(b* (((taco x :quietp t)
      ;; Unused binding collapses to nothing.  Quiet suppresses warning.
      (make-taco :shell 5
                 :meat 'beef
                 :cheese 'swiss
                 :lettuce 'iceberg
                 :sauce 'green))
     (five (+ 2 3)))
    five)

;; Previously this failed because we were using ACL2::|(IDENTITY FOO)| as a
;; variable.  We no longer do that.  Now, instead, it should fails because
;; ACL2::|(IDENTITY FOO)| is unbound.  See also acl2-books Issue 41.
(b* ((foo (make-taco :shell 5
                     :meat 'beef
                     :cheese 'swiss
                     :lettuce 'iceberg
                     :sauce 'green))
     ((taco x) (identity foo))
     (bad      ACL2::|(IDENTITY FOO)|)
     (five     (+ 2 3)))
    (list :x.shell x.shell
          :x.lettuce x.lettuce
          :five five
          :bad bad))

||#


(defsection test-of-tree-layout

  (defaggregate employee
    :tag :employee
    ((name stringp "some documentation")
     (salary natp :rule-classes :type-prescription :default 25))
    :layout :tree
    :short "Hello!")

  (assert! (b* ((emp (make-employee :name "foo")))
             (and (equal (employee->name emp) "foo")
                  (equal (employee->salary emp) 25))))

  ;; Shouldn't give a bind-warning
  (assert! (b* ((emp (make-employee :name "foo"))
                ((employee emp) emp))
             (and (equal emp.name "foo")
                  (equal emp.salary 25))))

  ;; No warning -- same name.
  (assert! (b* ((emp (make-employee :name "foo"))
                ((employee emp) emp))
             (and (equal emp.name "foo")
                  (equal emp.salary 25)
                  emp)))

  ;; This was prohibited through the release of ACL2 6.5, but now it is allowed
  ;; and works as expected; see Issue 41.
  (assert! (b* ((emp (make-employee :name "foo"))
                ((employee emp2) emp))
             (and (equal emp2.name "foo")
                  (equal emp2.salary 25)
                  emp2)))

  ;; Similarly is now supported
  (assert! (b* (((employee emp2) (make-employee :name "foo")))
             (and (equal emp2.name "foo")
                  (equal emp2.salary 25)
                  emp2)))

  (assert! (b* ((emp (make-employee :name "foo"))
                ((employee emp) (change-employee emp :name "bar")))
             (and (equal emp.name "bar")
                  (equal emp.salary 25))))

  (assert! (b* ((?emp (make-employee :name "foo"))
                ((employee emp) (change-employee emp
                                                 :name "bar"
                                                 :salary 156)))
             (and (equal emp.name "bar")
                  (equal emp.salary 156)))))


(defsection test-of-honsed-tree-layout

  (defaggregate h-employee
    :tag :h-employee
    ((name stringp "some documentation")
     (salary natp :rule-classes :type-prescription :default 25))
    :layout :tree
    :hons t
    :short "Hello!")

  (assert! (b* ((emp (make-h-employee :name "foo")))
             (and (equal (h-employee->name emp) "foo")
                  (equal (h-employee->salary emp) 25))))

  ;; Shouldn't give a bind-warning
  (assert! (b* ((emp (make-h-employee :name "foo"))
                ((h-employee emp) emp))
             (and (equal emp.name "foo")
                  (equal emp.salary 25))))

  ;; No warning -- same name.
  (assert! (b* ((emp (make-h-employee :name "foo"))
                ((h-employee emp) emp))
             (and (equal emp.name "foo")
                  (equal emp.salary 25)
                  emp)))

  ;; This was prohibited through the release of ACL2 6.5, but now it is allowed
  ;; and works as expected; see Issue 41.
  (assert! (b* ((emp (make-h-employee :name "foo"))
                ((h-employee emp2) emp))
             (and (equal emp2.name "foo")
                  (equal emp2.salary 25)
                  emp2)))

  ;; Similarly is now supported
  (assert! (b* (((h-employee emp2) (make-h-employee :name "foo")))
             (and (equal emp2.name "foo")
                  (equal emp2.salary 25)
                  emp2)))

  (assert! (b* ((emp (make-h-employee :name "foo"))
                ((h-employee emp) (change-h-employee emp :name "bar")))
             (and (equal emp.name "bar")
                  (equal emp.salary 25))))

  (assert! (b* ((?emp (make-h-employee :name "foo"))
                ((h-employee emp) (change-h-employee emp
                                                 :name "bar"
                                                 :salary 156)))
             (and (equal emp.name "bar")
                  (equal emp.salary 156)))))


(defsection test-of-fulltree

  (defaggregate employee2
    :tag :employee2
    ((name stringp "some documentation")
     (salary natp :rule-classes :type-prescription :default 25))
    :layout :tree
    :short "Hello!")

  (assert! (b* ((emp (make-employee2 :name "foo")))
             (and (equal (employee2->name emp) "foo")
                  (equal (employee2->salary emp) 25))))

  ;; Shouldn't give a bind-warning
  (assert! (b* ((emp (make-employee2 :name "foo"))
                ((employee2 emp) emp))
             (and (equal emp.name "foo")
                  (equal emp.salary 25))))

  ;; No warning -- same name.
  (assert! (b* ((emp (make-employee2 :name "foo"))
                ((employee2 emp) emp))
             (and (equal emp.name "foo")
                  (equal emp.salary 25)
                  emp)))

  ;; This was prohibited through the release of ACL2 6.5, but now it is allowed
  ;; and works as expected; see Issue 41.
  (assert! (b* ((emp (make-employee2 :name "foo"))
                ((employee2 emp2) emp))
             (and (equal emp2.name "foo")
                  (equal emp2.salary 25)
                  emp2)))

  ;; Similarly is now supported
  (assert! (b* (((employee2 emp2) (make-employee2 :name "foo")))
             (and (equal emp2.name "foo")
                  (equal emp2.salary 25)
                  emp2)))

  (assert! (b* ((emp (make-employee2 :name "foo"))
                ((employee2 emp) (change-employee2 emp :name "bar")))
             (and (equal emp.name "bar")
                  (equal emp.salary 25))))

  (assert! (b* ((?emp (make-employee2 :name "foo"))
                ((employee2 emp) (change-employee2 emp
                                                   :name "bar"
                                                   :salary 156)))
             (and (equal emp.name "bar")
                  (equal emp.salary 156)))))


(defsection test-of-fulltree

  (defaggregate h-employee2
    :tag :h-employee2
    ((name stringp "some documentation")
     (salary natp :rule-classes :type-prescription :default 25))
    :layout :tree
    :hons t
    :short "Hello!")

  (assert! (b* ((emp (make-h-employee2 :name "foo")))
             (and (equal (h-employee2->name emp) "foo")
                  (equal (h-employee2->salary emp) 25))))

  ;; Shouldn't give a bind-warning
  (assert! (b* ((emp (make-h-employee2 :name "foo"))
                ((h-employee2 emp) emp))
             (and (equal emp.name "foo")
                  (equal emp.salary 25))))

  ;; No warning -- same name.
  (assert! (b* ((emp (make-h-employee2 :name "foo"))
                ((h-employee2 emp) emp))
             (and (equal emp.name "foo")
                  (equal emp.salary 25)
                  emp)))

  ;; This was prohibited through the release of ACL2 6.5, but now it is allowed
  ;; and works as expected; see Issue 41.
  (assert! (b* ((emp (make-h-employee2 :name "foo"))
                ((h-employee2 emp2) emp))
             (and (equal emp2.name "foo")
                  (equal emp2.salary 25)
                  emp2)))

  ;; Similarly is now supported
  (assert! (b* (((h-employee2 emp2) (make-h-employee2 :name "foo")))
             (and (equal emp2.name "foo")
                  (equal emp2.salary 25)
                  emp2)))

  (assert! (b* ((emp (make-h-employee2 :name "foo"))
                ((h-employee2 emp) (change-h-employee2 emp :name "bar")))
             (and (equal emp.name "bar")
                  (equal emp.salary 25))))

  (assert! (b* ((?emp (make-h-employee2 :name "foo"))
                ((h-employee2 emp) (change-h-employee2 emp
                                                   :name "bar"
                                                   :salary 156)))
             (and (equal emp.name "bar")
                  (equal emp.salary 156)))))



(defsection test-of-list

  (defaggregate employee3
    :tag :employee3
    ((name stringp "some documentation")
     (salary natp :rule-classes :type-prescription :default 25))
    :layout :list
    :short "Hello!")

  (assert! (b* ((emp (make-employee3 :name "foo")))
             (and (equal (employee3->name emp) "foo")
                  (equal (employee3->salary emp) 25))))

  ;; Shouldn't give a bind-warning
  (assert! (b* ((emp (make-employee3 :name "foo"))
                ((employee3 emp) emp))
             (and (equal emp.name "foo")
                  (equal emp.salary 25))))

  ;; No warning -- same name.
  (assert! (b* ((emp (make-employee3 :name "foo"))
                ((employee3 emp) emp))
             (and (equal emp.name "foo")
                  (equal emp.salary 25)
                  emp)))

  ;; This was prohibited through the release of ACL2 6.5, but now it is allowed
  ;; and works as expected; see Issue 41.
  (assert! (b* ((emp (make-employee3 :name "foo"))
                ((employee3 emp2) emp))
             (and (equal emp2.name "foo")
                  (equal emp2.salary 25)
                  emp2)))

  ;; Similarly is now supported
  (assert! (b* (((employee3 emp2) (make-employee3 :name "foo")))
             (and (equal emp2.name "foo")
                  (equal emp2.salary 25)
                  emp2)))

  (assert! (b* ((emp (make-employee3 :name "foo"))
                ((employee3 emp) (change-employee3 emp :name "bar")))
             (and (equal emp.name "bar")
                  (equal emp.salary 25))))

  (assert! (b* ((?emp (make-employee3 :name "foo"))
                ((employee3 emp) (change-employee3 emp
                                                   :name "bar"
                                                   :salary 156)))
             (and (equal emp.name "bar")
                  (equal emp.salary 156)))))


(defsection test-of-alist

  (defaggregate employee4
    :tag :employee4
    ((name stringp "some documentation")
     (salary natp :rule-classes :type-prescription :default 25))
    :layout :alist
    :short "Hello!")

  (assert! (b* ((emp (make-employee4 :name "foo")))
             (and (equal (employee4->name emp) "foo")
                  (equal (employee4->salary emp) 25))))

  ;; Shouldn't give a bind-warning
  (assert! (b* ((emp (make-employee4 :name "foo"))
                ((employee4 emp) emp))
             (and (equal emp.name "foo")
                  (equal emp.salary 25))))

  ;; No warning -- same name.
  (assert! (b* ((emp (make-employee4 :name "foo"))
                ((employee4 emp) emp))
             (and (equal emp.name "foo")
                  (equal emp.salary 25)
                  emp)))

  ;; This was prohibited through the release of ACL2 6.5, but now it is allowed
  ;; and works as expected; see Issue 41.
  (assert! (b* ((emp (make-employee4 :name "foo"))
                ((employee4 emp2) emp))
             (and (equal emp2.name "foo")
                  (equal emp2.salary 25)
                  emp2)))

  ;; Similarly is now supported
  (assert! (b* (((employee4 emp2) (make-employee4 :name "foo")))
             (and (equal emp2.name "foo")
                  (equal emp2.salary 25)
                  emp2)))

  (assert! (b* ((emp (make-employee4 :name "foo"))
                ((employee4 emp) (change-employee4 emp :name "bar")))
             (and (equal emp.name "bar")
                  (equal emp.salary 25))))

  (assert! (b* ((?emp (make-employee4 :name "foo"))
                ((employee4 emp) (change-employee4 emp
                                                   :name "bar"
                                                   :salary 156)))
             (and (equal emp.name "bar")
                  (equal emp.salary 156)))))




(defaggregate m0 (a b c))

(assert! (let ((topic (xdoc::find-topic 'm0-p (xdoc::get-xdoc-table (w state)))))
           (and topic
                (equal (cdr (assoc :parents topic))
                       '(acl2::undocumented)))))

(xdoc::set-default-parents foo bar)

(defaggregate m1 (a b c))

(assert! (let ((topic (xdoc::find-topic 'm1-p (xdoc::get-xdoc-table (w state)))))
           (and topic
                (equal (cdr (assoc :parents topic))
                       '(foo bar)))))

(defaggregate m2 (a b c) :parents (bar))

(assert! (let ((topic (xdoc::find-topic 'm2-p (xdoc::get-xdoc-table (w state)))))
           (and topic
                (equal (cdr (assoc :parents topic))
                       '(bar)))))

(defaggregate pancake
  :tag :pancake
  ((syrup  booleanp)
   (butter booleanp)
   (sugar  natp))
  :extra-binder-names (messy)
  :layout :tree
  :verbosep t)

(define pancake->messy ((x pancake-p))
  (and (pancake->syrup x)
       (pancake->butter x)))

(define pancake-info ((x pancake-p))
  (b* (((pancake x)))
    (acl2::msg "syrupy: ~x0 buttery: ~x1 messy: ~x2~%"
               x.syrup x.butter x.messy))
  ///
  (assert!
   (equal (pancake-info (make-pancake :syrup t :butter nil :sugar 5))
          (acl2::msg "syrupy: ~x0 buttery: ~x1 messy: ~x2~%" t nil nil))))


(defaggregate student
  ((firstname stringp)
   (lastname  stringp)
   (grade     natp))
  :layout :fulltree
  :extra-binder-names (fullname))

(define student->fullname ((x student-p))
  :returns (fullname stringp :rule-classes :type-prescription)
  (concatenate 'string
               (student->firstname x)
               " "
               (student->lastname x)))

(assert! (equal (b* ((fred (make-student :firstname "Fredrick"
                                         :lastname "Flintstone"
                                         :grade 7))
                     ((student fred)))
                  (concatenate 'string
                               "Fred's full name is " fred.fullname "."))
                "Fred's full name is Fredrick Flintstone."))


#||

(defun test (emp n new-name)
  (declare (xargs :guard (and (employee-p emp)
                              (natp n)
                              (stringp new-name))))
  (if (zp n)
      nil
    (test (change-employee emp :name new-name)
          (- n 1)
          new-name)))

(let ((name "billy bob"))
  ;; 320,110 bytes allocated
  (time$ (test (make-employee :name name  :salary 13) 10000 name)))

(let ((name "billy bob"))
  ;; 112 bytes allocated
  (time$ (test (make-employee :name name  :salary 13) 10000 name)))

||#


(assert!
 ;; Test for name capture of the thing being changed
 (b* ((grade (make-student :firstname "foo" :lastname "bar" :grade 6))
      (new   (change-student grade :firstname "blah")))
   (and (equal (student->grade new) (student->grade grade))
        (equal (student->lastname new) (student->lastname grade))
        (equal (student->firstname new) "blah")
        (equal (student->firstname grade) "foo"))))

(define change-test ((grade student-p))
  ;; Test of a tricky name-capture situation.
  ;; Note that "grade" is the name of one of the student's fields.
  ;; We once had a name capture problem where we translated this into
  ;;
  ;; (LET ((FIRSTNAME "blah")
  ;;       (LASTNAME (STUDENT->LASTNAME GRADE))
  ;;       (GRADE (STUDENT->GRADE GRADE)))
  ;;    (MBE :LOGIC (STUDENT FIRSTNAME LASTNAME GRADE)
  ;;         :EXEC (REMAKE-STUDENT GRADE FIRSTNAME LASTNAME GRADE)))
  ;;
  ;; Note that the (REMAKE-STUDENT GRADE FIRSTNAME LASTNAME GRADE) call above
  ;; makes no sense at all.  To avoid this we reworked the way the change macro
  ;; expands to avoid capture.
  (change-student grade :firstname "blah"))


;; Added by Alessandro Coglio (coglio@kestrel.edu).
(defsection test-of-pred-option

  (defaggregate point
    ((x integerp)
     (y integerp))
    :pred pointp)

  (assert! (pointp (point 3 2))))