next prev up top content index

11 The Built-In Classes

Functions

Functions are the objects that accept arguments, perform computations, and return values.

Figure 11-5 shows the built-in function classes and some of their characteristics.

Figure 11-5 The Function Classes

Function Class Hierarchy
S – Sealed P – Primary C – Concrete I – Instantiable
O – Open F – Free A – Abstract U – Uninstantiable

General Functions

<function> [Sealed Abstract Class]


The class of objects that can be applied to arguments.

Superclasses:

<object>

Init-keywords:

None.

Description:

All functions are instances of <function>. Functions are described in Chapter 6, "Functions."

Operations:

The class <function> provides the following operations:

Table 11-65 Functions on <function>

Function

Description

Page

compose

Returns the composition of one or more functions.

346

complement

Returns a function that expresses the complement of a predicate.

346

disjoin

Returns a function that expresses the disjunction of one or more predicates.

347

conjoin

Returns a function that expresses the conjunction of one or more predicates.

347

curry

Returns a function based on an existing function and a number of default initial arguments.

348

rcurry

Returns a function based on an existing function and a number of default final arguments.

349

function-specializers

Returns the specializers of a function.

353

function-arguments

Returns information about the arguments accepted by a function.

354

function-return-values

Returns information about the values returned by a function.

354

applicable-method?

Tests if a function is applicable to sample arguments.

355

apply

Applies a function to arguments.

350

do

Iterates over one or more collections for side effect.

327

map

Iterates over one or more collections and collects the results in a freshly allocated collection.

328

map-as

Iterates over one or more collections and collects the results in a freshly allocated collection of a specified type.

328

map-into

Iterates over one or more collections and collects the results in an existing mutable collection.

329

any?

Returns the first true value obtained by iterating over one or more collections.

330

every?

Returns true if a predicate returns true when applied to all corresponding elements of a set of collections.

331

reduce

Combines the elements of a collection and a seed value into a single value by repeatedly applying a binary function.

331

reduce1

Combines the elements of a collection into a single value by repeatedly applying a binary function, using the first element of the collection as the seed value.

332

find-key

Returns the key in a collection such that the corresponding collection element satisfies a predicate.

335

replace-elements!

Replaces those collection elements that satisfy a predicate.

336

choose

Returns those elements of a sequence that satisfy a predicate.

333

choose-by

Returns those elements of a sequence that correspond to those in another sequence that satisfy a predicate.

333

do-handlers

Applies a function to all dynamically active handlers.

362

Generic Functions

<generic-function> [Sealed Instantiable Class]


The class of functions that are made up of a number of individual methods.

Superclasses:

<function>

Init-keywords:

The class <generic-function> supports the following init-keywords:

required:

An instance of <number> or <sequence>.

This argument represents the required arguments that the generic function accepts. If a sequence is supplied, the size of the sequence is the number of required arguments, and the elements of the sequence are the specializers. If a number is supplied, it is the number of required arguments, and the specializers default to <object>. If the argument is not supplied, or the supplied argument is neither a sequence nor a non-negative integer, an error is signaled.

rest?:

An instance of <boolean>.

A true value indicates that the generic function accepts a variable number of arguments. The default value is #f.

key:

#f or an instance of <collection> whose elements are keywords.

If the value is a collection, then the generic function accepts keyword arguments, and the collection specifies the set of mandatory keywords for the generic function. A value of #f indicates that the generic function does not accept keyword arguments. The default value is #f.

all-keys?:

An instance of <boolean>.

A true value indicates that the generic function accepts all keyword arguments. The default value is #f.

Description:

The class of generic functions. Generic functions are described in Chapter 6, "Functions."

The arguments describe the shape of the generic function's parameter list, and thereby control which methods can be added to the generic function. See the section "Kinds of Parameter Lists" on page 86 and the section "Parameter List Congruency" on page 93 for the implications of these choices.

An error is signaled if the value of rest?: is true and the value of key: is a collection. While a method parameter list may specify both #rest and #key, a generic function parameter list cannot.

An error is signaled if the value of all-keys?: is true and the value of key: is #f.

A new generic function initially has no methods. An error will be signaled if a generic function is called before methods are added to it. Once a generic function is created, you can give it behavior by adding methods to it with add-method or define method.

Generic functions are not usually created by calling make directly. Most often they are created by define generic or implicitly by define method.

Operations: The class <generic-function> provides the following operations:

Table 11-66 Functions on <generic-function>

Function

Description

Page

generic-function-methods

Returns the methods of a generic function.

351

add-method

Adds a method to a generic function.

352

generic-function-mandatory-keywords

Returns the mandatory keywords of a generic function, if any.

353

sorted-applicable-methods

Returns all the methods in a generic function that are applicable to sample arguments, sorted in order of specificity.

356

find-method

Returns the method in a generic function that has particular specializers.

356

remove-method

Removes a method from a generic function.

357

Methods

<method> [Sealed Class]


The class of functions that are applicable to arguments of a specified type.

Superclasses:

<function>

Init-keywords:

None.

Description:

The class of methods. Methods are described in Chapter 6, "Functions."

Operations:

The class <method> provides the following operations:

Table 11-67 Functions on <method>

Function

Description

Page

add-method

Adds a method to a generic function.

352

remove-method

Removes a method from a generic function.

357