我如何 return 列表中的一个的所有数据作为结构

how can I return all the data of one that is in a list as structure

我有一个问题,我无法找到从下面的列表中取回所有数据的方法:

(define lst1 (list
 (list "p1" "clock" "1000" "10")
 (list "p2" "shirt" "2000" "30")
 (list "p3" "pants" "4000" "20")
 (list "p4" "cap" "2300" "100")
 (list "p5" "string" "1600" "25")
 (list "p6" "glasses" "3000" "34")
 (list "p7" "shoes" "400" "120")))

作为一个结构,该结构将是(制造商产品代码产品价格数量)

我试过了,但是 returns 只是列表的一个数据,而不是 return 具有结构的整个列表。

(define-struct product (code product price quantity))

(define(load-files lst)
  

  (cond

    [(empty? lst)empty]
    [(list? lst)(list(make-product(first(first lst))(first(rest(first lst)))
                                  (first(rest(first lst)))
                                  (first(rest(rest(first lst))))))]
                                        
    [else(load-files (rest lst))
         ]
    )
  )

您不需要进行显式递归,这是使用 higher-order 函数的好机会,例如 mapcurryapply:

(define (load-files lst)
  (map (curry apply make-product)
       lst))

为了更明确一点,以上等同于:

(define (load-files lst)
  (map (lambda (item)
         (make-product (first item) (second item) (third item) (fourth item)))
       lst))