How does Scheme handle elements in a list?

Asked 2 years ago, Updated 2 years ago, 35 views

In the scheme, when a list is defined as ((item number a unit price a purchase number a) (item number b unit price b purchase number b) ...),
How should I describe the function to find the sum of the unit price of this number of purchases?

I know how to pass the list to the arguments of the function, but I don't know how to write how to take out the list and calculate the sum.

scheme

2022-09-30 14:16

1 Answers

The following is how to use cadr and apply.

(define lst'((110010)(22505)(35003))))
(apply+(map cadrlst))
=>
850


2022-09-30 14:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.