Slide 1SchemeScheme vs. PythonSlide 4Getting StartedSlide 6Quick SortSlide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Scheme Functional Programming: Lambda CalculusList Recursion Style Style Style …PermutationsSlide 20Slide 21Fun Debugging in DrSchemeScheme for Python ProgrammersCSE 399 005Valeria MonteroScheme-LISP origins-AI (MIT): High level features reprogram Slower-Teaching-Scheme and Python: Lambda, deep lexicalsScheme vs. Python-Synthax: Prefix vs. main-stream-Lexical Scope: Parentheses vs. Whitespace-Control Structures: Functional (tail-recursion-optimizing) vs. . . mainstream (while, for loops)-Support: Standard (R5RS, IEEE) vs. not -OOP: indirect support vs. Standard object system -Orientation: Mathematical vs. ProcessorScheme vs. Python-Implementation: Many vs. 2 synchronized . (Portable)-Garbage collection: Strong (cycles) vs. weak -Built in: No standard library vs. many data types, functions . (regular expressions, internet connectivity)-Macros vs. not-Scheme great for scripting/extensionGetting StartedDefine;Create new objects: Global Variable or Function(define <GlobalVariable1> <value1>)(define <function1 <expression1>)Operators(<operator> <expression1> <expression2> …)Common Operators: and, or, not, -, +, *, %, /SchemePythonPre-Operator Order(< a b) => #t(+ 3 5) => 8(and #t #f) => #f(Blocks)Quick SortConditional(cond (<condition1> <execute1>) (<condition2> <execute2>) (<conditionn> <executen>))Absolute Value:(define (abs x) (cond ((< x 0) (- x)) (x)))Python:IfElifElseCAR and CDR(car list) => first element(car '(a b c)) => a(cdr list) => list excluding car(cdr '(a b c)) => (b c)Play Around with Nested Lists: Reference maximum four car/cdr(cadar '((1 2 3) 3)) => 2(cadr '(1 2 3)) => 2(cadar '((1 2 3) 4 5 6)) => 2(cddddr '(1 2 3 4 5 6)) =>(5 6)APPEND and CONSAppend: Concatenates two listsCons: Constructs list with input: car, cdr> (append '(1 2) '(3 4))(1 2 3 4)> (cons '(1 2) '(3 4))((1 2) 3 4)LetVariables are bounded locally within Let body.(let ((variable1 value1) ...) expression1 expression2 ...)(let ((a (* 4 4))) (+ a a)) => 32(let ((+ *)) (+ 2 3)) => 6 Absolute Value:(define (abs n) (let ((a n) (b (-n))) (max a b)))Let vs. Let*Let evaluates the variables in parallel.Let* evaluates the variables sequentially.(let ((a 5) (b (* a 10)))b)=> reference to undefined identifier: a(let* ((a 5) (b (* a 10)))b)=> 50Python Parallel assignmentsa, b = b, aScheme Functional Programming: Lambda CalculusCOND Absolute Value:(define (abs x) (cond ((< x 0) (- x)) (x)))LET Absolute Value:(define (abs n) (let ((a n) (b (-n))) (max a b)))Lambda (λ)((lambda (variable1 ...) expression1 expression2 ...) value1 ...) λ Absolute Value:(define abs (λ (n) (if (>= n 0) n (- n))))List Recursion Style Style Style …PermutationsFor ComparisonDo: Iterative vs. Recursive(do ((variable1 value1) (variable2 value2) …) ((exitCondition) (exitFunction)) Body)Fun Debugging in DrScheme(car '())> car: expects argument of type <pair>; given
View Full Document