racket - Scheme Beginning Student, Function Body Extra Part -


i attempted follow solution provided in this question, didn't work.

essentially, function works so:

(define (item-price size normal-addons premium-addons discount)   (define price 0)   (+ price (* normal-addon-cost normal-addons) (* premium-addon-cost premium-addons) size)   (cond     .. conditions here     [else price])) 

however, met following error:

define: expected 1 expression function body, found 2 parts 

now, i've tried wrapping body of function in 'begin', when run claims 'begin' not defined. using beginner student language version oppose straight-up racket. insight on workaround?

the problem remains same: in language that's being used, can't write more 1 expression inside function body, can't use begin pack more 1 expression, , both let , lambda (which have allowed create local bindings) forbidden. that's lot of restrictions, can around using helper function calculates price each time:

(define normal-addon-cost 10)   ; example (define premium-addon-cost 100) ; example  (define (price size normal-addons premium-addons)   (+ (* normal-addon-cost normal-addons)      (* premium-addon-cost premium-addons)       size))  (define (item-price size normal-addons premium-addons discount)   (cond     ... conditions here ...     [else (price size normal-addons premium-addons)])) 

alternatively: if price used once, in-line expression calculates it, there's no need create local variable or helper function.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -