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


Groups > comp.lang.c > #162036

Re: How to disambiguate macro?

From David Brown <david.brown@hesbynett.no>
Newsgroups comp.lang.c
Subject Re: How to disambiguate macro?
Date 2021-07-22 08:47 +0200
Organization A noiseless patient Spider
Message-ID <sdb4an$56m$1@dont-email.me> (permalink)
References (9 earlier) <sd9a5q$qs0$1@dont-email.me> <87sg07k82m.fsf@bsb.me.uk> <sd9ib5$qh1$1@dont-email.me> <sd9mhe$q8b$1@dont-email.me> <sd9tkt$edf$1@dont-email.me>

Show all headers | View raw


On 21/07/2021 21:47, Bart wrote:
> On 21/07/2021 18:46, David Brown wrote:
>> On 21/07/2021 18:34, Bart wrote:
>>> On 21/07/2021 16:20, Ben Bacarisse wrote:
>>>> Bart <bc@freeuk.com> writes:
>>>>
>>>>> On 21/07/2021 14:20, Ben Bacarisse wrote:
>>>>>> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>>>>>>
>>>>>>> Neither B nor BCPL had short-circuit logical operators, relying
>>>>>>> instead
>>>>>>> on bitwise & and |, as did early C.
>>>>>> Minor correction.  B didn't have short-circuit & and | as such,
>>>>>> but it
>>>>>> had a weird rule that in conditional contexts like
>>>>>>      if (a & b) ...
>>>>>> the operator short-circuited!  C rightly ditched this contextual
>>>>>> interpretation in favour of explicitly short-circuiting operators.
>>>>>
>>>>> That's not so weird. I used to have something similar (not in C) where
>>>>> 'A and B' (ie. logical and, also 'or') short-circuited in conditional
>>>>> expressions as used in 'if' and 'while' control expressions, which
>>>>> tended to be implemented with branching.
>>>>>
>>>>> But in ordinary expressions, they didn't.
>>>>
>>>> I'm don't see how this would persuade someone that it's not weird.  A
>>>> private language is never going to be used by someone other than the
>>>> world authority on its semantics.
>>>>
>>>> In public-facing languages, such context-sensitive semantics seem to me
>>>> to be the epitome of "weird".
>>>>
>>>
>>> In BASIC, "=" was used for assignments, and "=" was also used as an
>>> equality operator.
>>>
>>> Those two contexts didn't clash, so there wasn't any confusion.
>>>
>>> It's similar with the special expression that follows if, while etc; the
>>> language can simply say that is a separate context.
>>>
>>> In my case, because control expression were expected to be full of
>>> branching anyway, but expressions had linear execution. Nowadays
>>> branchless code is fashionable.
>>
>> That makes little sense.
>>
>> In an "if", etc., your controlling expression is an expression.  In an
>> assignment, or other expression, you are using an expression.
>>
>> Are you suggesting that:
>>
>>     x = a && b;
>>
>>     if (a && b) ...
>>
>> are clearly different contexts and should have different semantics,
>> despite "a && b" being an expression in each case?
> 
> These do different things. One results in a concrete 1 or 0 boolean
> value. The other determines whether or not you jump to some label.
> 

The expressions are the same in each case.  After calculating "a && b",
they do different things with the results - but that comes /later/.

The way expressions are interpreted and evaluated is, in most languages,
independent of what you do with the results.  (The number of programming
languages is so vast that there are bound to be exceptions to almost any
rule or generalisation.)

If you write :

	int x = 4 / 3;
	float y = 4 / 3;

in most languages, you would not expect the first division to be done as
integers and the second to be done as floating point.  You would expect
consistency.  It might be consistently integer division, or consistently
floating point (and then converted to integer x and floating point y).
But you want consistency.

