Next: , Previous: , Up: iklib conditions   [Index]


6.12.8 One-based return value index conditions

Remembering that every expression may return multiple values, let’s say we need code like this:

(receive (a b c)
    (expression)
  (unless (fixnum? a) (raise-exception))
  (unless (symbol? b) (raise-exception))
  (unless (string? c) (raise-exception))
  ?body)

we might want to raise condition objects holding the index of the returned value; for this we can use &one-based-return-value-index as follows:

(receive (a b c)
    (expression)
  (internal-body
    (define (%error sexp idx obj)
      (raise
        (make-assertion-violation)
        (make-message-condition "failed object validation")
        (make-failed-expression-condition sexp)
        (make-one-based-return-value-index-condition idx)
        (make-irritants (list obj))))
    (unless (fixnum? a) (%error '(fixnum? a) 1 a))
    (unless (symbol? b) (%error '(symbol? b) 2 b))
    (unless (string? c) (%error '(string? c) 3 c)))
  ?body)
Condition Obect Type: &one-based-return-value-index

Condition type used to specify the one–based index of a return value in a tuple of return values from an expression. It is derived from &condition. It has the following fields:

index

A positive fixnum representing the one–based index of a return value.

Function: make-one-based-return-value-index-condition index

Build and return a new instance of &one-based-return-value-index.

Function: one-based-return-value-index-condition? obj

Return #t if obj is a condition object with component &one-based-return-value-index; otherwise return #f.

Function: condition-one-based-return-value-index cnd

Given a condition object of type &one-based-return-value-index return the index.