Marc:
I started writing a bitset library to leverage the bitwise-* operations.
I need some help in working with type macros, etc.
Can you look at the simple code below and tell me how to express it in the right way?
Also, your define-prim-nary implements a fold operation, which is much, much slower for bitwise operations than just
1. Making sure all arguments are exact ints.
2. Determining the size of the resulting bignum (to be possibly normalized to a fixnum later) from the sizes and signs of the arguments.
3. Allocating the final bignum and destructively modifying it based on the arguments.
Should I look into that a bit?
Brad
The start of bitsets.scm follows.
(##include "../lib/header.scm")
;; accessors and constructors are not inlined unless I add ;; the following declaration.
;; Is that why you write constructors and accessors as macros?
(declare (inlining-limit 300))
(define-structure ##bitset body)
(define-prim (##bitset-union bs1 bs2)
(##define-macro (type-error-on-x) `'(1)) (##define-macro (type-error-on-y) `'(2))
(if (##bitset? x) (if (##bitset? y) (make-##bitset (##bitwise-ior (##bitset-body x) (##bitset-body y))) (type-error-on-y)) (type-error-on-x)))
(define-prim-nary (bitset-union x y) (make-##bitset 0) (if (##bitset? x) x '(1)) (##bitset-union x y) macro-force-vars macro-no-check (##pair? ##fail-check-bitset))