Lecture overview -- Keyboard shortcut: 'u'  Previous page: Lambda expressions in Scheme -- Keyboard shortcut: 'p'  Next page: Optional parameters of Scheme functions (2) -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home    Lecture 2 - Page 40 : 46
Functional Programming in Scheme
Expressions, Types, and Functions
Optional parameters of Scheme functions (1)

It is often useful to pass one or more optional parameters to a function

In case an optional parameter is not passed explicitly, a default value should apply

(define (f rp . optional-parameter-list)
 (let ((op1 (optional-parameter 1 optional-parameter-list 1))
       (op2 (optional-parameter 2 optional-parameter-list "a"))
       (op3 (optional-parameter 3 optional-parameter-list #f)))
  (list rp op1 op2 op3)))

A example of a function f that accepts optional-parameters. Besides the required parameter rp, the function accepts an arbitrary number of additional parameters, the list of which are bound to the formal parameter optional-parameter-list. The function optional-parameter from the LAML general library accesses information from optional-parameter-list. In case an optional parameter is not passed, the default value (the last parameter of optional-parameter) applies.

y:/Kurt/Files/courses/prog3/prog3-03/sources/notes/includes/optional-par-sessionA number of calls of the function f.

For clarity we define f as the first interaction.