The Question of Plain-old-? (and plain old !)

At pretty much the outset of Ren-C, the ? was taken away from HELP.

The reason is that when you think about how rare short character sequences are in a language, it seems unwise to take them for something that you'd only type in the console. You would not use a ? help command in the middle of your code. And the few cases where you might want to deliberately invoke help it seems like you could just bite the bullet and type h-e-l-p.

So question was if there was some interesting broader use for ? in the language as a whole, some way you would use it in the line of writing a program. Similar questions might be asked about !, which Ren-C deliberately took away from being a synonym for NOT.

There are a lot of options, with enfix and postfix, variadics and other conventions. Yet nothing particularly satisfying has come up. What's been tried?

prefix SET? QUOTE

Usually, ? at the end of a word means it's asking a question--returning a LOGIC!--based on that word. But if there's no word, what's the question?

The most existential implicit question of all in Rebol is probably whether something is a value or not. But rather than ? being a synonym for value?, it could be set? quote, so ? foo would be a shorthand for set? 'foo.

I've never used it because, it's always made me uneasy:

if ? foo [print "foo is set"]
if not ? foo [print "foo is not set"]

if set? 'foo [print "foo is set"]
if unset? 'foo [print "foo is not set"]

It's "cleaner" but I'd hardly call it "clearer". And maybe it's my C bias, but it just looks like an infix operator. Something about if not ? foo makes me feel like the ? is splitting the left from the right, and it "sees" the if not somehow. ? is postfix in English, infix in most programming languages, it certainly doesn't feel right as prefix because it's "at the end of some invisible word"

It's been there, but I've not been compelled to start using it. I'm pretty sure this is a no, so I'm going to delete it.

postfix VALUE?

if select block thing ? [
    print "thing was in block, maybe a falsey thing"
]

This just ends up feeling weird for the sake of weird. "Hey, question marks are postfix in English, wouldn't it be weird if a ? operator that wasn't attached to a word of its own became postfix in Rebol?"

There are better ways of conditionally reacting to nulls, which are more pleasing and general:

 select block thing also [
    print "thing was in block, maybe a falsey thing
 ]

Ternary Operator

This is the first suggestion that comes to mind for most people. Because in C, C++, Java, JavaScript, Ruby and who knows how many other languages, ? is the left hand side of the ternary operator so condition ? branch1 : branch2.

While ? and ! were considered, the ?? and !! were chosen because they stand out more:

>> compose [
    (condition1 ?? [a b])
    c d
    (condition2 ?? [d e] !! [f g])
 ]

Two characters feels a bit heftier and more intentional, for something that's "at least as big as a 2-letter IF is"

>> compose [
    (condition1 ? [a b])
    c d
    (condition2 ? [d e] ! [f g])
 ]

The philosophy of choosing this doubling instead of going with something more slight comes from @draegtun by way of Perl6. It seems sound to me, and I wonder what others think--if they've tried it.

If ?? and !! are kept as it is (I've come to quite like them) it does suggest that maybe whatever ? and ! do be related to that, as a pairing. They could even be synonyms, and then people choose based on their tastes.

Breakpoint

This is an interesting idea that could be applied to either ? or !. They might even be slightly different shades of breakpoint.

Though I've mentioned the idea of ... acting as a sort of "placeholder breakpoint". You could use it as a kind of "TBD" in code, and if it were ever hit, it might prompt you for what you want put there. Then it might use some kind of reasoning about how to fill in what you said in the future if that point was ever hit again. So it seems to be a pretty good way to say breakpoint, if you ask me.

Leave it alone

Interestingly, Haskell allows ? to be a valid name for an operator, but doesn't define what it means in the box. It can become a ternary operator if you feel like, but you could use it for something else.

When listing short words I mentioned that it might not always be the best idea to take absolutely every name for some convention. Leaving a few to the user could be nice. What if ? weren't defined at all, and you could use it for whatever you like?

Other ideas...?


It should be noted that none of this is really contentious with using ? for help in the console. Especially the idea of leaving it alone in the language--and not taking it for anything.

But we've got a lot of creative options now. Is there some long word or useful operator that having a shorthand for would be appropriate, where ? is a good fit?