This preview shows page 1. Sign up to view the full content.
Unformatted text preview: Unnamed functions. Suppose we want to compute sin 2 5 + sin 2 6 + sin 2 7 + sin 2 8 We can use the generalized sum function this way: > (define (sinsq x) (* (sin x) (sin x))) > (sum sinsq 5 8) 2.408069916229755 But it seems a shame to have to define a named function sinsq that (lets say) were only going to use this once. Wed like to be able to represent the function itself as the argument to sum , rather than the functions name. We can do this using lambda : > (sum (lambda (x) (* (sin x) (sin x))) 5 8) 2.408069916229755 Lambda is a special form; the formal parameter list obviously isnt evaluated, but the body isnt evaluated when we see the lambda , eitheronly when we invoke the function can we evaluate its body. First-class data types. A data type is considered first-class in a language if it can be the value of a variable (i.e., named) an argument to a function the return value from a function a member of an aggregate In most languages, numbers are first-class; perhaps text strings (or individual text characters) are first-class;...
View Full Document
- Spring '10