[racket] Defining Variables in a function

From: Ken Hegeland (hegek87 at yahoo.com)
Date: Sun Jan 2 22:50:02 EST 2011

The idea of embedding a program inside another is learned later in the book, 
check on local to see how it works, or don't worry about embedding until later 

Simply define the function for now to just produce the amount of tax, 0, .15, or 

So the program should work like this
(equal? (tax 130)0)
(equal?(tax 250).15)
(equal?(tax 500).28)

get that working, then think about how you would solve this in one application. 
If you want to calculate net pay of some pay input, what would you do?

well, net pay is gross-pay - tax on gross pay.

How would you implement that for a gross pay input of 130, 250, and 500?

First, figure out what the net pay would be, then apply how you calculated that 
in scheme expressions.

This approach by you was very close:

(define (tax_pay pay)
    [(<= pay 240) 0]
    [(<= pay 480) (* pay 0.15)]
    [(> pay 480) (* pay 0.28)]))

There are two problems I saw, you are treating pay as another function. Just 
treat it as some input
any random number will work.

The second problem, think about what you are calculating in each conditional 

This function is pretty close. You only really need one function to compute net 

if you wanted you can define another function called pay for simple testing
;;assuming 12 dollars an hour as a pay rate

(define(pay hours)
...hours .12..)

Then applying (tax_pay(pay 25))

Would produce net pay for some given hourly input.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110102/e1ef37e6/attachment.html>

Posted on the users mailing list.