chickadee » srfi-253 » define-checked

(lambda-checked ((arg-name predicate?) args ...) body ...)syntax
(define-checked (name ((arg-name predicate?) args ...) body ...))syntax
(define-checked name predicate? value)syntax

A regular lambda, but where any argument checks (akin to calling check-arg directly) can be specified by writing (arg-name predicate?) in where a regular lambda would only allow arg-name.

Example:

 
(import (srfi 253))

(define foo (lambda-checked ((x number?)) (+ x 1)))

(foo 2)             ;=> 3
(foo "hello world") ;=> An error is raised

define-checked relates to lambda-checked the same way that define relates to lambda. The second form of define-checked validates that the value bound to name satisfies predicate?, or else an error is raised. define-checked also produces CHICKEN type declarations (see types) that match the defined function as well.

IMPORTANT NOTE: "rest" args such as ((arg1 pred?) args . rest) are not supported by this implementation, and will produce an compilation error if used.