|
@@ -0,0 +1,63 @@
|
|
|
+#lang racket
|
|
|
+(define (minimum L)
|
|
|
+ (let ((x (car L))
|
|
|
+ (xs (cdr L)))
|
|
|
+ (if (null? xs)
|
|
|
+ x
|
|
|
+ (minimum
|
|
|
+ (cons
|
|
|
+ (if (< x (car xs))
|
|
|
+ x
|
|
|
+ (car xs))
|
|
|
+ (cdr xs))))))
|
|
|
+(minimum '(2 2 1 4 5))
|
|
|
+
|
|
|
+(define (minimum2 x . rest)
|
|
|
+ (if (null? rest)
|
|
|
+ x
|
|
|
+ (apply minimum2
|
|
|
+ (cons
|
|
|
+ (if (< x (car rest))
|
|
|
+ x
|
|
|
+ (car rest))
|
|
|
+ (cdr rest)))))
|
|
|
+(minimum2 5 9 7 88 54 79)
|
|
|
+
|
|
|
+(let ((x 0))
|
|
|
+ (let label ()
|
|
|
+ (when (< x 10)
|
|
|
+ (display x)
|
|
|
+ (newline)
|
|
|
+ (set! x (+ x 1))
|
|
|
+ (label))))
|
|
|
+
|
|
|
+(let label ((x 10))
|
|
|
+ (when (> x 0)
|
|
|
+ (display x)
|
|
|
+ (newline)
|
|
|
+ (label (- x 1))))
|
|
|
+
|
|
|
+(define (fact x)
|
|
|
+ (define (fact-tail x accum)
|
|
|
+ (if (= x 0)
|
|
|
+ accum
|
|
|
+ (fact-tail (- x 1) (* accum x))))
|
|
|
+ (fact-tail x 1))
|
|
|
+(fact 10)
|
|
|
+
|
|
|
+(for-each (lambda (x)
|
|
|
+ (display x) (newline))
|
|
|
+ '(this is it))
|
|
|
+
|
|
|
+(define (vector-for-each body vect)
|
|
|
+ (let ((max (- (vector-length vect) 1)))
|
|
|
+ (let loop ((i 0))
|
|
|
+ (body (vector-ref vect i))
|
|
|
+ (when (< i max)
|
|
|
+ (loop (+ i 1))))))
|
|
|
+
|
|
|
+(vector-for-each (lambda (x)
|
|
|
+ (display x) (newline))
|
|
|
+ #(this is it))
|
|
|
+
|
|
|
+
|