# RFC: Source-relative paths & expression-level "comments"

**URL:** <https://discourse.julialang.org/t/rfc-source-relative-paths-expression-level-comments/49799>\
**Category:** Internals & Design\
**Created:** [November 8, 2020, 5:46pm UTC](https://discourse.julialang.org/t/rfc-source-relative-paths-expression-level-comments/49799 "2020-11-08T17:46:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [November 8, 2020, 5:46pm UTC](https://discourse.julialang.org/t/rfc-source-relative-paths-expression-level-comments/49799/1 "2020-11-08T17:46:50Z")

</div>

Hi, I am not certain this is the appropriate forum for this - or if I should just be making a PR. I’m not part of the Julia dev team (don’t know the procedure).

I realized it might be nice to have two small macros added to Julia’s library:

- Something to “expand” source-relative paths.
- Something to quickly disable a multi-line expression

### Source-relative paths:

Mostly copied from `@ __DIR__ `:

```julia
macro srelpath(filepath)
	__source__.file === nothing &&
		return throw("Cannot find source-relative path")
	_dirname = dirname(String( __source__.file))
	_dirname = isempty(_dirname) ? pwd() : abspath(_dirname)
	return joinpath(_dirname, filepath)
end

```

This would allow one to more easily pass a source-relative (instead of cwd-relative) path to functions in other modules, for example:

```julia
data = readdlm(@srelpath("delim_file.txt"), '\t', Int, '\n')

```

It is basically just a shorthand (following other `*path()` functions) for the following:

```julia
data = readdlm(joinpath(@ __DIR__ , "delim_file.txt"), '\t', Int, '\n')

```

It is a small change, but I think it slightly improves readability.

### Quick expression-level diable:

```julia
macro X(ex); return nothing; end

```

Very simple, but it would allow one to quicly disable multi-line expressions such as a function definition or large data declarations (alternative to `#= [...] =#`):

```julia
@X function MyFun()
	println("Running...")
end

@X b = Dict(
	:a => 54,
	:b => 7,
	:c => 11,
	:d => 22,
)

```

Again, it is only a small change from encasing with `#= [...] =#`, but I think it is (sufficiently) often easier to disable/enable an expression by prepending something instead of encasing it with `#= [...] =#`.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 9, 2020, 1:21pm UTC](https://discourse.julialang.org/t/rfc-source-relative-paths-expression-level-comments/49799/3 "2020-11-09T13:21:37Z")

</div>

> [@MA\_Laforge](#):
>
> if I should just be making a PR. I’m not part of the Julia dev team (don’t know the procedure).

The procedure is [documented](https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md), and you can make a PR without being part of the dev team (just fork), but there is no reason why this functionality couldn’t just live in a package.

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [November 9, 2020, 6:54pm UTC](https://discourse.julialang.org/t/rfc-source-relative-paths-expression-level-comments/49799/4 "2020-11-09T18:54:43Z")

</div>

Thanks. I forgot about that page!

Agreed, it could just live in a package - I just don’t want to create a bunch of elemental packages, each for a single macro (as an example). And if I bundle them all in a poorly themed “MyUsefulAddons” packages, I will likely be its only user.

So I might have just ventured onto a pointless exercise here. Thanks for the pointer, though. I will try to remember the CONTRIBUTING.md page in the future!

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [November 9, 2020, 7:16pm UTC](https://discourse.julialang.org/t/rfc-source-relative-paths-expression-level-comments/49799/5 "2020-11-09T19:16:50Z")

</div>

> [@MA\_Laforge](#):
>
> elemental packages

reading the above made my mind go

> Water, Earth, Fire, Air. Long ago, the four nations lived together in harmony. Then, everything changed when the Fire Nation attacked. Only the **Avatar** , master of all four elements, could stop them, but when the world needed him most, he vanished. A hundred years passed and …

I think you meant _elementary_.

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [November 9, 2020, 9:55pm UTC](https://discourse.julialang.org/t/rfc-source-relative-paths-expression-level-comments/49799/6 "2020-11-09T21:55:36Z")

</div>

🙂

Funny. Just made me realize I don’t really know the difference between “elemental” and “elementary”.  
 → [ELEMENTAL Definition & Meaning - Merriam-Webster](https://www.merriam-webster.com/dictionary/elemental)  
 → [ELEMENTARY Definition & Meaning - Merriam-Webster](https://www.merriam-webster.com/dictionary/elementary)

### TLDR;

Apparently you are correct if I used elemental as a noun.

But as an adjective, it appears elemental is appropriate because it refers to a package that encapsulates a _single_ element:

> 1 a **:** of, relating to, or being an [element](https://www.merriam-webster.com/dictionary/element)

OTOH, “elementary” seems like it refers to something being “basic” (in its simplest form):

> 1 a **:** of, relating to, or dealing with the simplest [elements](https://www.merriam-webster.com/dictionary/elements) or principles of something

But I did like the quote nonetheless 🙂. Very visual.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [November 9, 2020, 10:04pm UTC](https://discourse.julialang.org/t/rfc-source-relative-paths-expression-level-comments/49799/7 "2020-11-09T22:04:15Z")

</div>

> [@MA\_Laforge](#):
>
> But I did like the quote nonetheless 🙂. Very visual.

It is imprinted in the mind of many of my generation as [it was played before every episode of “Avatar: the last airbender”](https://www.youtube.com/watch?v=d1EnW4kn1kg).

But good to know that elemental may be used this way. English is not my first language, and “elemental” probably got in my vocabulary from D&D so I never questioned myself about other uses.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 10, 2020, 7:36am UTC](https://discourse.julialang.org/t/rfc-source-relative-paths-expression-level-comments/49799/8 "2020-11-10T07:36:12Z")

</div>

> [@MA\_Laforge](#):
>
> elemental packages, each for a single macro (as an example)

I find some packages that _implement one thing and do it well_ very useful, eg

> **[GitHub - mauro3/UnPack.jl: \`@pack!\` and \`@unpack\` macros](https://github.com/mauro3/UnPack.jl)**
>
> \`@pack!\` and \`@unpack\` macros. Contribute to mauro3/UnPack.jl development by creating an account on GitHub.

> **[GitHub - jw3126/ArgCheck.jl: Package for checking function arguments](https://github.com/jw3126/ArgCheck.jl)**
>
> Package for checking function arguments. Contribute to jw3126/ArgCheck.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [November 10, 2020, 8:56pm UTC](https://discourse.julialang.org/t/rfc-source-relative-paths-expression-level-comments/49799/9 "2020-11-10T20:56:28Z")

</div>

@Tamas_Papp: And to a certain extent, I sort of agree. I myself implemented NumericIO (which is just to provide better control over writing out floating point values using more readable formatting (ex: 2×10² for 2e2 or 50μ for 5e-6):  
[https://github.com/ma-laforge/NumericIO.jl](https://github.com/ma-laforge/NumericIO.jl)

I was also hesitant in publishing a over simple package at that time, but it ended up being a good idea. (Though I should revisit it - I have issues with the API, etc).

But am disliking the idea of having to start all of my “scripts” with a block like:

```julia-auto
using Unpack
using ArgCheck
using SourceRelativePaths
using ExpressionDisable
using FieldDefaults
using Parameters
using Reexport
using NumericIO

#Finally, code starts here...

```

### It might be ok, though

I suppose I _could_ package those up in a personal “JuliaExtensions\_MA” package to create my own version of “core julia”.

I’ll have to think about that. If I find it practical, then I might just agree with you @Tamas_Papp.

### Lingering concerns

I suppose this creates an artificial little mental block for myself because macros like `@X` seem sort of obscure if they are not part of the language, so using it increases learning time for other developers - especially if everyone implements slightly different versions.

- So I tend to avoid using modules like Parameters.jl or even Reexport.jl.
- I assume people avoid using NumericIO.jl for similar reasons.

But I must admit, my reasoning is not necessarily a rational one.
