我们需要使用一个函数来计算“每欧元的cpu性能”。当我们运行代码时,它返回错误::: *: expects a number as 1st argument, given (lambda (a1) ...)为什么参数cpu-clock是一个λ函数,而不是一个数字?我们该如何纠正它呢?以下是我们的代码(这不是全部代码,但这是必要的部分):
(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)提前谢谢你。
发布于 2019-12-04 17:31:29
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))https://stackoverflow.com/questions/59171627
复制相似问题