[RFC] Operators GET, SET and CLEAR for L bits

Jose E. Marchesi jemarch@gnu.org
Wed Jan 28 08:49:19 GMT 2026


Hello people!

I propose to add the following operators (to apply to L bits) to the
extended standard prelude:


  prio SET = 7, CLEAR = 7;

  op SET = (bits b, int n) bits:
     if n >= 1 AND n <= bits_width
     then b OR 2r1 SHL (n-1)
     else b
     fi;

  op CLEAR = (bits b, int n) bits:
     if n >= 1 AND n <= bits_width
     then b AND NOT (2r1 SHL (n-1))
     fi;

  prio GET = 4;

  op GET = (bits b, int n) bool:
     if n >= 1 AND n <= bits_width
     then ABS (b AND n) /= 0
     fi;

Usage example:

  pub mode Termios = struct (bits iflag, lflag, oflag);

  pub int flag_igncr  = 1, { Input flags }
          flag_icrnl  = 2,
          flag_ixon   = 3,
          flag_ignbrk = 4,
          flag_parmrk = 5,
          flag_brkint = 6,
          flag_istrip = 7,
          flag_inlcr  = 8,
          flag_opost  = 1, { Output flags }
          flag_echo   = 1, { Local flags }
          flag_echonl = 2,
          flag_icanon = 3,
          flag_isig   = 4,
          flag_iexten = 5;

  [...]

  pub proc term_raw_mode = (ref Term t) void:
  begin
        bool ret;

        if Termios termios;
           ret := tcgetattr(ofd of t, termios)
        then
             iflag of termios := iflag of termios
                                 SET flag_ignbrk
                                 SET flag_brkint
                                 SET flag_parmrk
                                 SET flag_istrip
                                 SET flag_inlcr
                                 SET flag_igncr
                                 SET flag_icrnl
                                 SET flag_ixon;
             oflag of termios := oflag of termios
                                 CLEAR flag_opost;
             lflag of termios := lflag of termios
                                 CLEAR flag_echo
                                 CLEAR flag_echonl
                                 CLEAR flag_icanon
                                 CLEAR flag_isig
                                 CLEAR flag_iexten;
             ret := tcsetattr(ofd of t, termios)
        fi;

        if NOT ret
        then term_error("error switching terminal to raw mode: "
                        + strerror(errno))
        fi
  end;

Opinions?

In particular we have to choose some priorities that really make sense
for these operators.

I am bad with priorities... :(


More information about the Algol68 mailing list