3
我刚写的函数添加寄存器为二进制加法的球拍两个n位寄存器(使用位添加功能作为辅助):二进制加法的优雅代码?
(define (bit-add x y c)
(values (bitwise-xor x y c) (bitwise-ior (bitwise-and x y)
(bitwise-and x c)
(bitwise-and y c))))
(define (add-registers xs ys)
(let ([carry 0])
(values (reverse (for/list ([b1 (reverse xs)] [b2 (reverse ys)])
(let-values ([(nb nc) (bit-add b1 b2 carry)])
(set! carry nc)
nb)))
carry)))
但是我发现我的代码很丑陋。所以我想知道这是否可以写得更加简洁和优雅?