Since (somewhere in) Python 3 there is the Path infix operator /. I think this is one of the prettiest things existing in Python 3.
Python 3.6.7
>>> from pathlib import Path
>>> Path('foo') / 'bar'
PosixPath('foo/bar')
>>> 'foo' / Path('bar')
PosixPath('foo/bar')
In practice this results to code looking like process(datasets / 'trees' / 'pineapple.tsv'). Since Julia partly aims at scripting and being easy to use I think this would be a great addition to the Julia language.
Would it be possible to link the infix /operator to joinpath in the Julia language? I'm aware that creating custom infix operators is possible and that Julia does not have a type for paths. The latter meaning that the infix operator would be coupled to all AbstractStrings. In case one of these or other arguments make the idea infeasible, feel free to close the issue.
Have you seen https://github.com/rofinn/FilePathsBase.jl? This allows you to do exactly this using the same operator as is used for infix string concatination, *.
We should not pun on / by making it mean both division and joinpath. Note, however, that if you in your own code want to use / for this it's a simple as doing this:
julia> const / = joinpath
joinpath (generic function with 4 methods)
julia> "foo" / "bar" / "baz"
"foo/bar/baz"
Of course, then you can't also use / for division but that may be inadvisable. If you really want both, you can do this instead:
julia> a/b = Base.:/(a, b)
/ (generic function with 2 methods)
julia> a::String/b::String = joinpath(a, b)
/ (generic function with 2 methods)
julia> 1/2
0.5
julia> "foo"/"bar"/"baz"
"foo/bar/baz"
Most helpful comment
We should not pun on
/by making it mean both division andjoinpath. Note, however, that if you in your own code want to use/for this it's a simple as doing this:Of course, then you can't also use
/for division but that may be inadvisable. If you really want both, you can do this instead: