De-Verbification: NOUN OF X vs. NOUN X ?

Recently I made the same mistake several times, naming variables things like first, last, head or tail when those are verbs in historical Rebol. One case was porting some unrelated C code which named a variable "first". The other case was just repeating some habits from inside the interpreter implementation, where you can freely call things "head" or "tail".

This led me to wonder how much value there is in saying head x vs. head of x. It's pretty easy to type the latter, and the flow is reasonably natural.

Here's a line of historical code from CLEAN-PATH, which is a "heavy use case" of those functions:

if all [#"/" = last out #"/" <> last file] [
    remove back tail out

Today we can make that flow more nicely:

all [#/ = last out | #/ <> last file] then [
    remove back tail out

Now imagine that we rigged it up so that you had to use OF. I think even in this heavy usage case it's not so bad...arguably clearer:

all [#/ = last of out | #/ <> last of file] then [
    remove back of tail of out

I think it's reasonable to say that if you're working on series a lot somewhere, you might find it convenient to shorten the notation...but as POINTFREE gets more convenient, maybe you could set those kinds of shorthands up as:

last: <- last of _
tail: <- tail of _
back: <- back of _

The key here is asking if these shorthands are really the ones you want; or might it be more empowering to leave more words free in global space (especially ones that are more obviously nouns).

I've mentioned that it's becoming second nature these days to write things like first: first of x without blinking. It feels like we'd be better off going this route.

There's some technical questions here, about expanding the "OF-context". Things like FIRST and SECOND are specializations set up in usermode of PICK. So how do you put these specializations in where OF can find them? This suggests OF is picking out of an extensible scope of property accessors. Maybe if things work out with dualism of actions and objects, the context could have the same you could just say:

>> of.first: <- pick _ 1

>> first of [a b c]
== a

Pushing on such approaches seems crucial to the problem of modules and contention for short words...

I like the brevity of the current behaviour.
For example
head of [a b c]
means to me: a
head [a b c] means put the series index at the beginning.
Some things are just the way they are in Rebol, and yes we all suffer from the occasional oversight of words that are already taken and now overwritten by the new definition. Especially when converting stuff from other examples and languages this can happen (a lot) but that could hold true for a translation toward many other languages from such a source as well.
When you aim to do (more) automatic conversions (to keep up with upgrades in the original source) you might be inclined to smoothen this process, but a variable name like 'first' could also get renamed by the original devs to 'start' and last could become 'exit' (and for langs that use exit think 'quit').
What it comes down to is you have freed up this gem, for the sole purpose to please OTHER languages.

And another point one can make is, first is a bad name, first what?

I'd need to think about this. I quite like OF in these simple examples, but when I read at code like this (in a script from from Bohdan Lechnowsky), and think about adding OFs, I'm not so sure:

days: head remove back tail insert head copy system/locale/days last system/locale/days

I would never write something that looks like this snippet, but I can understand what might lead someone to write this.

1 Like