12 lines
468 B
Plaintext
12 lines
468 B
Plaintext
scommon(a, b) := block([n: min(slength(a), slength(b))],
|
|
substring(a, 1, catch(for i thru n do (
|
|
if not cequal(charat(a, i), charat(b, i)) then throw(i)), n + 1)))$
|
|
|
|
commonpath(u, [l]) := block([s: lreduce(scommon, u), c, n],
|
|
n: sposition(if length(l) = 0 then "/" else l[1], sreverse(s)),
|
|
if integerp(n) then substring(s, 1, slength(s) - n) else ""
|
|
)$
|
|
|
|
commonpath(["c:/files/banister.jpg", "c:/files/bank.xls", "c:/files/banana-recipes.txt"]);
|
|
"c:/files"
|