Deutsch   English   Français   Italiano  
<v3t0aa$1k8ck$2@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bart <bc@freeuk.com>
Newsgroups: comp.lang.c
Subject: Re: Interval Comparisons
Date: Thu, 6 Jun 2024 19:48:42 +0100
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <v3t0aa$1k8ck$2@dont-email.me>
References: <v3merq$b1uj$1@dont-email.me>
 <pan$63fde$3c88716e$c61af1ee$d0a27c97@invalid.invalid>
 <v3o706$kfrm$2@dont-email.me> <v3o7jr$ki9u$1@dont-email.me>
 <v3of4h$pbb1$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 06 Jun 2024 20:48:43 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b02ee27fe84d0707205a15f2e6befadb";
	logging-data="1712532"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19rF//1hXsYO8HEZeJ6njp8"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:JQy0EtIQOuMHglkMKHjzKOWDTKo=
In-Reply-To: <v3of4h$pbb1$1@dont-email.me>
Content-Language: en-GB
Bytes: 2926

On 05/06/2024 02:30, Lawrence D'Oliveiro wrote:
> On Wed, 5 Jun 2024 00:22:36 +0100, bart wrote:
> 
>> On 05/06/2024 00:12, Lawrence D'Oliveiro wrote:
>>
>>> On Tue, 4 Jun 2024 11:41:54 -0000 (UTC), Blue-Maned_Hawk wrote:
>>>
>>>> i think that we need not worsen the matter with new ternary operators.
>>>
>>> These are not ternary operators.
>>
>> So what are they?
> 
> A special case in the syntax rules for the comparison operators
> <https://docs.python.org/3/reference/expressions.html#comparisons>.
> 
>> I've implemented them several times, and found they really need to be
>> treated as a special kind of n-ary opterator.
> 
> Remember, Python allows users to define custom overloads for the standard
> operators. For comparisons, these functions always take two operands, and
> the compiler takes care of invoking them correctly to handle interval
> comparisons.


Well, for these 3 lines in my scripting language:


   if a = b then end             # universal
   if a = b < c then end         # chained (like Python, unlike C)
   if (a = b) < c then end       # emulate C behaviour

These are the ASTs produced (2: is the empty True branch; 3: would be 
for the 'else' branch, not present here):

- 1 if:
- - 1 eq:
- - - 1 name: a
- - - 2 name: b
- - 2 block:

- 1 if:
- - 1 cmpchain: eq lt
- - - 1 name: a
- - - 1 name: b
- - - 1 name: c
- - 2 block:

- 1 if:
- - 1 lt:
- - - 1 eq:
- - - - 1 name: a
- - - - 2 name: b
- - - 2 name: c
- - 2 block:

Notice the middle one is one linear group with N operands and N-1 
comparisons.

No operator overloads are allowed, but if they were, it would still 
work, but a comparison operator would be required to return True or 
False from its two operands. It would be unwise for it to return a 
string for example.