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 name...so 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

Jun-2022: Post moved here from the thread remarking on Kaj's Meta Project

I looked to see if there were any updates on Kaj's Meta project, and it looks like he is kind of focusing on porting existing Atari 2600 demos written in assembly to the language.

There the usual debate on the Atari forum of people talking about why languages succeed or not, asking and trying to get at why anyone would care about Rebol, expressing skepticism that Kaj will strike gold...but he says it's successful even if he just uses it and it gives him a "competitive edge".

If you're interested you can read the threads:

One thing I noticed is that he has chosen to go with FIRST-OF instead of just FIRST. I've questioned this before, because things like NEXT and FIRST are useful variable names. In Ren-C there would be presumably no hyphen, so you could write:

first: first of block

Similar to how you can today say:

type: type of block

This is because OF quotes its left argument, with the idea that this is learnable.

You could of course still say:

first: specialize :of [property: 'first]

Which is actually how it works today.

4 Likes

I think I'm okay saying that people who do this kind of thing can pick a helpers lib that specializes FIRST and LAST and such.

But in the core, these make more sense to leave undefined.

The only thing really blocking me at this point is that I don't have an answer to how these things that extend OF get registered. But this is another epicycle of the many unanswered things about function/method dispatch in the language.

I feel like hacking it in wouldn't put us in that much worse of a position than we are already... and it would free up these terms for variables in the common case.