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