The NewPath Finesse: %%: (<- MAKE FILE! LIT)

When I first proposed NewPath years ago, there was resistance to the idea that FILE! have structure by default. @rgchris insisted %foo/bar was best left unstructured and string-like. Compromises were suggested like (%foo)/bar to get a PATH!, but this did not satisfy anyone really. So things just kind of sat around in a stuck state for a while.

But I persisted in believing that hammering out a clean PATH! and TUPLE! mechanic would pay dividends with time. Today we have those clean types and are sorting through the implications.

A lot of great ideas are coming out of the sky this week, and here is what I think is poised to be another great one:

%% Quotes WORD!/PATH!/TUPLE! for MAKE FILE!

Let's imagine that %% is given to WORD!, and defaults to an operator which quotes its right hand side and makes a file out of it.

>> %% foo/bar
== %foo/bar

>> %% foo/(second [bar baz])
== %foo/baz

>> extension: %txt
>> %% ~/projects/myfile.(extension)
== %~/projects/myfile.txt

If what you have is a PATH! already you can escape it with colon:

>> path: 'foo/(reverse "rab").txt
>> %% :path
== %foo/bar.txt

This form probably is more comprehensible as make file! path, however.

Why Double-Percent Instead of Single?

Superbig reason: Single percent would lead to ambiguity of %/foo as a FILE! and as a PATH!.

One might think of workarounds like (:%)/foo to call a refinement on a function, and think that might be okay. But the moment you do a COMPOSE on a PATH! with something you think is a valid WORD! and wind up with something that molds like a file, it's sacrificed all the work on coherence that has been done.

That reason alone would be good enough. But the visibility is much better with the double operator, while the single one kind of disappears:

>> % foo.(if true ['txt])
== %foo.txt

>> %foo.(if true ['txt])  ; imagine matched () are allowed
== %foo.(if true ['txt])

Doubling helps keep the connotation to files while being sufficiently different to call attention to the fact that it's an extremely different quoting operator.

This sacrifices files named %% as needing to be written as %"%". In the scheme of things, I don't think that's too big a deal. Percent signs in general could be used, in %foo%4E type files...though that looks kind of strange and maybe %"foo%4E" is better, where % is considered one of those characters that warrants putting the filename in quotes.

The Breakthrough We've Been Waiting For

This seems to check all the boxes. It means we don't have to worry about making things like READ take plain PATH! or WORD! or TUPLE! in some confusing way. The notion that it takes a file is very cleanly and very directly communicated by the operator... and this is coupled with showing the exact moment at which GROUP!s will be evaluated.

3 Likes