Next: , Previous: , Up: syntaxes   [Contents][Index]


5.7 Branching on type of expression

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

Syntax: case-type ?expr ?clause0 ?clause
Auxiliary Syntax: =>
Auxiliary Syntax: else

Similar to case but branches based on the type of the single value returned by ?expr. This syntax is meant to be used with the typed language only, its behaviour is unspecified when using the standard language.

Each ?clause must have one of the formats:

((?type-id) . ?body)
((?type-id) => ?receiver-expr)
(else . ?body)

where: ?type-id must be a type identifier; the else clause is valid only as last clause; ?receiver-expr must be an expression evaluating to a closure object accepting a single argument.

Examples:

(case-type 123
  ((<vector>)   'vector)
  ((<fixnum>)   'fixnum)
  ((<string>)   'string))
⇒ no values

(case-type 123
  ((<vector>)   'vector)
  ((<fixnum>)   => (lambda (arg) (list arg 'fixnum)))
  ((<string>)   'string)
  (else   'else))
⇒ (123 fixnum)

(case-type #t
  ((<vector>)   'vector)
  ((<fixnum>)   'fixnum)
  ((<string>)   'string)
  (else         'else))
⇒ else