Add lab 4 content.

This commit is contained in:
Isaac Shoebottom
2022-09-22 16:16:55 -03:00
parent baf9b933de
commit 3bb4db362e
8 changed files with 100 additions and 2 deletions

4
labs/L04/application.rkt Normal file
View File

@ -0,0 +1,4 @@
#lang racket
(require "hello.rkt")
(require rackunit)
(hello)

View 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
View 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
View 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))