Why isn't there "number plus" postfix syntax for more than or equal?

151 views
Skip to first unread message

anon notmyfault64

unread,
Apr 23, 2020, 11:48:13 AM4/23/20
to golang-nuts
Hello,

Many times outside programming we use "number plus" postfix syntax to denote more than or equal, for example:

a 99+

But why isn't there such syntax above in all programming languages, including Go? That is, why does following code not compile with invalid syntax error?

var r int = 18

if r 13+ {
    fmt
.Println("Hooray! We are teen! We can do anything!")
} else {
    fmt
.Println("Oh No! We are still child, so we need parental control!")
}


Ian Lance Taylor

unread,
Apr 23, 2020, 12:43:32 PM4/23/20
to anon notmyfault64, golang-nuts
I don't see the advantage over writing r >= 13.

It's not useful for a programming language to have multiple ways of
writing the exact same thing. Of course, any language does have
multiple ways of doing some things, but there is should always be a
reason for it. I don't see a reason for this one.

For what it's worth, I'm not familiar with the "a 99+" notation. I
would not know what that meant without an explanation.

Ian

Michael Jones

unread,
Apr 23, 2020, 2:42:25 PM4/23/20
to Ian Lance Taylor, anon notmyfault64, golang-nuts
You could extend the notation:

If r 13+- {
  // if r is close to 13, in a handwavy sense
  :
}

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWm5jaEa36FMqLaea22BTB_WwZOsZpwrW1ei1N_KN64eg%40mail.gmail.com.
--
Michael T. Jones
michae...@gmail.com

Dan Kortschak

unread,
Apr 23, 2020, 6:05:22 PM4/23/20
to Michael Jones, Ian Lance Taylor, anon notmyfault64, golang-nuts
I look forward to the addition of the definition of "in a handwavy
sense" to the spec.

Rob Pike

unread,
Apr 23, 2020, 8:04:23 PM4/23/20
to Dan Kortschak, Michael Jones, Ian Lance Taylor, anon notmyfault64, golang-nuts
if r == 13 despiteallobjections { ... }

-rob


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

anon notmyfault64

unread,
Apr 23, 2020, 9:31:48 PM4/23/20
to golang-nuts
In this context, this number plus syntax short-circuit more than or equal, so

a 99+

is same as

a >= 99


Michael Jones

unread,
Apr 24, 2020, 10:44:46 AM4/24/20
to anon notmyfault64, golang-nuts
Hi “Anon”,

A more serious answer (though just personal opinion) is that your idea lacks the “grammar” that it implies. 

Value Relationship Value “a >= 99”

is a “sentence” or fragment in most computer languages. It is a logical assertion that is either true or false and can be composed into larger sentences in that grammar. 

99 <= a && a <= 123 

What your “value range” notion is saying is not just “99 or more” but also “is in the range of 99 or more”. The “in the range of” is implied in addition to the + as “or more”.

a 99+

It feels empty of the relationship even if 99+ has the range meaning. Compare:

a in 99+

That feels clearer to me. Both concepts are now made explicit. The language Pascal has ranges and a membership clause. ADA also embraced some of it. We could imagine:

a in 99..
a in 99..123

The “in” part feels important to me. 

Michael


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

Scott Pakin

unread,
Apr 24, 2020, 2:29:09 PM4/24/20
to golang-nuts
On Friday, April 24, 2020 at 8:44:46 AM UTC-6, Michael Jones wrote:
That feels clearer to me. Both concepts are now made explicit. The language Pascal has ranges and a membership clause. ADA also embraced some of it. We could imagine:

a in 99..
a in 99..123

The “in” part feels important to me. 

Python's chained comparison operators are arguably more compatible with the existing Go syntax and semantics, though:

99 <= a <= 128

— Scott
Reply all
Reply to author
Forward
0 new messages