Page 1 of 1

SCHEME LANGUAGE: Help fix the code. I can't figure out why my code is not working: #lang scheme (define milk 2.99) (defi

Posted: Thu Jul 14, 2022 2:19 pm
by answerhappygod
SCHEME LANGUAGE:
Help fix the code. I can't figure out why my code is notworking:
#lang scheme
(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))
Error:+: contract violation expected: number? given: carrots
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 recursively goingthrough the list using those defines to calculate the sum asbelow. Will that work? If not, why not?