1
#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))    

I am trying to get a list of objects from my structure and I am unsure of the correct syntax. Below is what I tired

(storeItem-des (car masterList)

I was expecting "red delicious apple"

But I get

storeItem-des: contract violation
expected: storeItem?
given: redApple

It seems like it is returning redApple, which seems correct. Where am I going wrong?

Alex Knauth
  • 8,133
  • 2
  • 16
  • 31
Jonnyutah
  • 37
  • 4
  • This problem is answered by [What is the difference between `quote` and `list`?](https://stackoverflow.com/questions/34984552/what-is-the-difference-between-quote-and-list) – Alex Knauth Oct 14 '18 at 22:48

1 Answers1

1

You're creating a list of symbols, not storeItems.

'(x y z) is equivalent to (list 'x 'y 'z), not (list x y z). So if you want to create a list containing the values of the variables x, y and z, you need to use the latter.

sepp2k
  • 363,768
  • 54
  • 674
  • 675