(1)
(quotient 10 2)
(quotient (+ 8 7) 5)
(+ (* 3
(+ (* 2 4)
(+ 3 5)))
(+ (- 10 7)
6))
(2)
(define pi 3.14)
(* pi 2)
(define (Abs x)
(if (< x 0)
(- x)
x))
(Abs -3)
(3)
(define (square x) (* x x))
(define (average x y) (/ (+ x y) 2))
(average 2 3)
(4)
(load "demo.scm")
(5)
(define (plus4 x) (+ x 4))
(define plus4 (lambda (x) (+ x 4)))
((lambda (x y z) (+ x y (square z)))1 2 3)
(define (square x) (* x x))
(define sum-square
(lambda (x y) (+ (square x) (square y)))
)
(sum-square 3 4)
(print "Hello, World!")
(6)
#lang racket
(define (square x) (* x x))
((lambda (x y z) (+ x y (square z))) 1 2 3)
(print "hello")
(7)
#lang racket
(define (fib n)
(cond ((= n 0) 0)
((= n 1) 1)
(else (+ (fib (- n 1)) (fib (- n 2))))
)
)
(fib 35)
(8)
(begin (print 1) (print 2) 3 4 5)
(9)
(define x 9)
(cond ((> x 10) (begin (print "big") (print "guy")))
(else (begin (begin (print "small") (print "fry")))))
(10)
(if (> x 10) (begin
(print 'big')
(print 'guy'))
(begin
(print 'small')
(print 'fry')))
(11)
(define a 2)
(define b 3)
(define c (let ((a 3)
(b (+ 2 2)))
(sqrt (+ (* a a) (* b b)))))
c
(12)
(let ((a 3) (b 3)) (sum-square a b))
(13)
(define a (cons 1 (cons 2 (cons 3 (cons 4 null)))))
a
(14)
(cons 1 (cons 2 null))
(define x (cons 1 (cons 2 null)))
x
(car x)
(cdr x)
(cons 1 (cons 2 (cons 3 (cons 4 null))))
(15)
(define a 1)
(define b 2)
(list a b)
(16)
(list quotient 10 2)
(eval (list quotient 10 2))
(17)
(begin
(define (f x total)
(if (< x 10)
(f (+ x 2) (+ total (* x x)))
total))
(f 2 0))
(begin
(define (f x total)
(if (< (* x x) 50)
(f (+ x 1) (+ total x))
total))
(f 1 0))))
(18)
(define (sum-while starting-x while-condition add-to-total update-x)
(begin
(define (f x total)
(if while-condition
(f update-x (+ total, add-to-total))
total
)
)
(f starting-x 0)
)
)
(eval (sum-while 2 (< x 10) (* x x) (+ x 2)))
(eval (sum-while 1 (< (* x x) 50) x (+ x 1)))