Next: , Previous: , Up: Generic Procedures   [Contents][Index]


4.1 Generic Procedure Datatype

The following definitions are used to construct and inspect generic procedures.

Procedure: make-generic-procedure arity [name]

Creates and returns a new generic procedure. The generic procedure requires arity arguments.

Arity may take one of the following forms. An exact positive integer specifies that the procedure will accept exactly that number of arguments. A pair of two exact positive integers specifies inclusive lower and upper bounds, respectively, on the number of arguments accepted; the CDR may be #f indicating no upper bound.

Name is used for debugging: it is a symbol that has no role in the semantics of the generic procedure. Name may be #f to indicate that the generic procedure is anonymous. If name is not specified, it defaults to #f.

Examples:

(define foo-bar (make-generic-procedure 2))

(define foo-baz (make-generic-procedure '(1 . 2) 'foo-baz))

(define foo-mum (make-generic-procedure '(1 . #f)))
Syntax: define-generic name lambda-list

Defines name to be a generic procedure. Lambda-list is an ordinary parameter list, which is exactly like the parameter list in a lambda special form. This expands into

(define name
  (make-generic-procedure arity
                          (quote name)))

where arity is determined from lambda-list.

Examples (compare to examples of make-generic-procedure):

(define-generic foo-bar (x y))

(define-generic foo-baz (x #!optional y))

(define-generic foo-mum (x . y))
Procedure: generic-procedure? object

Returns #t if object is a generic procedure, otherwise returns #f. Note that every generic procedure satisfies the predicate procedure?.

Procedure: generic-procedure-arity generic-procedure

Returns the arity of generic-procedure, as specified in the call to make-generic-procedure. The returned arity must not be modified.

Procedure: generic-procedure-name generic-procedure

Returns the name of generic-procedure, as specified in the call to make-generic-procedure.


Next: , Previous: , Up: Generic Procedures   [Contents][Index]