Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #385559

Re: Interval Comparisons

From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c
Subject Re: Interval Comparisons
Date 2024-06-04 14:04 -0700
Organization None to speak of
Message-ID <878qzk1kts.fsf@nosuchdomain.example.com> (permalink)
References <v3merq$b1uj$1@dont-email.me> <v3ml0d$bpds$5@dont-email.me> <v3mlrb$c7d5$1@dont-email.me>

Show all headers | View raw


Mikko <mikko.levanto@iki.fi> writes:
> On 2024-06-04 08:58:53 +0000, David Brown said:
>> On 04/06/2024 09:14, Lawrence D'Oliveiro wrote:
>>> Would it break backward compatibility for C to add a feature like this
>>> from Python? Namely, the ability to check if a value lies in an interval:
>>> def valid_char(c) :
>>> "is integer c the code for a valid Unicode character." \
>>> " This excludes surrogates."
>>> return \
>>> (
>>> 0 <= c <= 0x10FFFF
>>> and
>>> not (0xD800 <= c < 0xE000)
>>> )
>>> #end valid_char
>> Do you mean, could C treat "a <= x <= b" as "(a <= x) && (x <= b)" 
>> without breaking existing code?  The answer is no, C treats it as
>> the expression "(a <= x) <= b".  So you would be changing the
>> meaning of existing C code.  I think it's fair to say there is
>> likely to be very little existing correct and working C code that
>> relies on the current interpretation of such expressions, but the
>> possibility is enough to rule out such a change ever happening in C.
>> (And it would also complicate the grammar a fair bit.)
>> 
>> <https://c-faq.com/expr/transitivity.html>
>
> That does not prevet from doing the same with a different syntax.
> The main difference is that in the current C syntax that cannot be
> said without mentioning c twice. In the example program C would
> require that c is mentioned four times but the shown Python code
> only needs it mentioned twice. An ideal syntax woult only mention
> it once, perhaps
>
>  return c in 0 .. 0xD7FF, 0xE000 .. 0x10FFFF ;
>
> or
>
>  return c : [0 .. 0xD800), [0xE000 .. 0x10FFFF] ;
>
> or something like that, preferably so that no new reserved word is
> needed.

Relatedly, gcc has case ranges as an extension, and there's a proposal
to add them to C2Y (Y=6?):
<https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3269.htm>

The gcc feature uses the existing "..." token rather than "..".  I'm not
sure whether using ".." would have caused problems beyond the need to
introduce a new token.

One minor issue, whether the feature uses ".." or "...", is that "1...2"
is a valid preprocessing number (and not a valid literal) so
`c in 1...2` would result in a syntax error.  You just need to add
spaces: `c in 1 ... 2` (which I'd argue is a good idea anyway).

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Interval Comparisons Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-06-04 07:14 +0000
  Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-04 10:58 +0200
    Re: Interval Comparisons Mikko <mikko.levanto@iki.fi> - 2024-06-04 12:13 +0300
      Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-04 13:02 +0200
        Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-04 12:23 +0100
          Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-04 15:24 +0200
            Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-04 15:16 +0100
              Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-04 17:40 +0200
            Re: Interval Comparisons scott@slp53.sl.home (Scott Lurndal) - 2024-06-04 15:27 +0000
              Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-04 16:58 +0100
                Re: Interval Comparisons Michael S <already5chosen@yahoo.com> - 2024-06-04 19:25 +0300
                Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-04 17:54 +0100
          Re: Interval Comparisons Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-06-05 03:29 +0000
        Re: Interval Comparisons Mikko <mikko.levanto@iki.fi> - 2024-06-04 16:11 +0300
      Re: Interval Comparisons Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-06-04 15:42 +0200
      Re: Interval Comparisons Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-04 14:04 -0700
  Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-04 11:39 +0100
  Re: Interval Comparisons Thiago Adams <thiago.adams@gmail.com> - 2024-06-04 08:32 -0300
    Re: Interval Comparisons Bonita Montero <Bonita.Montero@gmail.com> - 2024-06-04 13:37 +0200
    Re: Interval Comparisons Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-04 15:29 -0700
  Re: Interval Comparisons Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> - 2024-06-04 11:41 +0000
    Re: Interval Comparisons Michael S <already5chosen@yahoo.com> - 2024-06-04 15:17 +0300
    Re: Interval Comparisons Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-06-04 23:12 +0000
      Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-05 00:22 +0100
        Re: Interval Comparisons Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-06-05 01:30 +0000
          Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-06 19:48 +0100
            Re: Interval Comparisons Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-06-06 22:54 +0000
              Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-07 01:52 +0100
                Re: Interval Comparisons Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-06-07 02:17 +0000
                Re: Interval Comparisons Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-06 20:53 -0700
                Re: Interval Comparisons Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-06-07 04:25 +0000
                Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-07 11:22 +0200
                Re: Interval Comparisons Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-07 02:55 -0700
                Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-07 13:04 +0200
                Re: Interval Comparisons Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-07 11:57 -0700
                Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-08 17:42 +0200
                Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-07 11:28 +0100
                Re: Interval Comparisons Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-06-07 10:45 +0000
                Re: Interval Comparisons Michael S <already5chosen@yahoo.com> - 2024-06-07 14:51 +0300
                Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-07 13:17 +0200
                Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-07 13:20 +0100
                Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-09 13:26 +0200
                Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-10 16:33 +0100
                Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-10 17:56 +0200
                Re: Interval Comparisons scott@slp53.sl.home (Scott Lurndal) - 2024-06-07 14:00 +0000
                Re: Interval Comparisons Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-06-07 10:42 +0000

csiph-web