Add lab 4 content.
This commit is contained in:
4
labs/L04/application.rkt
Normal file
4
labs/L04/application.rkt
Normal file
@ -0,0 +1,4 @@
|
||||
#lang racket
|
||||
(require "hello.rkt")
|
||||
(require rackunit)
|
||||
(hello)
|
15
labs/L04/functions-as-values.rkt
Normal file
15
labs/L04/functions-as-values.rkt
Normal file
@ -0,0 +1,15 @@
|
||||
#lang slideshow
|
||||
(define (series mk)
|
||||
(hc-append 4 (mk 5) (mk 10) (mk 20)))
|
||||
|
||||
(define (series2 mk)
|
||||
(apply hc-append 4 (map mk '(5 10 20))))
|
||||
|
||||
(define (series3 mk)
|
||||
(apply hc-append 1 (build-list 100 mk)))
|
||||
|
||||
(module+ test
|
||||
(require rackunit)
|
||||
(require racket/serialize)
|
||||
(check-equal? (serialize (series circle)) (serialize(series2 circle))))
|
||||
|
11
labs/L04/hello.rkt
Normal file
11
labs/L04/hello.rkt
Normal file
@ -0,0 +1,11 @@
|
||||
(module hello racket
|
||||
(provide hello)
|
||||
(define (hello) (displayln "Hello world!"))
|
||||
|
||||
(module+ test
|
||||
(require rackunit)
|
||||
(check-equal? (with-output-to-string hello) "Hello world!\n")
|
||||
(check-equal? (with-output-to-string hello) (begin (sleep 3) "Hello world!\n")))
|
||||
|
||||
(module+ main
|
||||
(hello)))
|
9
labs/L04/recursion.rkt
Normal file
9
labs/L04/recursion.rkt
Normal file
@ -0,0 +1,9 @@
|
||||
#lang racket
|
||||
(define (fact n)
|
||||
(cond
|
||||
[(zero? n) 1]
|
||||
[else (* n (fact (sub1 n)))]))
|
||||
|
||||
(module+ test
|
||||
(require rackunit)
|
||||
(check-equal? (fact 10) 3628800))
|
Reference in New Issue
Block a user