Sujet : Re: Rather simple list/set operation [?]
De : HenHanna (at) *nospam* dev.null (HenHanna)
Groupes : comp.lang.lispDate : 09. Jun 2024, 01:23:02
Autres entêtes
Organisation : novaBBS
Message-ID : <7c221443e88c02df44ab3b4716708ef9@www.novabbs.com>
References : 1
User-Agent : Rocksolid Light
B. Pym wrote:
From: Drew Krause
Subject: rather simple list/set operation
Date: Tue, 3 Jan 2012 19:01:19 -0600
Drew Krause wrote:
Maybe someone can help me with this? I start with a list, e.g. ((0) (1 3) (1 2) (4 6) (5 7) (7 8))
and want all members of intersecting lists to appear in the same
sublist:
=> ((0) (1 2 3) (4 6) (5 7 8))
Gauche Scheme:
(use srfi-1) ; "lset-" functions
(use srfi-42) ; do-ec
(define (coalesce lists)
(define accum '())
(do-ec (:list x lists)
(receive
(miss hit)
(partition (lambda (y) (null? (lset-intersection equal? x y)))
accum)
(set! accum
(cons (apply lset-union equal? x hit) miss))))
accum)
(coalesce '((2 4) (8 9) (4 5 8)))
===>
((2 9 4 5 8))
(coalesce '((2 4) (3 9) (5 6) (2 3)))
===>
((4 9 2 3) (5 6))
(coalesce '((0) (1 3) (1 2) (4 6) (5 7) (7 8)))
===>
((5 7 8) (4 6) (3 1 2) (0))
(coalesce '((2 4) (3 9) (5 6) (2 3) (55 66) (0) (66 6)))
===>
((5 55 66 6) (0) (4 9 2 3))
Do-ec and Receive often go together?
Is there a set of programs (or Problems) or Tutorial for this style of
programming?
Transitive closure constructs the output graph from the
input graph. In computer science, the concept of transitive closure can be thought of
as constructing a data structure that makes it possible to answer
reachability questions.