Next: , Previous: , Up: args   [Index]


8.3 Performing arguments validation

The following bindings are exported by the library (vicare arguments validation).

Macro: with-arguments-validation (?who) ((?validator ?arg ...) ...) ?body0 . ?body

If arguments validation is enabled: expand to code that validates the ?arg expressions using to the ?validator clause, then evaluate the ?body forms; if arguments validation is disabled: just evaluate the ?body forms.

?who must be an identifier used as argument when building a &who condition object.

?validator must be one among:

NOTE In future a full logic expression may be possible as ?validator argument. At present only the special or case is supported, with false as first operand.

Simple example:

(define-argument-validation (fixnum who obj)
  (fixnum? obj)
  (procedure-argument-violation who
    "expected fixnum as argument"
    obj))

(define-argument-validation (integer who obj)
  (integer? obj)
  (procedure-argument-violation who
    "expected integer as argument"
    obj))

(with-arguments-validation (who)
     ((fixnum  X)
      (integer Y))
  (do-this)
  (do-that))

multiple clauses are evaluated from first to last, so the above example is equivalent to:

(with-arguments-validation (who)
     ((fixnum  X))
  (with-arguments-validation (who)
       ((integer Y))
    (do-this)
    (do-that)))

which is equivalent to something like:

(if (fixnum? X)
    (if (integer? X)
        (begin
          (do-this)
          (do-that))
      (procedure-argument-violation who
        "expected integer as argument"
        obj))
  (procedure-argument-violation who
    "expected fixnum as argument"
    obj))
Macro: with-dangerous-arguments-validation (?who) ((?validator ?arg ...) ...) ?body0 . ?body

Like with-arguments-validation, but the validation is always performed even when global arguments validation is disabled.


Next: , Previous: , Up: args   [Index]