REBOL 3.0

Do we dare add ++ and -- ?

Carl Sassenrath, CTO
REBOL Technologies
7-Feb-2007 20:30 GMT

Article #0057
Main page || Index || Prior Article [0056] || Next Article [0058] || 41 Comments || Send feedback

Here's a question to think about for 3.0. (I'm sure I asked this before, but let's revisit it again).

Do we dare add the C-style ++ and -- functions as a standard part of REBOL 3.0?

 Advantagea handy shortcut used by most C programmers.
 Disadvantagemodifies a word without using the SET-WORD notation (of course, you can already do that in REBOL) and adds noise to expressions (looks like an infix operator, but is not -- see examples at end).

Examples:

count: 0
++ count ; add one
-- count ; sub one

Notes:

  1. increments or decrements value by one
  2. returns the new value
  3. could also be allowed for series values to change index position
  4. only prefix. No postfix form (e.g. n ++).
  5. function precedence, same as negate. (Makes it less useful in non paren expressions.)

Example of last point, this is not valid:

if ++ count > 10 [...]

Just like you cannot write:

if negate count > 10 [...]

You either need to use prefix, reverse the comparison, or paren it:

if greater? ++ count 10 [...]
if 10 <= ++ count [...]
if (++ count) > 10 [...]

So, there you are. Useful or not useful as a standard part of REBOL? Tell us.

41 Comments

REBOL 3.0
Updated 18-Nov-2017 - Edit - Copyright REBOL Technologies - REBOL.net