[racket] Basic Racket Question
On Wed, Dec 22, 2010 at 2:04 PM, Robby Findler
<robby at eecs.northwestern.edu>wrote:
> FWIW, if you were in my class, that solution would get few points. You
> may have noticed people asking you about the design recipe in this
> thread. That is a reference to this book that you might find useful:
>
> http://www.htdp.org/
>
> Robby
>
> On Tue, Dec 21, 2010 at 8:49 PM, Sayth Renshaw <flebber.crue at gmail.com>
> wrote:
> >
> >
> > On Wed, Dec 22, 2010 at 1:19 PM, Sayth Renshaw <flebber.crue at gmail.com>
> > wrote:
> >>
> >>
> >> On Wed, Dec 22, 2010 at 1:02 PM, Danny Yoo <dyoo at cs.wpi.edu> wrote:
> >>>
> >>> >> (define (netpay gross tax-rate)
> >>> >> (-(gross)(* gross tax-rate)))
> >>> >>
> >>> >> So I expect the function to calculate as
> >>> >>
> >>> >> = (-(240)(* 240 0.15)
> >>> >> = ( - 240 36)
> >>> >> = 204
> >>>
> >>>
> >>> Just to be more careful: when you're showing the calculation, make
> >>> sure to include the use of the function:
> >>>
> >>> (netpay 240 0.15)
> >>> = (-(240)(* 240 0.15)
> >>> = ( - 240 36)
> >>> = 204
> >>>
> >>>
> >>> There's a hitch on the first step in the calculation, and it has to do
> >>> with the parens. Unlike its use in traditional math notation, parens
> >>> are significant in this language: that is, every use of paren has to
> >>> mean something: it's not superfluous: if you have too many or too few,
> >>> it changes the meaning of the program.
> >>>
> >>>
> >>> So, within the larger term here:
> >>>
> >>> (- (240) (* 240 0.15))
> >>>
> >>> the subterm
> >>>
> >>> (240)
> >>>
> >>> means "call the function 240". That may not be what you intend, but
> >>> that what it means in this language.
> >>>
> >>>
> >>> You can see this if you go back to what the error message is saying:
> >>>
> >>> function call: expected a defined function name or a primitive
> >>> operation name after an open parenthesis, but found a function
> >>> argument name
> >>>
> >>> It's basically trying to point out this problem, that the use of
> >>> "(gross)" within the expression
> >>>
> >>> (-(gross)(* gross tax-rate))
> >>>
> >>> is trying to use gross as if it were a function, rather than the
> >>> numeric argument to netpay.
> >>
> >> the subterm
> >>
> >> (240)
> >>
> >> means "call the function 240". That may not be what you intend, but
> >> that what it means in this language.
> >>
> >> Awesome pickup, thank you. Can I ask how I could then specify gross a
> >> single item in the formula and not as a function?
> >
> > Thank you everyone, I have solved it and thank you for picking me up on
> the
> > small intricises.
> >
> > This is my solution though it works I do feel I "Cheated" somewhat but
> this
> > is what I have done and tested working.
> >
> > (define tax-rate 0.15)
> > (define pay-rate 12)
> > (define (gross hours)
> > (* hours pay-rate))
> >
> > (define (netpay gross tax-rate)
> > (- gross 0 (* gross tax-rate)))
> >
> >
> >> (netpay (gross 20)tax-rate)
> > 204
> >>
> >
> > Sayth
> >
> > _________________________________________________
> > For list-related administrative tasks:
> > http://lists.racket-lang.org/listinfo/users
> >
>
Indeed I know what you are referencing.
;; *Contract*: area-of-ring : number number -> number
;; *Purpose*: to compute the area of a ring whose radius is
;; outer and whose hole has a radius of inner
;; *Example*: (area-of-ring 5 3) should produce 50.24
;; *Definition*: [refines the header]
(define (area-of-ring outer inner)
(- (area-of-disk outer)
(area-of-disk inner)))
;; *Tests*:
(area-of-ring 5 3)
;; expected value
50.24
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20101222/70007432/attachment.html>