前几天,我花了大量时间跟踪我的一个例程中的一个意外行为,最终意识到我是使用fix函数的著名模糊因子的另一个受害者。
费克斯,骗我一次,你真丢脸。。。骗我两次,我真丢脸!
- (defun fuzzfix (input / *error*)
- ;Jef! 2015-12-15. Automatic addition of a fuzz factor to avoid fix
- ;returning a bad value due to a fuzz difference.
- (defun *error* ( msg )
- (if (not (member msg '("Function cancelled" "quit / exit abort")))
- (princ (strcat "\nError: " msg))
- )
- (princ)
- )
- (if (> 0 input)
- (fix (- input 0.000000000000001))
- (fix (+ input 0.000000000000001))
- )
- )
以下是我的问题:
-您是否会放弃任何反指示,即每次使用修复程序时自动添加模糊?
-你会换一种方式吗?
-你知道有没有其他函数(除了fix)可能会受到模糊影响并返回意外结果?
还有一个更一般的问题。。。何时使用/不使用*error*?在这里,我想我可能只是进行了numberp验证,在这两种情况下,在函数中使用fuzzfix都会触发该函数中的错误,无论fuzzfix是否返回(通过*error*)“错误:错误参数类型:numberp:nil”或自定义消息,如“fuzzfix需要一个数字”,由我自己的numberp“else”返回。欢迎就此提出任何建议。
谢谢,干杯! |