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
|
;; -*-theme-*-
;; Copyright (C) 2015 Tommi Höynälänmaa
;; Distributed under GNU General Public License version 3,
;; see file doc/GPL-3.
;; Expected results: compilation OK
;; Programs using gen-assoc in this module shall give a runtime error.
(define-body (tests test573)
(import (standard-library list-utilities))
(define-param-proc make-assoc-list (%key %value)
(()
(:assoc-list %key %value)
pure)
(create (:assoc-list %key %value) null))
(define-static-param-virtual-method gen-assoc (%key %value)
(((al (:assoc-list %key %value)) (obj-key %key))
(:maybe %value)
pure)
(assert (equal? 1 2))
(let ((obj-assoc (assoc-general obj-key (field-ref al 'l-contents)
null equal?)))
(if (not-null? obj-assoc)
(let ((obj1 (cast (:pair %key (:singleton %value)) obj-assoc)))
(singleton-get-element (cdr obj1)))
null)))
(define-static-param-virtual-method gen-assoc-set! (%key %value)
(((al (:assoc-list %key %value))
(obj-key %key)
(obj-value %value))
<none>
nonpure)
(let ((obj-assoc (gen-assoc al obj-key)))
(if (not-null? obj-assoc)
(let ((obj1 (cast (:pair %key (:singleton %value)) obj-assoc)))
(singleton-set-element! (cdr obj1) obj-value))
(let* ((sgt (make-singleton obj-value))
(binding (cons obj-key sgt)))
(field-set! al 'l-contents
(cons binding (field-ref al 'l-contents))))))))
|