manpagez: man pages & more
info bigloo
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16.4 Assertions

bigloo syntax: assert (var…) s-expression

Assertions can be enabled or disabled using Bigloo’s compilation flags -g flag to enable them). If the assertions are disabled they are not evaluated. If an assertion is evaluated, if the expression exp does not evaluate to #t, an error is signaled and the interpreter is launched in an environment where var… are bound to their current values.

Assertion forms are legal expressions which always evaluate to the unspecified object.

Here is an example of assertion usage:

(module foo
   (eval (export foo)))

(define (foo x y)
   [assert (x y) (< x y)]
   (labels ((gee (t)
                 [assert (t) (>= t 0)]
                 (let ((res (+ x t)))
                    [assert (res t) (> res 10)]
                    res)))
      (set! x (gee y))
      [assert (x) (> x 10)]
      x))

(repl)

This module is compiled with the -g flag to enable assertions, then the produced executable is run:

$ a.out

1:=> (foo 1 2)

File "foo.scm", line 9, character 158:
#                   [assert (res t) (> res 10)]
#                   ^
# *** ERROR:bigloo:assert
# assertion failed – (BEGIN (> RES 10))
    0. GEE
    1. FOO
———————–
Variables’ value are : 
   RES : 3
   T : 2
———————–
*:=> ^D
File "foo.scm", line 12, character 228:
#      [assert (x) (> x 10)]
#      ^
# *** ERROR:bigloo:assert
# assertion failed – (BEGIN (> X 10))
    0. FOO
———————–
Variables’ value are : 
   X : 3
———————–

*:=> 3
1:=> (foo 1 2)
File "foo.scm", line 9, character 158:
#                   [assert (res t) (> res 10)]
#                   ^
# *** ERROR:bigloo:assert
# assertion failed – (BEGIN (> RES 10))
    0. GEE
    1. FOO
———————–
Variables’ value are : 
   RES : 3
   T : 2
———————–

*:=> 

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on March 31, 2014 using texi2html 5.0.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.