[racket] Basic Racket Question

From: Norman Gray (norman at astro.gla.ac.uk)
Date: Tue Dec 21 07:41:48 EST 2010

On 2010 Dec 21, at 11:50, 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.

I think you may need to go a little further back in the tutorial.  It looks like you're misunderstanding some fairly important basics.

> (define (tax t)
>  (= t 0.15))

That defines a function called 'tax', which takes one argument, and returns true if that argument is numerically equal to 0.15 -- that is, the function '=' is an equality test, not an assignment.  That's probably not what you think it does.

> (define (payrate p)
>  (= p $12.00))

That defines another function, called 'payrate', which tests whether its argument is numerically equal to the value of the identifier (ie, 'variable') $12.00.  That identifier hasn't been defined anywhere, though something like (define $12.00 1234.56) would work.

> (define (netpay hours tax payrate)
>  (* h p)-(* t(* h p)))

That defines a function which takes three arguments, named 'hours', 'tax' and 'payrate', and which doesn't use any of them.  It also uses an infix '-'.

Somethink like

(define (netpay hours tax payrate)
  (- (* hours payrate) (* hours payrate tax)))
(netpay 40 0.15 5.0)

is probably closer to what you want.

Of course, the following is neater:

(define (netpay2 hours tax payrate)
  (* hours payrate (- 1 tax)))

Like I say, it would probably be useful to head back to the beginning of whichever tutorial it is you're reading.

Good luck,

Norman


-- 
Norman Gray  :  http://nxg.me.uk



Posted on the users mailing list.