“application: not a procedure” in determinant code

拟墨画扇 提交于 2019-12-25 18:38:25

问题


application: not a procedure; expected a procedure that can be applied to arguments given: 2 arguments...: -4 -6 12 -3 1 2 7

What does this error mean given the following code?

(define (det2x2 a b c d)(- (* a d) (* b c)))
(define (det2x2prod a1 b1 c1 d1 a2 b2 c2 d2)  (det2x2 (+ (* a1 a2)(* b1 c2))
                                                      (+   (* a1 b2)(* b1 d2))
                                                      (+   (* c1 a2)(* d1 c2))
                                                      (+   (* c1 b2) (* d1 d2))))
(det2x2prod 2 (- 4)(- 6) 12(- 3) 1 2 7)
(define (prod-inv a1 b1 c1 d1 a2 b2 c2 d2) not (= 0 (det2x2prod (a1 b1 c1 d1 a2 b2 c2 d2))))
(define (prod-inv-2 a1 b1 c1 d1 a2 b2 c2 d2)not(= 0 (det2x2(a1 b1 c1 d1)(det2x2(a2 b2 c2 d2)))))
(prod-inv   2 (- 4) (- 6) 12 (- 3) 1 2 7)
(prod-inv-2 2 (- 4)(- 6) 12 (- 3) 1 2 7)

*This is my first day working with scheme


回答1:


You have lots of syntax errors - missing parenthesis, erroneous parenthesis, etc. You shold test each procedure thoroughly before writing the next, don't wait until you have lots of code to start testing. Try this:

(define (det2x2 a b c d)
  (- (* a d) (* b c)))

(define (det2x2prod a1 b1 c1 d1 a2 b2 c2 d2)
  (det2x2 (+ (* a1 a2) (* b1 c2))
          (+ (* a1 b2) (* b1 d2))
          (+ (* c1 a2) (* d1 c2))
          (+ (* c1 b2) (* d1 d2))))

(det2x2prod 2 -4 -6 12 -3 1 2 7)

(define (prod-inv a1 b1 c1 d1 a2 b2 c2 d2)
  (not (= 0 (det2x2prod a1 b1 c1 d1 a2 b2 c2 d2))))

(define (prod-inv-2 a1 b1 c1 d1 a2 b2 c2 d2)
  (not (= 0 (det2x2 a1 b1 c1 d1) (det2x2 a2 b2 c2 d2))))

(prod-inv   2 -4 -6 12 -3 1 2 7)
(prod-inv-2 2 -4 -6 12 -3 1 2 7)

What were you trying to do with prod-inv and prod-inv-2? I fixed the compilation errors, but make sure that they implement the algorithm given in the assignment. prod-inv-2 doesn't seem correct.



来源:https://stackoverflow.com/questions/18470443/application-not-a-procedure-in-determinant-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!