|
From: | Kon Lovett |
Subject: | Re: [Chicken-users] Integrating unit tests into source code |
Date: | Thu, 14 Dec 2006 09:48:54 -0800 |
On Dec 14, 2006, at 1:51 AM, felix winkelmann wrote:
Err, maybe in-between ;-) Plain doc-strings are nice for REPL usage, so sure. But I agree w/ Peter that contracts are better at the procedure definition locus than tests. They are not called "unit tests" for nothing. (Check out "signature-type.scm" in the 'procedure-surface' egg for a start down this road.) As you know, I would like declare to be legal within a lambda form: (define (fixnum+ a b) (declare (documentation (p (code "fixnum+") " takes two fixnums, " (tt "a") " & " (tt "b") ", and returns the sum.")) (contract (-> fixnum fixnum fixnum) (if (= 0 a) b (+ (sub1 a) (add1 b)))) (fixnum)) (+ a b) ) The contract signature is enforced, unless '(no-signature-checks)' or '(unsafe)', by the compiler (or interpreter?) inserting code that does fixnum? checks & aborts w/ (condition (exn type fixnum)) if violated. And the simpler, doc-string, form: (define (fixnum+ a b) "fixnum+ takes two fixnums, a & b, and returns the sum." (+ a b) ) Is interpreted as: (define (fixnum+ a b) (declare (documentation "fixnum+ takes two fixnums, a & b, and returns the sum.")) (+ a b) ) And the form: (define (fixnum+ a b) (declare (contract (-> fixnum fixnum fixnum) (if (= 0 a) b (+ (sub1 a) (add1 b)))) (fixnum)) (+ a b) ) Is interpreted as: (define (fixnum+ a b) (declare (documentation (code "(fixnum+ (fixnum a) (fixnum b) fixnum)")) (contract (-> fixnum fixnum fixnum) (if (= 0 a) b (+ (sub1 a) (add1 b)))) (fixnum)) (+ a b) ) At the toplevel declare '(documentation ...)' makes sense but '(contract ...)' I doubt. Best Wishes, Kon
|
[Prev in Thread] | Current Thread | [Next in Thread] |