> <\body> <\session|scheme|default> <\unfolded-io|Scheme] > (+ 1 1) <|unfolded-io> 2 <\unfolded-io|Scheme] > (begin \ \ (+ 1 1) \ \ (+ 1 3)) <|unfolded-io> 4 <\unfolded-io|Scheme] > (and (begin \ \ \ \ \ \ \ (debug-message "std" "branch 1\\n") \ \ \ \ \ \ \ #t) \ \ \ \ \ (begin \ \ \ \ \ \ \ (debug-message "std" "branch 2\\n") \ \ \ \ \ \ \ #t)) <|unfolded-io> #t <\unfolded-io|Scheme] > (or (begin \ \ \ \ \ \ \ (debug-message "std" "branch 1\\n") \ \ \ \ \ \ \ #t) \ \ \ \ \ (begin \ \ \ \ \ \ \ (debug-message "std" "branch 2\\n") \ \ \ \ \ \ \ #f)) <|unfolded-io> #t <\input|Scheme] > \; <\session|scheme|default> <\unfolded-io|Scheme] > (define result 0) <|unfolded-io> 0 <\input|Scheme] > (for (x (list 1 2 3 4)) \ \ (set! result (+ result x))) <\unfolded-io|Scheme] > result <|unfolded-io> 10 <\unfolded-io|Scheme] > (define (range n) \ \ (if (\= n 0) \ \ \ \ \ \ (list ) \ \ \ \ \ \ (append (range (- n 1)) (list n)))) <|unfolded-io> range <\unfolded-io|Scheme] > (range 5) <|unfolded-io> (1 2 3 4 5) <\unfolded-io|Scheme] > (define (sigma1 n) \ \ (define result1 0) \ \ (for (i (range n)) \ \ \ \ (set! result1 (+ result1 i))) \ \ result1) <|unfolded-io> sigma1 <\unfolded-io|Scheme] > (sigma1 100) <|unfolded-io> 5050 <\input|Scheme] > \; <\session|scheme|default> <\unfolded-io|Scheme] > (define (sigma2 n) \ \ (if (= n 0) \ \ \ \ \ \ 0 \ \ \ \ \ \ (+ n (sigma2 (- n 1))))); tail recursive <|unfolded-io> sigma2 <\unfolded-io|Scheme] > (sigma2 100) <|unfolded-io> 5050 <\input|Scheme] > \; <\session|scheme|default> <\unfolded-io|Scheme] > (define (sum start end) \ \ (cond ((\ start end) 0) \ \ \ \ \ \ \ \ ((= start end) end) \ \ \ \ \ \ \ \ (else (+ start \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (sum (+ start 1) end))))) <|unfolded-io> sum <\unfolded-io|Scheme] > (sum 2 100) <|unfolded-io> 5049 <\input|Scheme] > \; <\session|scheme|default> <\unfolded-io|Scheme] > (define (fib n) \ \ (cond ((= n 0) 0) \ \ \ \ \ \ \ \ ((= n 1) 1) \ \ \ \ \ \ \ \ (else (+ (fib (- n 1)) \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (fib (- n 2)))))) <|unfolded-io> fib <\unfolded-io|Scheme] > (fib 2) <|unfolded-io> 1 <\unfolded-io|Scheme] > (fib 4) <|unfolded-io> 3 <\unfolded-io|Scheme] > (stree-\tree \ '(tree "fib 2" \ \ \ \ \ \ \ \ (tree "fib 1" (tree 1)) \ \ \ \ \ \ \ \ (tree "fib 0" (tree 0)))) <|unfolded-io> >|>>> <\input|Scheme] ;> scheme tree \<#2018\>' \; <\session|scheme|default> <\unfolded-io|Scheme] > (define (fib2 n) \ \ (define a 0) \ \ (define b 1) \ \ (define old_b 0) \ \ (for (i (range n)) \ \ \ \ (set! old_b b) \ \ \ \ (set! b (+ a b)) \ \ \ \ (set! a old_b)) \ \ a) <|unfolded-io> fib2 <\unfolded-io|Scheme] > (fib2 2) <|unfolded-io> 1 <\input|Scheme] > \; <\session|scheme|default> <\unfolded-io|Scheme] > (define (fib3 n) \ \ (define (fib_ab n a b) \ \ \ \ (if (\= n 0) \ \ \ \ \ \ \ \ a \ \ \ \ \ \ \ \ (fib_ab (- n 1) b (+ a b)))) \ \ (fib_ab n 0 1)) <|unfolded-io> fib3 <\unfolded-io|Scheme] > (fib3 -1) <|unfolded-io> 0 <\input|Scheme] > \; <\initial> <\collection> <\references> <\collection> > > > > > <\auxiliary> <\collection> <\associate|toc> |math-font-series||Slide 2> |.>>>>|> |math-font-series||Slide 3> |.>>>>|> |math-font-series||Slide 4> |.>>>>|> |math-font-series||Slide 5> |.>>>>|> |math-font-series||Slide 6> |.>>>>|>