• Re: why &| dont work and its possible to make it work

    From fir@3:633/10 to All on Wed Sep 9 13:28:51 2026
    bart pisze:
    On 09/09/2026 08:14, Lawrence D?Oliveiro wrote:
    On Mon, 7 Sep 2026 16:42:13 +0100, bart wrote:

    I think 'A && B' is equivalent to '(!!A ? 1 : (!!B ? 1 : 0))', if a
    boolean result is needed.

    Why not just

    ÿÿÿÿ A ? B ? true : false : false

    Yes, that's better, and more correct. I think mine implemented OR not
    AND, and I also decided not to test it.

    I used !! because I was aiming towards needing to use & and | but that didn't happen (!!A & !!B would be non-short-circuiting).


    i think probably in simple cases when you dont acll functions etc

    like if(a<2 & b>7)

    .. im not sure though but if compiler has optimising block it is rather
    useles to calc b>7

    & probably be short-circuiting anyway
    In any case, this is very different from A & B.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From fir@3:633/10 to All on Wed Sep 9 14:01:05 2026
    fir pisze:
    bart pisze:
    On 09/09/2026 08:14, Lawrence D?Oliveiro wrote:
    On Mon, 7 Sep 2026 16:42:13 +0100, bart wrote:

    I think 'A && B' is equivalent to '(!!A ? 1 : (!!B ? 1 : 0))', if a
    boolean result is needed.

    Why not just

    ÿÿÿÿ A ? B ? true : false : false

    Yes, that's better, and more correct. I think mine implemented OR not
    AND, and I also decided not to test it.

    I used !! because I was aiming towards needing to use & and | but that
    didn't happen (!!A & !!B would be non-short-circuiting).


    i think probably in simple cases when you dont acll functions etc

    like if(a<2 & b>7)

    .. im not sure though but if compiler has optimising block it is rather useles to calc b>7

    & probably be short-circuiting anyway

    sorry i mixed line order (writing the one beginig .. in wrong place)

    should be

    i think probably in simple cases when you dont acll functions etc

    like if(a<2 & b>7)

    & probably be short-circuiting anyway

    .. im not sure though but if compiler has optimising block it is rather
    useles to calc b>7



    In any case, this is very different from A & B.



    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Kaz Kylheku@3:633/10 to All on Thu Sep 10 20:13:35 2026
    On 2026-09-07, fir <profesor.fir@gmail.com> wrote:
    as i once said i decided to not use && and || as it annoys me (same s == annoys me)

    so i will decide to use & | insted but as i not code regullarry today i
    not yet maneged to test it throughly when it not work and
    if it need big changes in languege to work

    i mean one option is that & | should work for BOTH logical and bitwise

    The predecessors to the C language had only the bitwise & and | which was
    used for testing logical conditions. That's why those operators have
    a strangely low precedence.

    They work for the purpose, but you have to be fastidiously consistent
    about your representation of true; e.g. ensure that true is always 1.

    In code like:

    if ((status_reg & FOO_MASK) && (io_reg & BAR_MASK)) ..

    we cannot blindly replace && with & because status_reg & FOO_MASK
    might produce 0x40, and io_reg & BAR_MASK might produce 0x20.

    The & and | operators also do not feature left-to-right sequencing.
    So we cannot replace && with & in code like

    if (ptr != 0 && ptr->foo == bar) ...

    Both operands of the & will be evaluated regardless of the value of the
    left operand.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)