Scheme Language Suppose you are writing a Scheme program for a grocery store that will calculate the total price of a cu

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Scheme Language Suppose you are writing a Scheme program for a grocery store that will calculate the total price of a cu

Post by answerhappygod »

Scheme Language
Suppose you are writing a Scheme program for a grocery storethat will calculate the total price of a customer's items,represented as a list. Your partner suggests writing a seriesof Scheme forms like(define item price) then recursivelygoing through the list using those defines to calculate the sum asbelow.
Will that work? If not, why not? What needs to befixed?
(define milk 2.99)
(define chicken 7.99)
(define carrots 1.99)
(define add-cart (lambda(x) (if (empty? x) 0 (+ (car x)(add-cart (cdr x))))))
(add-cart '(milk chicken carrots))
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply