:: *:在给定(lambda(a1)…)的情况下,期望数字作为第一个参数。

问题描述 投票:0回答:1
我们需要使用一个函数来计算“每欧元的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)

谢谢你。

我们需要使用一个函数来计算“每欧元的cpu性能”。当我们运行代码时,它返回错误::: *:期望将数字作为第一个参数,给定(lambda(a1)...)为什么是参数...

racket
1个回答
0
投票
cpu-clockcpu-corescpu-price等是函数,而不是值。它们采用cpu结构并返回相应的值。因此,您应该以这种方式更改功能:
© www.soinside.com 2019 - 2024. All rights reserved.