I would like to define a list like ((item number a price a number a number a purchase a) (item number b price b number b purchase b) ...) in scheme and create a function to find the total price of the item such as a * purchase a + price b * purchase b + ...
How should I write a function?
>(display(count-price'(((110010)(22505)(35003))))
#langracket
(define(seki xy)(* xy))
(define(count-price item)
(if(null?item)
`()
(apply+seki(map cadritem)(map last item)))
Change the parameters of the function seki
to a list.
入力 The input value assumes a list of positive integers with 3 elements, so you will need to add an error check.
(define(sekilst)(apply*(cdrlst)))
(define(count-price item)
(if(null?item)
`()
(apply+(map seki item)))
(display(count-price'((110010)(22505)(35003))))
=>
3750
© 2024 OneMinuteCode. All rights reserved.