Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 如何将结构对象放入列表中?_List_Scheme_Structure - Fatal编程技术网

List 如何将结构对象放入列表中?

List 如何将结构对象放入列表中?,list,scheme,structure,List,Scheme,Structure,我试图从我的结构中获取对象列表,但我不确定正确的语法。下面是我所累的 #lang Scheme (define-struct storeItem (id des cost)) (define redApple (make-storeItem 0 "red delicious apple" 1.99)) (define chickenLeg (make-storeItem 1 "boned chicken" 2.99)) (define porkLoin (make-storeItem 2 "

我试图从我的结构中获取对象列表,但我不确定正确的语法。下面是我所累的

#lang Scheme

(define-struct storeItem (id des cost))

(define redApple (make-storeItem 0 "red delicious apple" 1.99))
(define chickenLeg (make-storeItem 1 "boned chicken" 2.99))
(define porkLoin (make-storeItem 2 "processed pork" 4.99))
(define milkD (make-storeItem 3 "vitamin d milk" 3.99))
(define baguetteBread (make-storeItem 4 "french bread" 0.99))
(define orangeJuice (make-storeItem 5 "fruit juice drink)" 1.49))
(define beanCan (make-storeItem 6 "beans in a can" 2.49))

(define masterList '(redApple chickenLeg porkLoin milkD baguetteBread 
   orangeJuice beanCan))    
我期待着“红色美味苹果”

但我明白了

(storeItem-des (car masterList)

它似乎正在返回
redApple
,这似乎是正确的。我哪里出错了?

您正在创建符号列表,而不是
storeItem
s


(x y z)
等同于
(list'x'y'z)
,而不是
(list x y z)
。因此,如果您想创建一个包含变量
x
y
z
的值的列表,您需要使用后者。

谢谢您。应用:不是一个程序;需要一个可应用于给定参数的过程:#参数…:这是我每次更改列表类型时得到的结果。@Jonnyutah您收到错误消息的代码是什么?@Jonnyutah您是否编写了
(list redApple chickenLeg…)
?@Jonnyutah听起来好像你忘了把
列表
放在开头。@Barmar如果我创建了(列表1、2、3),如果没有名称,我该如何导航该列表?谢谢这个问题的答案是
storeItem-des: contract violation
expected: storeItem?
given: redApple