CS135 Lecture : Intro to Computer Science Introduction to functional programming in scheme, defining constants and functions

52 views1 pages

Document Summary

Our definitions f(x) = x2,g(x,y)=x+y become: (define (fx) (* x x)) (define (g x y (+ x y)) Define is a special form (looks like a scheme function, but not all of its arguments are evaluated). It binds a name to an expression (which uses the parameters that follow the name). The body expression typically uses the parameters together with other built-in and user- defined functions. Replace the parameters with values in order to call function (i. e (g 3 5) will result in 8) Each parameter name has meaning only within the body of its function: (define (fx) (* x x)) (define (g x y (+ x y)) There will be no confusion between the x values. Kind of like a local variable in java. The definitions k = 3 and p = k2 become: (define k 3) binds 3 to the function k (define p (* k k)) binds the product of (k *k) to p .

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions