Lec3 - CMPSC461:ProgrammingLanguage Concepts Lecture3 Instructor:Prof.SwaratChaudhuri Recursion,[email protected] nbyncheckerboard Fibonacci Fib(0)=0

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CMPSC461:ProgrammingLanguage Concepts Lecture3 Instructor:Prof.SwaratChaudhuri Recursion,[email protected] nbyncheckerboard Fibonacci: Fib(0)=0 Fib(1)=1 Fib(n)=Fib(n1)+Fib(n2) Sumofthefirstnnaturalnumbers Sumoftheallevennumbersupton Thesum(1+c+2*c+3*c+...+c*n) Thesum(1+c+c2+c3+...+cn) [email protected] Howannoyingwouldbetogiveanameto everyconstantvalue? (definex2)ratherthanjust2 Sowhyareyouexpectedtoassignanameto [email protected]??? InScheme,[email protected] (lambda(x)exp) e.g.,(lambda(xy)(*xyy)) aprocedurethattakesx,yandcomputesxy2. Proceduresarejustdata Nobasicdifferencebetween"foo"and2 Well,ok,onethingisthat"foo"doesn'tprint sonicely Socanwepassproceduresasparameters??? Yes!(Higherorderprogramming) Writeaproceduretwicethattakesinaprocedurefanda valuexandappliesftwicetog. (define(twicefx)(f(fx))) [email protected]@onsfandg. Givenf,compute sum=f(0)+f(1)+f(2)+... (define(pictseriesf) (hcappend5(f2)(f5)(f8)(f10))) (definepictseries(lambda(f) (hcappend5(f2)(f5)(f8)(f10)))) Lists [email protected] Listdatastructure: Listx car(x) cdr(x) (null?x) (consheadtail) [email protected]@oncalls:'(123) (list1234) ...
View Full Document

This note was uploaded on 09/30/2008 for the course CMPSC 461 taught by Professor Chaudhuri during the Fall '08 term at Pennsylvania State University, University Park.

Ask a homework question - tutors are online