Racket 球拍-根据给定列表生成新列表

Racket 球拍-根据给定列表生成新列表,racket,Racket,我试图基于原始列表创建一个新列表,其中列表的每个元素都包含原始列表中的第一个元素,第二个元素是原始列表中第二个和第三个元素的乘积 示例:如果原始列表为 (list (list "A" 2 3) (list "B" 3 4) 那么结果就是 (list (list "A" 6) (list "B" 12)) 到目前为止,我写了: (define (total-price-list lol) (cond [(empty? lol) empty] [else (list (pr

我试图基于原始列表创建一个新列表,其中列表的每个元素都包含原始列表中的第一个元素,第二个元素是原始列表中第二个和第三个元素的乘积

示例:如果原始列表为

(list (list "A" 2 3) (list "B" 3 4)
那么结果就是

(list (list "A" 6) (list "B" 12)) 
到目前为止,我写了:

(define (total-price-list lol)
  (cond
    [(empty? lol) empty]
    [else (list (price-list (first lol))
                (price-list (rest lol)))]))

(define (price-list row)
  (list (first row) (* (second row) (third row))))

我不知道如何达到想要的结果。有人能帮我写代码吗?

映射中的lambda保持第一个元素不变,并将每个子列表的第二个和第三个元素相乘

(define (total-price-list lol)
  (map (λ (l) (list (first l) (* (second l) (third l)))) lol))

(total-price-list (list (list "A" 2 3) (list "B" 3 4)))
; => '(("A" 6) ("B" 12))

谢谢你的帮助,我明白你的意思了。但是我不允许使用map:我们可以将lambda提升为一个helper,并将lol和f替换为map的定义:define total price list lol cond[empty?lol'][else cons f first lol total price list rest lol]define f l list first l*second l third l total price list a 2 3 list B 3 4;=>'A 6 B 12抱歉,因此不允许您在注释中正确格式化多行代码