[racket] Defining Variables in a function

From: Sayth Renshaw (flebber.crue at gmail.com)
Date: Sat Jan 1 09:03:28 EST 2011

Working through HTDP and I got to this example(below) I created a working
function but I reused a function, is there a better way to assign a variable
in another function so, for refernce this was the question.

*Exercise 4.4.2.*   Develop the function tax, which consumes the gross pay
and produces the amount of tax owed. For a gross pay of $240 or less, the
tax is 0%; for over $240 and $480 or less, the tax rate is 15%; and for any
pay over $480, the tax rate is 28%.

My Working solution

;;; Given a gross wage determine the tax that applies taxed in bands
;;; number -> number
;;; less than 240, greater than 240 < 480, greater than 480
(define (tax_pay pay)
    [(<= pay 240) 0]
    [(<= pay 480) (* pay 0.15)]
    [(> pay 480) (* pay 0.28)]))

(define (pay hours)
  (* 12 hours))
;;; Calculate netpay (pay - tax)
;;; Pay rate 12 and user input hours
;;; (pay (payrate * hours)) - (pay -(tax (pay * tax percent))
(define (netpay hours)
  (- (pay hours)(tax_pay (pay hours))))

Proposed solution - assign a variable to the pay calculation and reuse it,
however it thinks I am redefining the function tax_pay. In embryo this is a
better way to crack the egg isn't it?

(define (netpay2 hours)
  (h (pay hours)
     (- h (tax_pay h))))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110102/1bf8d9be/attachment.html>

Posted on the users mailing list.