Functional Languages
Key Concepts
- based on mathematical functions
(a mapping of members of one set (domain) to another set (range
set)
- evaluation order of their mapping expression is controlled
by recursion and
conditional expressions rather than
by sequencing and iterative repetition
- no side effects, so functions always define the same value
given the same set of arguments (referential
transparency)
- Functions are first-class entities — can be used as
parameters or return values
- No state, no variables, no assignment statements
- Functions and data take the same form (that of lists)
- Can easily express even basic operations as functions
Introduction to Scheme
(Most of the Scheme we will look at would require only minor
modifications to be rewritten as LISP functions.)
- Scheme interpreter -- a read-evaluate-write infinite loop
reads an expression type by user (in form of a list)
interprets the expression (by the function EVAL)
displays results
- Primitive functions -- deal only with numeric atoms
(* 3 7) | 21 | 3*7 |
(+ 5 7 2) | 14 | 5+7+2 |
(- 5 6) | -1 | 5-6 |
(- 15 7 2) | 6 | 15 - 7 - 2 |
(-24 (* 4 3)) | 12 | 24 - (4 * 3) |
(sqrt 49) | 7 | square root of 49 |
(sqrt -2) | 1.41421... i | v- 2i |
Alyce Brady, Kalamazoo College