Skip to content

Instantly share code, notes, and snippets.

@sogaiu
Last active December 23, 2025 03:47
Show Gist options
  • Select an option

  • Save sogaiu/59bd2522c38044da0ad9985d5cd22ab8 to your computer and use it in GitHub Desktop.

Select an option

Save sogaiu/59bd2522c38044da0ad9985d5cd22ab8 to your computer and use it in GitHub Desktop.
(defn diff-path
[left right]
(var i 0)
(var done false)
(def [shorter longer]
(if (<= (length left) (length right))
[left right]
[right left]))
(for j 0 (length shorter)
(when (not= (get left j) (get right j))
(set done true)
(set i j)
(break)))
(cond
(not done)
[shorter (string/slice longer (length shorter))]
#
(= 0 i)
["" nil]
#
[(string/slice shorter 0 i) ""]))
(comment
(diff-path "/usr/include"
"/usr/include/fstab.h")
# =>
["/usr/include" "/fstab.h"]
(diff-path "/tmp" "hello")
# =>
["" nil]
(diff-path "/etc/motd" "/etc/issue")
# =>
["/etc/" ""]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment