File: immutable-containers.lisp

package info (click to toggle)
cl-containers 20170403-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,072 kB
  • ctags: 1,387
  • sloc: lisp: 8,341; makefile: 14
file content (36 lines) | stat: -rw-r--r-- 935 bytes parent folder | download | duplicates (4)
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

(in-package #:containers)

(defclass* immutable-keys-mixin ()
  "Keys may not be added or changed after the container is created."
  ((allow-mutation? nil ia))
  (:export-p t)
  :export-slots)


(defmethod item-at! :around ((container immutable-keys-mixin) 
                             value &rest indexes)
  (declare (dynamic-extent indexes))
  (when (and (completely-created? container)
             (not (allow-mutation? container)))
    (unless (key-exists-p container indexes)
      (error 'key-does-not-exist-error)))
  (call-next-method)
  value)


#|

(lift:deftestsuite test-immutable-keys-mixin ()
  ())

(lift:addtest (test-immutable-keys-mixin)
  foo
  (let ((c (make-container '(immutable-keys-mixin alist-container))))
    (lift:ensure-error (setf (item-at c :a) 2))))

(lift:addtest (test-immutable-keys-mixin)
  bar
  (let ((c (make-container '(alist-container))))
    (lift:ensure-error (setf (item-at c :a) 2))))
|#