#;2> (topological-sort
'((i am)
(not trying)
(confuse the)
(am trying)
(trying to)
(am not)
(trying the)
(to confuse)
(the issue))
eqv?)
(not i am trying to confuse the issue)
Ordering the sublists in this way may make it more clear what the correct output should be:
(i am)
(am not)
(not trying)
(trying to)
(to confuse)
(am trying)
(confuse the)
(trying the)
(the issue)
It seems that the order ought to be:
i am not trying to confuse the issue
Is this a bug, or am I missing something?
---- Edit: ----
Combining sublists with common heads:
(topological-sort
'((i am)
(not trying)
(confuse the)
(am trying not)
(trying to the)
(to confuse)
(the issue))
eqv?)
(i am not trying to confuse the issue)
So it seems the proper approach is to preprocess the input to make sure that no two sublists share the same head.
Solving the Rosetta Code topological sort problem:
(use srfi-1) ; list operators
(use srfi-69) ; hash-tables
(define data
'((des_system_lib std synopsys std_cell_lib des_system_lib dw02 dw01 ramlib ieee)
(dw01 ieee dw01 dware gtech)
(dw02 ieee dw02 dware)
(dw03 std synopsys dware dw03 dw02 dw01 ieee gtech)
(dw04 dw04 ieee dw01 dware gtech)
(dw05 dw05 ieee dware)
(dw06 dw06 ieee dware)
(dw07 ieee dware)
(dware ieee dware)
(gtech ieee gtech)
(ramlib std ieee)
(std_cell_lib ieee std_cell_lib)
(synopsys)))
(define table (make-hash-table))
(for-each
(lambda (xs)
(let ((head (car xs)) (tail (cdr xs)))
(for-each
(lambda(key)
(when (not (eqv? key head))
(hash-table-update!/default
table key (lambda (accum) (cons head accum)) '())))
tail)))
data)
(define answer
(topological-sort (hash-table->alist table) eqv?))
answer
One possible result (because hash-tables are unordered, it may be different each time):
(std ieee dware dw05 dw06 dw07 ramlib std_cell_lib gtech synopsys
dw02 dw01 des_system_lib dw03 dw04)
Attempting to validate the answer:
(any
(lambda (tail)
(any
(lambda (key)
(and (hash-table-exists? table key)
(member (car tail) (hash-table-ref table key))))
(cdr tail)))
(reverse (pair-fold cons '() answer)))
#f
It seems to be correct.
Yes, it is a known bug: