On Wed, Dec 22, 2010 at 9:43 AM, Sayth Renshaw <[email protected]>wrote:
> > > On Wed, Dec 22, 2010 at 2:04 AM, Stephen Bloch <[email protected]> wrote: > >> >> On Dec 21, 2010, at 6:50 AM, Sayth Renshaw wrote: >> >> > Doing the netpay of employee tax = 0.15 and pay = hrs *12. From the >> beginner tutorial. I see two ways a simple and a hard way but neither work. >> > >> > Hard way >> > >> > (define (hours h) >> > (h : number?)) >> > (define (tax t) >> > (= t 0.15)) >> > (define (payrate p) >> > (= p $12.00)) >> > (define (netpay hours tax payrate) >> > (* h p)-(* t(* h p))) >> >> Something else I forgot to mention in my previous message: you're quite >> right to want to give names to the tax rate and the hourly pay. The usual >> way to do this in Beginner Racket would be >> (define tax-rate 0.15) >> (define pay-rate 12) >> Note that these definitions are OUTSIDE the definition of "netpay". >> >> You can then use these in functions you define. For example, the >> "inventory" step of this function definition would become >> (define (netpay hours) >> ; hours a number >> ; pay-rate a number ($/hour) >> ; tax-rate a number >> ... >> ) >> and then the body could use all three of these variable names. >> >> Later in the book, you'll learn another way to do it, using "local >> variables" so the names "tax-rate" and "pay-rate" are visible only INSIDE >> "netpay": >> (define (netpay hours) >> (local [(define tax-rate 0.15) >> (define pay-rate 12)] >> ; hours a number >> ; tax-rate a number >> ; pay-rate a number ($/hour) >> ... >> )) >> This version doesn't work in Beginning Student Language, though; you need >> Intermediate Student Language. >> >> >> >> >> Stephen Bloch >> [email protected] >> >> > Firstly thank you very much for the feedback and ideas its very > appreciated. > > I am following the book again and your examples but i am rewriting examples > so I am learning it. > > I came to this as a solution based on feeedback but it is erroring on the > word gross as part of my netpay function. Do i need to define the gross > function in my netpay function? > > > (define tax-rate 0.15) > (define pay-rate 12) > (define (gross hours) > (* hours pay-rate)) > > (define (netpay gross tax-rate) > (gross (- tax-rate))) > > Not quite grabbing something intrinsic, unfortunately Norman this is the > start of the book..If I have defined gross function as suggested earlier why > can't my netpay function use it? > see ultimately a version like this makes the most sense to me but it won't allow defined functions. I keep getting this error. function call: expected a defined function name or a primitive operation name after an open parenthesis, but found a function argument name This is my preferred version. (define tax-rate 0.15) (define pay-rate 12) (define (gross hours) (* hours pay-rate)) (define (netpay gross tax-rate) (-(gross)(* gross tax-rate)))
_________________________________________________ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users

