[racket] Basic Racket Question

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Tue Dec 21 21:02:18 EST 2010

>>  (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.


Posted on the users mailing list.