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 (let’s say) we’re only going to use this once. We’d like to be able to represent the function itself as the argument to sum , rather than the function’s 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 isn’t evaluated, but the body isn’t evaluated when we see the lambda , either—only when we invoke the function can we evaluate its body. • Firstclass data types. A data type is considered firstclass 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 firstclass; perhaps text strings (or individual text characters) are firstclass;...
View
Full Document
 Spring '10
 Harvey,B
 formal parameter list, generalized sum function, Firstclass data types

Click to edit the document details