[racket] Basic Racket Question

From: Ken Hegeland (hegek87 at yahoo.com)
Date: Tue Dec 21 22:55:49 EST 2010

While you got it working, you are over complicating the process.

First you defined that variables, that's fine

(define tax-rate .15)
(define pay-rate 12)

The function net-pay only needs one input, the amount of hours you are working.

With the defined pay-rate and tax-rate, how would you determine net-pay of 10 hours by hand?

I hope you would multiply pay-rate by hours to produce gross pay

(12 * 10)=120, so 120 is the gross pay.

Now how would you find the net pay of the gross pay? You could either subtract .15 from 1, or subtract gross pay*.15 from gross pay.

120*.85= 102, or 120-120*.15 =102.

While auxiliary functions are a great thing to understand you don't quite need them for such a small function, you can even define the function with out defining variables.

The solution you came up with just seems confusing when I look at it.

You defined gross-pay as
(define(gross-pay h)
(* h pay-rate))

You are using gross in net-pay as an argument which isn't really something you need to do right now.

Everytime you want to check a number you need to type (netpay(gross x)taxrate)

why not just develop it so you can type (net-pay x) and have it produce the net-pay?

Try doing it without using an auxiliary function and the ONLY argument as h

(define(netpay h)
(tax-rate payrate h..)

 Those should be the only things used in your program.



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

Posted on the users mailing list.