Reputation: 11
I've created a function that gives a items in a list a certain score
(define newlist '((score 'A ) (score 'A1 ) (score 'A2 )))
but cannot get it to return a ( X Y Z) list . Only
'((score 23 ) (score 12 ) (score 7 ))
which is only the substituted values for my variables.
Upvotes: 0
Views: 108
Reputation: 70155
When you use quote
(the character '
) what follows in not evaluated. So in what you provided, the entire list of three items is not evaluated. To evaluate use list
as such:
(define newlist (list (score 'A) (score 'A1) (score 'A2)))
As @kmoerman points out, there are other ways, using map
, to get a valid result; however, your original problem was using quote
instead of list
.
Upvotes: 0
Reputation: 430
You could use the map
function:
;if A, A1 and A2 are to be used as symbols:
(define newlist (map score '(A A1 A2)))
;which is equivalent to:
(define newlist (map score (list 'A 'A1 'A2)))
;however, if A, A1 and A2 are variables whose values you wish to use:
(define newlist (map score (list A A1 A2)))
Upvotes: 1