How does Scheme handle elements in a list?

Asked 4 months ago, Updated 4 months ago, 11 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


© 2023 OneMinuteCode. All rights reserved.