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?
SCHEME LANGUAGE: Help fix the code. I can't figure out why my code is not working: #lang scheme (define milk 2.99) (defi
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
SCHEME LANGUAGE: Help fix the code. I can't figure out why my code is not working: #lang scheme (define milk 2.99) (defi
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!