;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname Funcl-12EGs) (read-case-sensitive #t) (teachpacks ((lib "docs.rkt" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "docs.rkt" "teachpack" "htdp")) #f))) (let ((x 10)) ; slide 13 Functional-12 (let ((f (lambda (a) (+ a x)))) (let ((x 2)) (* x (f 3))))) (define (len ys) ; slide 16 Functional-12 (if (null? ys) 0 (+ 1 (len (cdr ys))))) (len '(3 4 5)) (define (lentr ys tot) ; slide 16 -tail recursive fcn (if (null? ys) tot (lentr (cdr ys) (+ 1 tot)))) (define (len2 ys) (lentr ys 0)) (len2 '(3 4 5)) (define (fact n); original factorial fcn (cond ((zero? n) 1) ((eq? n 1) 1) (else (* n (fact (- n 1)))))) (fact 1) (fact 5) (define (factor n acc) ;helper fcn is tail recursive (cond ((zero? n) 1) ((eq? n 1) acc) (else (factor (- n 1) (* n acc))))) (define (factorial n) (factor n 1)) (factorial 1) (factorial 3) (let ((x 5)) ; slide 19 Fncl-12 lecture showing closures (let ((f (let ((x 10)) (lambda (y) x)))) (list x (f 1) x (f 1)))) (define (gg z) (let* ((x 2) (f (lambda (y) (+ x y)))) (map f z))) (gg '(1 2 3)) gg (define (curried+ x) (lambda(y) (+ x y))) ; slide 22, Fncl-12 lecture ((curried+ 2) 3) (let ((f (curried+ 1))) (f 10)) (define hh (lambda(x) (lambda(y) (* x y)))) ; slide 23 Fcnl-12 hh ((hh 2) 20) (hh 2) ; (hh 2 3) hh: expects only 1 argument, but found 2