12 Functions

Functions are ubiquitous in Dylan. Generic functions and methods — the two kinds of function — are the primary means of specialization. Many common operations, such as slot references and arithmetic operations, are accomplished through function calls. In Dylan, unlike in many languages, functions are first-class objects. They can be the values of variables or slots, arguments to other functions, or values returned by functions. Dylan has functions that build new functions out of existing functions. Much of the power of Dylan arises through its sophisticated treatment of functions.

This chapter discusses general aspects of the operation of functions in Dylan. It does not describe all aspects of functions. In particular, we discuss the process of method dispatch within generic functions elsewhere (see Sections 5.5, 6.2, 9.3, and 18.4). This chapter covers three main topics:

1. The syntax of function calls, including abbreviations for function calls

2. The function-calling protocol, and particularly the interaction between a function and its caller

3. The uses of functions as objects, including ways of creating and operating on functions