我们需要使用一个函数来计算“每欧元的cpu性能”。当我们运行代码时,它返回错误::: *: expects a number as 1st argument, given (lambda (a1) ...)
为什么参数cpu-clock
是lambda函数而不是数字?我们该如何纠正?这是我们的代码(这不是完整的代码,但这是必要的部分):
(define-struct cpu (name socket clock cores price))
(define-struct gpu (name gflops memory connectors price))
(define-struct mainboard (name socket connectors price))
;; A list of cpus
(define cpus
(list
(make-cpu 'R9-3900X 'AM4 3.8 12 512.99)
(make-cpu 'R3-1200 'AM4 3.1 4 49.55)
(make-cpu 'R3-3200G 'AM4 3.6 4 92.99)
(make-cpu 'R5-3600 'AM4 3.6 6 195.9)
(make-cpu 'R7-3700X 'AM4 3.6 8 328.9)
(make-cpu 'i3-9100F 'LGA1151v2 3.6 4 75.65)
(make-cpu 'i5-9400F 'LGA1151v2 2.9 6 143.49)
(make-cpu 'i7-9700F 'LGA1151v2 3 8 329.99)
)
)
;; Type:
;; Returns:
(define (cpu-performance-per-euro cpu)
(/ (round (* (/ (* cpu-clock cpu-cores) cpu-price) 1000)) 1000)
)
(check-expect (cpu-performance-per-euro (make-cpu 'R9-3900X 'AM4 3.8 12 512.99)) 0.089)
谢谢。
答案 0 :(得分:0)
cpu-clock
,cpu-cores
,cpu-price
等是函数,而不是值。它们采用cpu
结构并返回相应的值。因此,您应该以这种方式更改功能:
(define (cpu-performance-per-euro cpu)
(/ (round (* (/ (* (cpu-clock cpu) (cpu-cores cpu)) (cpu-price cpu)) 1000)) 1000))