The desire to turn --
into a form of comment, joins some of the spirit of wanting to take ==
away from strict equality. And we've even been discussing if there's something about ++
that makes its variants seem more like "drawing lines out of symbols" than really what Rebol wants to canonize as a somewhat niche operator.
This leaves us with the question of how to increment or decrement variables without having to mention their name twice:
number-of-variants: number-of-variants + 1
For historical perspective, Rebol did this with ++ number-of-variants
...though it was a late and controversial addition, in 2007. That might make sense to a C programmer, but it doesn't really have any semiotic basis in Rebol lore. One thing is that it's not totally clear that something is getting assigned. Another problem is that you don't really get a way to increment by anything besides 1.
Ren-C gained the ability to quote left hand sides, so we tried number-of-variants: ++ 1
. It was a step up, and permitted modifications by values other than 1.
But, we now want number-of-variants: -- 1
to make the 1 a comment. So another solution is needed.
number-of-variants: += 1
has seemed sort of even lamer than ++, given that = is not used for assignment at all. It is familiar, however, and should be mentioned as a possibility. And it might not be so bad: x: -= 1
might be read as "alter x such that it is equal to 1 less than it is now" as opposed to seeing the = as being there because it's an assignment operator...after all, you have the X: to suggest assignment.
In any case, we could make an operator that's generic in this sense. So number-of-variants: op + 1
, the OP would quote the SET-WORD! on the left, fetch its value, then quote the right to get a FUNCTION!. It would make the fetched value the first argument...evaluating afterward to get the second argument. It's hard to give this thing a good short English name... I suggested me
, as in number-of-variants: me + 1
. Odd, but a symbolic name would kind of start chipping away at Rebol's aesthetic.
(I whimsically suggested a variant to use with prefix functions as being MY, so block: my append [1 2 3]
would act as block: append block [1 2 3]
)
But while a very useful tool, ME and MY are suboptimal names. We might wonder if we can do better. One thing that's not completely out of the question would be just e.g. number-of-variants: - 1
. It looks a little bit close to number-of-variants: -1
, but Rebol is a language of space significance and that's something people have to live with anyway. Here's a sample broken implementation of the + operator that does this:
+: enfix function [:a [<end> any-value!] b [any-value! <...>]] [
case [
maybe [set-word! set-path!] :a [ ;-- `x: + 10` => `x: x + 10`
set a add (get a) (take b)
]
set? 'a [ ;-- `x + y` => `add x y`
add (reduce :a) (take b)
]
] else [ ;-- nothing on left, switch to variadic sum
sum: 0
while [not tail? b] [
sum: add sum (take b)
]
]
]
It looks promising when you try it:
>> 10 + 20
== 30
>> x: 10
>> x: + 20
== 30
>> x
== 30
>> (+ 10 20 30)
== 60
The only problem with it is that it has two competing demands on it when interacting with other infix math ops. When you write 2 * 3 + 4
, Rebol's rule of precedence is such that the 2 * 3
must be evaluated before the addition. Yet since we're accomplishing our trick with quoting the left, it's not currently possible to defer to decide if we want to quote the SET-WORD! or not. A left quote can't be delayed on enfix, so you get the 3... not the evaluative 6.
But due to the state of the evaluator at that moment, it's not impossible. It's just something the evaluator needs to be modified to allow. Basically, to say that you're interested in SET-WORD! or SET-PATH! but only if they're literally there on the left, otherwise acquire the parameter as normal. We might call these <set>
annotated parameters, the way you might say <end>
or <opt>
.
Is it worth it? I don't know. Every little piece of complexity like this is a tradeoff. And looking at x: - 1
meaning "subtract one from x" may not actually be that great. The average reader would assume that if it meant anything besides an error, it meant "make x negative 1".
Just putting it all out there to summarize the current state of things and see if anyone has any better ideas. I might go ahead and write me
and my
just so they're around in case someone comes up with a better name for them.