[racket] exercise problem

From: Stephen Bloch (bloch at adelphi.edu)
Date: Tue Feb 21 16:40:34 EST 2012

On Feb 21, 2012, at 3:18 PM, Roelof Wobben wrote:

> Op 21-2-2012 20:51, Stephen Bloch schreef:
>> 
>> On Feb 21, 2012, at 2:43 PM, Roelof Wobben wrote:
>> 
>>> But now I get this error message : 
>>> unsaved editor>:27:23: function call: expected a function after the open parenthesis, but found a part in: (tarief1 amount)
>>> 
>>> When I do (tarief 1 amount) instead of ((tarief amount))
>> Yes, that's where the syntax error is.  So you've fixed that.
> 
> I fixed that?  I always thought that if I use another function that I must be into ().
> So In my opinion one () for the then part and one () for the function call. 

No, there is no pair of parentheses for the "then" part, only one for the function call.

(cond [question answer]
           [question answer]
           ...
           [question answer])
where each question and each answer is an expression (usually a function call).

>> 1) Have you written a complete set of test cases, with right answers, using "check-expect"?  Since there are four categories of input for this problem, you need at least four test cases, and you should probably have three more for the boundaries, a total of seven test cases.
> 
> Nope, check-expect is not explained on chapter section 3 of the book how to design programms. So I did not use that function.  I can make test-cases but then in this form 
> 
> (= (tarief 495) 1,2375) 

That should work too, although it's not as convenient.  Make sure you put a bunch of those test cases in the Definitions pane, after the definition:

(define (tarief blah blah)
   blah blah blah
   )

(= (tarief 495) 1,2375)
(= (tarief 0) 0)
(= (tarief 100) whatever)
...

That will also solve the next problem:

> 3) Have you used the Stepper to watch what your program is doing? 
> 
> Yes, when I do (payback 2600) on the prompt and press Step I only see a message  All definitions have been sucessfully evaluated and not other outcome so that did not help me any further. 

The Stepper only works on expressions in the Definitions pane, not the Interactions pane.  If you put your test cases in the Definitions pane as described above, the Stepper will help you find where things are going wrong.

BTW, check-expect is not discussed in _How to Design Programs_ because it hadn't been invented yet when the book was written.  It's quite easy to use, though: replace the = sign in the above tests with check-expect, and when you hit "Run" you'll get a report of which of your test cases worked, the expected answer and the actual answer.

You might consider working through the Second Edition of _How to Design Programs_ instead; see http://www.ccs.neu.edu/home/matthias/HtDP2e/ .



Stephen Bloch
sbloch at adelphi.edu

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120221/cbf435ad/attachment.html>

Posted on the users mailing list.