Since I am fairly new to racket I stumbled across a problem I could not solve.
To break it down, I have a list containing several structures of the same type, and I want to create a list with only one specific argument of each elements structure. Something like this:
(define-struct sample (name number))
(define samples (list (make-sample "A" 1) (make-sample "B" 2)))
So when apply the function to this list I get the following list:
(lit "A" "B")
I want to solve this problem without recursion, only using lambda expressions and map and fold.
I tried to get access to every elements argument by using:
(foldr sample-name samples)
But that does not work.
Does anyone know how to solve this problem?
Thank you in advance! Appa
You're looking for map
, please take a look at the documentation to understand the difference between foldr
and map
.
(map sample-name samples)
=> '("A" "B")