scm: Add assoc-set!
* module/mes/scm.mes (assoc-set!): New function. * tests/scm.test ("assoc-set!", "assoc-set! new"): New tests.
This commit is contained in:
parent
58dfe0b7bd
commit
a53e878435
|
@ -120,6 +120,12 @@
|
|||
(if entry (cdr entry)
|
||||
#f)))
|
||||
|
||||
(define (assoc-set! alist key value)
|
||||
(let ((entry (assoc key alist)))
|
||||
(if (not entry) (acons key value alist)
|
||||
(let ((entry (set-cdr! entry value)))
|
||||
alist))))
|
||||
|
||||
(define (memq x lst)
|
||||
(if (null? lst) #f ;; IF
|
||||
(if (eq? x (car lst)) lst
|
||||
|
|
|
@ -90,6 +90,8 @@ exit $?
|
|||
(pass-if "assq-set!" (sequal? (assq-set! '((b . 1)) 'a 0) '((a . 0) (b . 1))))
|
||||
(pass-if "assq-set! 2" (sequal? (assq-set! '((a . 0)) 'a 1) '((a . 1))))
|
||||
(pass-if "assoc" (sequal? (assoc '(a . 0) '((a . 0) (b . 1) ((a . 0) aa))) '((a . 0) aa)))
|
||||
(pass-if-equal "assoc-set!" '((a . 0) (b . 2)) (assoc-set! '((a . 0) (b . 1)) 'b 2))
|
||||
(pass-if-equal "assoc-set! new" '((b . 2) (a . 0)) (assoc-set! '((a . 0)) 'b 2))
|
||||
|
||||
(pass-if "builtin? car" (builtin? car))
|
||||
(pass-if "builtin? cdr" (builtin? cdr))
|
||||
|
|
Loading…
Reference in a new issue