I have the following code:
(define-struct p (x z))
(define-struct s (p my-symbol))
(define N01 (make-s (make-p 22 'a) 'symbol))
(define N02 (make-s (make-p 25 'b) 'symbol))
(define N03 (make-s (make-p 23 'c) 'symbol))
(define my-list (list N01 N02 N03))
Now I want to have a list that should look like this: (list 22 25 23)
or (list 'a 'b 'c)
I know that when I call this (p-x (s-p (first my-List)))
I get 22 but how can I do that for the whole numbers or symbols in my-List
? I think it can be done in a recursive procedure.
Note: I need to use the beginner level with list abbreviations
Thank you for your help!
Start by making a function and determine what you need it to do. You are off to a good start. First use the design recipe to determine what this function will do. It will take in a list of structs and return a list of numbers. After This we can deduce that we will terminate the loop when we reach an empty list. Using what you made we can create this function.
(define (get-p list)
(cond [(empty? list) empty]
[else (cons (p-x (s-p (first list))) (get-p (rest list)))]))
I encourage you to use this same strategy to make a function that returns a list of Z's from my-List.