13-bitwise.scm (818B)
1 ;; Step-10c bitwise primitives: bit-and bit-or bit-xor bit-not 2 ;; arithmetic-shift. 3 ;; 4 ;; bit-and/or/xor are variadic (identity on 0 args: -1, 0, 0); 5 ;; bit-not is unary; arithmetic-shift is binary (k<0 is right shift). 6 ;; Step-11 reader/printer deferrals mean we can't literalize -1 or 7 ;; a negative shift; we synthesize both via `(bit-not 0)` and witness 8 ;; through non-negative results. 9 (if (= (bit-and) (bit-not 0)) 10 (if (= (bit-and 15) 15) 11 (if (= (bit-and 15 6) 6) 12 (if (= (bit-or) 0) 13 (if (= (bit-or 1 2 4) 7) 14 (if (= (bit-xor 15 6) 9) 15 (if (= (bit-xor 15 15) 0) 16 (if (= (bit-not (bit-not 42)) 42) 17 (if (= (arithmetic-shift 1 3) 8) 18 (if (= (arithmetic-shift 16 (bit-not 1)) 4) 19 42 0) 0) 0) 0) 0) 0) 0) 0) 0) 0)