commit 8141d02
chld
·
2026-08-15 18:31:01 +0000 UTC
parent f12c699
modify list-sort to return a list create a full target list
M
Makefile
+1,
-2
1@@ -2,8 +2,7 @@ x: a b
2 a: c
3 b:
4 c:
5-
6-ekfjheik
7+ echo "you reached c target good"
8
9 goon: green
10 green: hi
M
test.scm
+16,
-3
1@@ -1,4 +1,5 @@
2-(use-modules (util))
3+(use-modules (util)
4+ (srfi srfi-1))
5
6 ;; a needs c so put it first
7 ;; a then put a
8@@ -6,6 +7,7 @@
9 ;; then x
10 ;; c -> a -> b -> x
11
12+(define t-list '())
13 (define m-list '())
14 (define f-list (file-read "Makefile"))
15
16@@ -18,8 +20,19 @@
17 (display m-list)
18 (newline)(newline)
19
20-(list-sort (car (list-ref m-list 0)) m-list)(newline)
21-(list-sort "goon" m-list)
22+;; (list-sort (car (list-ref m-list 0)) m-list)(newline)
23+;; (list-sort "goon" m-list)
24+
25+(do ((i 0 (+ i 1)))
26+ ((>= i (length m-list)))
27+ (set! t-list (append t-list
28+ (list-sort (car (list-ref m-list i)) m-list)
29+ t-list
30+ ))
31+ )
32+(set! t-list (delete-duplicates t-list equal?))
33+(display t-list)
34+;; => (1 2 3 4 5)
35
36 ;; (display (list-ref (list-ref (list-ref m-list 0) 1) 0))
37
M
util.scm
+12,
-3
1@@ -24,7 +24,16 @@
2 (string-split ds #\space))))
3 (list t d)))
4
5+
6 (define (list-sort t l)
7- (let ((ds (cadr (assoc t l))))
8- (for-each (lambda (dep) (list-sort dep l)) ds)
9- (format #t "~a\n" t)))
10+ (let ((s '()) (r '()))
11+
12+ (define (visit t)
13+ (if (not (member t s))
14+ (begin (let ((e (assoc t l)))
15+ (if e (for-each visit (cadr e))))
16+ (set! s (cons t s))
17+ (set! r (cons t r)))))
18+
19+ (visit t)
20+ (reverse r)))