只用“+”“-”“if0”"with"(代入)这几个操作定义一个乘法操作,和判断一个数是正是负
可用操作有
“+”
“-”
“if0”这个操作的意思是:
the if0 conditional expression
To compute the value of the expression {if0 test-expr yes-expr no-expr}, first evaluate the test-expr. If it has the value 0, evaluate the yes-expr branch; otherwise, evaluate the no-expr branch. For example:
{if0 {+ 3 {+ -5 2}} {+ 8 9} {+ 5 6}}
should return 17.
就是说,这个操作判断的是 第一个表达式,如果第一个表达式结果为0的话,则最终结果为第二个表达式的值,如果第一个表达式结果为1的话,那么最终结果为第三个表达式的值。
“with”是代入操作,例如:(with (x 3) (with (y 9) (+ x y))) 先是把y = 9代入 +x y然后把 x=3代入
(1)如何用这几个操作定义一个乘法操作
(2)如何用这几个操作定义一个判断一个数是正是负的操作
可以定义其他的辅助操作,但是辅助操作也必须来自于这四种操作,
例如我定义一个判断是否相等的操作: (deffun (equal? x y)(if0 (- x y) 0 1))
能提供思路即可,不是要用特定的语言,只求怎么能通过这四种简单的操作,来定义两个其他的操作