Challenge 1: Concatenating [a, b] and [c, d, e] via Difference Lists — Possible Solution ==================================================================== dl_demo.pl: dl_concat(A-B, B-C, A-C). Query: ?- L1 = [a, b | H1], DL1 = L1-H1, L2 = [c, d, e | H2], DL2 = L2-H2, dl_concat(DL1, DL2, Combined-H2), H2 = []. L1 = [a, b, c, d, e], DL1 = [a, b, c, d, e]-[], H1 = [c, d, e], L2 = [c, d, e], DL2 = [c, d, e]-[], H2 = [], Combined = [a, b, c, d, e]. Explanation: DL1 represents the open list [a, b | H1], DL2 represents the open list [c, d, e | H2]. dl_concat(DL1, DL2, Combined-H2) unifies H1 (the first list's hole) with L2 itself, so L1 becomes [a, b, c, d, e | H2] without walking or copying a single element -- notice L1 itself changes as a side effect of the unification, since H1 was a shared variable inside it all along. The final step, H2 = [], closes the remaining open tail, turning Combined into the ordinary, fully closed list [a, b, c, d, e]. WHY THIS WORKS AS AN ANSWER ------------------------------ This builds two difference lists exactly per the chapter's own List-Hole representation, concatenates them with dl_concat/3 as defined, and explicitly closes the result by unifying the final hole with [], producing the expected ordinary five-element list.