mc #4933(2007/12/22 20:08 GMT) [ Common Lisp ] Rating0/0=0.00
shiroさんの#4930の真似で自分も演算子の上書きにしてみました。 with-modで囲んだ部分に指定した数字の法が適用されます。 (with-mod 10 (print (= (print (* 18 39)) (print (* 8 9))))) => 2 2 T
1 2 3 4 5 6 7 8 9 10 11 12
(defmacro with-mod (div &body body) `(%with-mod ((+ - * /) ,div) ,@body)) (defmacro %with-mod (((&rest fns) div) &body body) (let ((g (gensym))) `(let ((,g (labels ,(mapcar (lambda (fn) `(,fn (&rest expr) (mod (apply (symbol-function ',fn) expr) ,div))) fns) ,@body))) (if (numberp ,g) (mod ,g ,div) ,g))))
Rating0/0=0.00-0+
[ reply ]
mc
#4933()
[
Common Lisp
]
Rating0/0=0.00
shiroさんの#4930の真似で自分も演算子の上書きにしてみました。 with-modで囲んだ部分に指定した数字の法が適用されます。 (with-mod 10 (print (= (print (* 18 39)) (print (* 8 9))))) => 2 2 T(defmacro with-mod (div &body body) `(%with-mod ((+ - * /) ,div) ,@body)) (defmacro %with-mod (((&rest fns) div) &body body) (let ((g (gensym))) `(let ((,g (labels ,(mapcar (lambda (fn) `(,fn (&rest expr) (mod (apply (symbol-function ',fn) expr) ,div))) fns) ,@body))) (if (numberp ,g) (mod ,g ,div) ,g))))Rating0/0=0.00-0+
[ reply ]