This is something that always leaves me a bit stumped, the equivalent of Ruby’s
../, when joining with an absolute path it uses that, and it respects the OS path name separator (less of interest to me but nice to have).
> Pathname('/he/lo/world').join('../foo/bar') => #<Pathname:/he/lo/foo/bar> > Pathname('/he/lo/world').join('/var/www/foo/bar') => #<Pathname:/var/www/foo/bar>
Clojure itself has nothing like it AFAIK. I’m ok with falling back to Java, but the closest I could find,
java.nio.file.Paths/get is a variadic method, meaning interop gets awkward. (you have to give it a java array). It also doesn’t resolve
../ unless you
normalize, so this is what I ended up using.
(defn path-join [p & ps] (str (.normalize (java.nio.file.Paths/get p (into-array String ps)))))
How do other people do this? Or do just… not do this?