[racket] Defining Variables in a function

From: Sayth Renshaw (flebber.crue at gmail.com)
Date: Sat Jan 1 19:22:35 EST 2011

On Sun, Jan 2, 2011 at 6:05 AM, Stephen Bloch <sbloch at adelphi.edu> wrote:

> Another solution, which doesn't require any language features you don't
> know yet, is to write a helper function that takes in the gross pay and
> computes the net pay from it.  Your main function then calls this new helper
> function on the result of your "pay" function.  The "pay" function is called
> only once, and your new helper uses the result twice.
>
> Stephen Bloch
> sbloch at adelphi.edu



I can't quite get it to happen at the moment. But is this more the style you
were referring to...However it doesn't like me embedding one function in the
definition of another. will have to keep thinking :-)

(define (netpay hours)
  (* 12 hours))

(define (tax (netpay hours))
  (cond
    [(<= netpay 240) 0]
    [(<= netpay 480) (* 0.15 netpay)]
    [(> netpay 480) (* 0.28 netpay)]))

(define (mypay hours)
  (- (netpay hours)(tax hours)))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110102/1e8383a6/attachment.html>

Posted on the users mailing list.