#lang racket ; export everything (provide (all-defined-out)) (define x 3) ; val x = 3 (define y (+ x 2)) ; call + (define cube1 (lambda (x) (* x (* x x)))) ; (x * (x * x)) (define cube2 (lambda (x) (* x x x))) (define (cube3 x) (* x x x)) (define (pow1 x y) ; x to the yth power (if (= y 0) 1 (* x (pow1 x (- y 1))))) (define pow2 (lambda (x) (lambda (y) (pow1 x y)))) (define pow3 (lambda (x) (lambda (y) (if (= y 0) 1 (* x ((pow3 x) (- y 1))))))) (define three-to-the (pow2 3)) (define sixteen ((pow3 2) 4)) (define ntimes (lambda (f) (lambda (n) (lambda (x) (if (= n 0) x (f (((ntimes f) (- n 1)) x))))))) (define (sum xs) (if (null? xs) 0 (+ (car xs) (sum (cdr xs))))) (define (my-append xs ys) (if (null? xs) ys (cons (car xs) (my-append (cdr xs) ys)))) (define (my-map f xs) (if (null? xs) null (cons (f (car xs)) (my-map f (cdr xs))))) (define (my-fold f acc xs) (if (null? xs) acc (f (car xs) (my-fold f acc (cdr xs))))) (define (range n) (if (= n 0) '(0) (cons n (range (- n 1))))) (define (fact n) (if (= n 0) 1 (* n (fact (- n 1))))) (define (fib n) (if (<= n 1) 1 (+ (fib (- n 1)) (fib (- n 2))))) (define (fib2 n) (define (loop f1 f2 n) (if (<= n 0) f2 (loop (+ f1 f2) f1 (- n 1)))) (loop 1 1 n)) (define uW 30) (define uH 60) (define (mkUniv) (my-map (lambda (i) (my-map (lambda (i) ".") (range uW))) (range uH))) ;(define (prUniv u) ; (my-map (lambda (r) ; (my-map print r) ; (newline) ; null) ; u)) (define (prUniv u) (for/list ([r u]) (for/list ([c r]) (print c)) (newline))) (car '(* 3 3 3))