source: project/wiki/eggref/5/checks @ 37165

Last change on this file since 37165 was 37165, checked in by juergen, 10 months ago

checks 1.0 docu

File size: 3.7 KB
Line 
1[[tags: egg]]
2[[toc:]]
3
4== Pre- and postconditions made easy
5
6This egg implements some routines, which are outsourced from
7simple-exceptions. In particular macros << and >>, which accept an
8argument or result, checks it against zero or more predicates and
9returns it in case of success unchanged. Otherwise it prints a
10meaningful error message, showing i.a. the offending predicate and the
11argument's or result's name. They are implemented as macros instead of
12procedures, because I didn't want an extra parameter with the argument's
13or result's name.
14In reimplementing those routines, I changed the syntax a bit, so be
15careful, if you used the eqally named routines from simple-expressions.
16
17=== Interface
18
19==== assert*
20
21<macro>(assert* loc xpr ....)</macro>
22
23checks the expressions xpr .... in sequence and raises an exception
24for the first failing expression with location property loc and
25arguments property the failing expression quoted.
26
27==== <<<
28
29<macro>(<<< loc arg arg? ...)</macro>
30
31precondition test:
32returns arg unchanged only if all predicates arg? return #t on it,
33otherwise an error message with the offending predicate and the
34location loc is printed.
35
36==== <<
37
38<macro>(<< arg arg? ...)</macro>
39
40precondition test:
41returns arg unchanged only if all predicates arg? return #t on it,
42otherwise an error message with the offending predicate is printed.
43
44==== >>>
45
46<macro>(>>> loc result result? ...)</macro>
47
48postcondition test:
49returns result unchanged only if all predicates result? return #t on it,
50otherwise an error message with the offending predicate and the
51location loc is printed.
52
53==== >>
54
55<macro>(>> result result? ...)</macro>
56
57postcondition test:
58passes result unchanged only if all predicates result? return #t on it
59otherwise an error message with the offending predicate is printed.
60
61==== true?
62
63<procedure>(true? xpr)</procedure>
64
65returns always #t
66
67==== false?
68
69<procedure>(false? xpr)</procedure>
70
71returns always #f
72
73=== Examples
74
75(define x 5)
76
77(<< x positive? odd?)
78; -> 5
79
80(<< x zero? odd?)
81; -> error
82
83(<< x positive? even?)
84; -> error
85
86
87== Last update
88
89Jan 30, 2019
90
91== Author
92
93[[/users/juergen-lorenz|Juergen Lorenz]]
94
95== License
96
97 Copyright (c) 2014-2019, Juergen Lorenz
98 All rights reserved.
99
100 Redistribution and use in source and binary forms, with or without
101 modification, are permitted provided that the following conditions are
102 met:
103 
104 Redistributions of source code must retain the above copyright
105 notice, this list of conditions and the following disclaimer.
106 
107 Redistributions in binary form must reproduce the above copyright
108 notice, this list of conditions and the following disclaimer in the
109 documentation and/or other materials provided with the distribution.
110 Neither the name of the author nor the names of its contributors may be
111 used to endorse or promote products derived from this software without
112 specific prior written permission.
113   
114 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
115 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
116 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
117 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
118 HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
119 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
120 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
121 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
122 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
123 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
124 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
125
126== Version History
127
128; 1.0 : extracted and modified from simple-exceptions
129
130
Note: See TracBrowser for help on using the repository browser.