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
|
;; Copyright (C) 2017 Tommi Höynälänmaa
;; Expected results: translation and running OK
(define-proper-program (tests test589)
(import (standard-library core)
(standard-library console-io))
(define-param-proc assoc-set0 (%key %value)
(((al (:alist %key %value))
(x-key %key)
(x-value %value))
(:pair (:alist %key %value) <boolean>)
pure)
(match-type al
((<null>) (cons null #f))
((al1 (:nonempty-alist %key %value))
(let ((p-binding (car al1)))
(if (equal? (car p-binding) x-key)
(cons
(cons
(cons x-key x-value)
(car (assoc-set0 (cdr al1) x-key x-value)))
#t)
(let ((x (assoc-set0 (cdr al1) x-key x-value)))
(cons
(cons (car al1)
(car x))
(cdr x))))))))
(define-main-proc (() <none> nonpure)
(let ((al '((abc . 1) (def . 2) (ghi . 3))))
(console-display-line (assoc-set0 al 'jkl 5))
(console-display-line (assoc-set0 al 'def 6)))))
|