Challenge 3: What Breaks When a Hole Is Closed Too Early — Possible Solution ==================================================================== dl_demo.pl: dl_concat(A-B, B-C, A-C). Query: ?- L1 = [a, b | H1], DL1 = L1-H1, H1 = [], % hole closed early, by mistake L2 = [c, d | H2], DL2 = L2-H2, dl_concat(DL1, DL2, Combined). false. -- Explanation -- -- -- After H1 = [], DL1 is no longer an open difference list at all -- -- it has become the ordinary, fully closed list [a, b]-[], since its -- own hole was bound to [] before any splicing happened. When -- dl_concat(DL1, DL2, Combined) then runs, it tries to unify DL1's -- own second component (which is now permanently [], not an -- unbound variable) with DL2's first component (the list [c, d | H2]). -- Unifying [] with [c, d | H2] fails outright -- [] and a -- non-empty list can never unify -- so the whole dl_concat call -- fails, with no useful error message pointing at H1 = [] as the -- actual root cause several lines earlier. The list [a, b] is now -- permanently sealed off; nothing can ever be spliced into it again. WHY THIS WORKS AS AN ANSWER ------------------------------ This deliberately closes a difference list's hole before attempting a second concatenation, showing the resulting dl_concat/3 call fails outright because [] can no longer unify with an incoming list, directly demonstrating the chapter's own warning about premature hole-binding silently breaking later concatenations.