<br><br><div class="gmail_quote">On Wed, Dec 22, 2010 at 9:43 AM, Sayth Renshaw <span dir="ltr"><<a href="mailto:flebber.crue@gmail.com">flebber.crue@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><div></div><div class="h5"><br><br><div class="gmail_quote">On Wed, Dec 22, 2010 at 2:04 AM, Stephen Bloch <span dir="ltr"><<a href="mailto:sbloch@adelphi.edu" target="_blank">sbloch@adelphi.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><br>
On Dec 21, 2010, at 6:50 AM, Sayth Renshaw wrote:<br>
<br>
</div><div>> 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.<br>
><br>
> Hard way<br>
><br>
> (define (hours h)<br>
> (h : number?))<br>
> (define (tax t)<br>
> (= t 0.15))<br>
> (define (payrate p)<br>
> (= p $12.00))<br>
> (define (netpay hours tax payrate)<br>
> (* h p)-(* t(* h p)))<br>
<br>
</div>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<br>
(define tax-rate 0.15)<br>
(define pay-rate 12)<br>
Note that these definitions are OUTSIDE the definition of "netpay".<br>
<br>
You can then use these in functions you define. For example, the "inventory" step of this function definition would become<br>
<div> (define (netpay hours)<br>
; hours a number<br>
</div> ; pay-rate a number ($/hour)<br>
; tax-rate a number<br>
...<br>
)<br>
and then the body could use all three of these variable names.<br>
<br>
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":<br>
(define (netpay hours)<br>
(local [(define tax-rate 0.15)<br>
(define pay-rate 12)]<br>
; hours a number<br>
; tax-rate a number<br>
; pay-rate a number ($/hour)<br>
...<br>
))<br>
This version doesn't work in Beginning Student Language, though; you need Intermediate Student Language.<br>
<div><div></div><div><br>
<br>
<br>
<br>
Stephen Bloch<br>
<a href="mailto:sbloch@adelphi.edu" target="_blank">sbloch@adelphi.edu</a><br>
<br>
</div></div></blockquote></div><br></div></div>Firstly thank you very much for the feedback and ideas its very appreciated.<br><br>I am following the book again and your examples but i am rewriting examples so I am learning it.<br>
<br>
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?<div class="im"><br><br> (define tax-rate 0.15)<br>
(define pay-rate 12)<br></div>
(define (gross hours)<br> (* hours pay-rate))<br> <br> (define (netpay gross tax-rate)<br> (gross (- tax-rate)))<br><br>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?<br>
</blockquote></div><br>see ultimately a version like this makes the most sense to me but it won't allow defined functions. I keep getting this error.<br><br>function call: expected a defined function name or a primitive operation name after an open parenthesis, but found a function argument name<br>
<br>This is my preferred version.<br><br> (define tax-rate 0.15)<br> (define pay-rate 12)<br> (define (gross hours)<br> (* hours pay-rate))<br> <br> (define (netpay gross tax-rate)<br> (-(gross)(* gross tax-rate)))<br>
<br><br>