Basic Werk | Blog | Contact


MEMOMEM

20130703_Gauche_memo



memo



(define *alist* '())
(define (union set1 set2) (cond ((null? set1) set2) ((member (car set1) set2) (union (cdr set1) set2)) (else (cons (car set1) (union (cdr set1) set2)))))
(define (union-alist! lst) (let ((l (assoc (car lst) *alist*))) (set! (cdr l) (list (union (cadr l) (cadr lst))))))
(define (add-alist! lst) (push! *alist* lst))
(define (add-or-union-alist! lst) (if (assoc (car lst) *alist*) (union-alist! lst) (add-alist! lst)))



(for-each (lambda (lst) (add-or-union-alist! lst)) '((a (s d f)) (b (q w e)) (a (y u i s s))))
*alist* ((b (q w e)) (a (d f y u i s s)))


#Gauche #Scheme #Lisp



SN 2013/07/03 15:20:28

Archives > 20130703_Gauche_memo.html