> 
> 
>> What about
>>
>>     if a && b     (for languages that don't need parenthesis)
>>
>> and
>>
>>     if (a && b)
>>
>> ?
>>
>> What about
>>
>>     x = a && b;
>>     if (x) ....
>>
>>
>> It's fine to have the same symbol used in different contexts - look at
>> how often commas are used in most languages.  Having an operator give
>> different meanings depending on other code around it (other than the
>> operands), is asking for trouble.
> 
> I'm not good at keeping old versions of languages. But one I've just
> tried didn't even allow && in a normal expresion. It meant having to write:
> 
>    x = a && b;
> 
> as the equivalent of:
> 
>    x = (a && b ? 1 : 0);
> 
> So here && still has one behaviour.
> 

I guess with your personal little languages, you never really have to
think about things like specifications, consistency, documentation,
compatibility, logical design, or any of these other things that concern
real languages.  You can just make things up and modify them as you go
along, changing the language tools as often as the programs written in
the language.

> But now all my languages support short-circuiting logic ops in any
> context. One idea for non-short-circuiting versions of && and || was
> dropped (I had too many features already), but it would have allowed:
> 
>   if task1() andb task2() then
>       println "Both succeeded"
>   end
> 
> Here these are independent and you want to attempt both even if the
> other failed.

Adding rarely used and cryptic operators or syntaxes is always a mistake
in a language, unless there is no other way to achieve the same goals.

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


Thread

How to disambiguate macro? John Forkosh <forkosh@panix.com> - 2021-07-20 11:15 +0000
  Re: How to disambiguate macro? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-07-20 13:49 +0100
    Re: How to disambiguate macro? John Forkosh <forkosh@panix.com> - 2021-07-20 12:56 +0000
      Re: How to disambiguate macro? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-07-20 15:36 +0100
        Re: How to disambiguate macro? John Forkosh <forkosh@panix.com> - 2021-07-21 01:48 +0000
          Re: How to disambiguate macro? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-07-20 19:18 -0700
          Re: How to disambiguate macro? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-07-20 20:27 -0700
            Re: How to disambiguate macro? John Forkosh <forkosh@panix.com> - 2021-07-21 04:15 +0000
              Re: How to disambiguate macro? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-07-21 02:00 -0700
              Re: How to disambiguate macro? James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-07-21 06:02 -0400
          Re: How to disambiguate macro? James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-07-21 06:00 -0400
            Re: How to disambiguate macro? John Forkosh <forkosh@panix.com> - 2021-07-21 10:10 +0000
              Re: How to disambiguate macro? Bart <bc@freeuk.com> - 2021-07-21 11:30 +0100
              Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-21 13:31 +0200
              Re: How to disambiguate macro? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-07-21 13:02 +0100
                Re: How to disambiguate macro? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-07-21 14:20 +0100
                Re: How to disambiguate macro? Bart <bc@freeuk.com> - 2021-07-21 15:15 +0100
                Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-21 16:28 +0200
                Re: How to disambiguate macro? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-07-21 16:20 +0100
                Re: How to disambiguate macro? Bart <bc@freeuk.com> - 2021-07-21 17:34 +0100
                Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-21 19:46 +0200
                Re: How to disambiguate macro? Manfred <noname@add.invalid> - 2021-07-21 20:42 +0200
                Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-22 08:37 +0200
                Re: How to disambiguate macro? Bart <bc@freeuk.com> - 2021-07-21 20:47 +0100
                Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-22 08:47 +0200
                Re: How to disambiguate macro? Bart <bc@freeuk.com> - 2021-07-22 11:31 +0100
                Re: How to disambiguate macro? antispam@math.uni.wroc.pl - 2021-07-22 14:37 +0000
                Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-22 18:15 +0200
                Re: How to disambiguate macro? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-07-21 21:19 +0100
                Re: How to disambiguate macro? Manfred <noname@add.invalid> - 2021-07-21 15:42 +0200
                Re: How to disambiguate macro? scott@slp53.sl.home (Scott Lurndal) - 2021-07-21 15:39 +0000
              Re: How to disambiguate macro? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-07-21 09:22 -0700
              Re: How to disambiguate macro? James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-07-21 17:24 -0400
                Re: How to disambiguate macro? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-07-21 16:42 -0700
                Re: How to disambiguate macro? John Forkosh <forkosh@panix.com> - 2021-07-22 05:49 +0000
                Re: How to disambiguate macro? James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-07-22 19:11 -0400
                Re: How to disambiguate macro? John Forkosh <forkosh@panix.com> - 2021-07-22 05:30 +0000
                Re: How to disambiguate macro? scott@slp53.sl.home (Scott Lurndal) - 2021-07-22 14:14 +0000
                Re: How to disambiguate macro? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-07-22 17:06 +0100
                OT: possessive adjectives (Was: How to disambiguate macro?) Manfred <noname@add.invalid> - 2021-07-22 15:04 +0200
                Re: OT: possessive adjectives Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-08-14 13:37 -0700
          Re: How to disambiguate macro? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-08-14 13:58 -0700
  Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-20 14:50 +0200
    Re: How to disambiguate macro? John Forkosh <forkosh@panix.com> - 2021-07-20 13:19 +0000
      Re: How to disambiguate macro? Bart <bc@freeuk.com> - 2021-07-20 14:40 +0100
        Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-20 21:02 +0200
      Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-20 21:00 +0200
      Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-21 08:15 +0200
      Re: How to disambiguate macro? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-08-14 23:17 -0700
  Re: How to disambiguate macro? John Forkosh <forkosh@panix.com> - 2021-07-20 12:51 +0000
  Re: How to disambiguate macro? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-07-20 08:47 -0700

csiph-web