[racket] Help with exception raising and testing

From: Galler (lzgaller at optonline.net)
Date: Tue Aug 27 20:48:42 EDT 2013

>>why a thunk?

The inferential leap to be made is that Racket uses applicative order,
meaning the arguments of a procedure are each evaluated from left-to-right
before the procedure is itself evaluated

for example:
(+ 1 (+ 2 3))

is reduced to 

(+ 1 5)

before being evaluated as

6

the procedure (test-exn...) is no different

the way you initially wrote your code,  (sum-coins -1 ...) is evaluated and
throws an error  *before* test-exn is evaluated.

If a library function asks for a thunk as an argument, the author generally
intends to run the given function in some customized context.

 For example, in the case of test-exn, the author provided customized error
handling, error type-checking, and reporting. 

> Does this mean I have to teach my students about lambda definitions before
I can have them use rackunit for testing?

Only to the extent you want to use test-exn. Perhaps you could provide it as
a syntactical-recipe for using that particular rackunit function, if it
doesn't fit into your desired pedagogical sequence. 

Its the first sentence under the definition. See:
http://docs.racket-lang.org/reference/exns.html?q=raise-argument-error#%28def._%28%28quote._~23~25kernel%29._raise-argument-error%29%29

"Creates an exn:fail:contract value and raises it as an exception"

R/
Zack




Posted on the users mailing list.