From 3bb4db362e224b901dac423e2eabbc3af0b38356 Mon Sep 17 00:00:00 2001 From: Isaac Shoebottom Date: Thu, 22 Sep 2022 16:16:55 -0300 Subject: [PATCH] Add lab 4 content. --- journal/_src/posts/2022-09-21-lab-four.md | 17 +++++++++++ .../2022-09-21-lab-three-scribble-demo.scrbl | 14 +++++++++ journal/index.html | 30 +++++++++++++++++-- journal/sitemap.txt | 2 ++ labs/L04/application.rkt | 4 +++ labs/L04/functions-as-values.rkt | 15 ++++++++++ labs/L04/hello.rkt | 11 +++++++ labs/L04/recursion.rkt | 9 ++++++ 8 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 journal/_src/posts/2022-09-21-lab-four.md create mode 100644 journal/_src/posts/2022-09-21-lab-three-scribble-demo.scrbl create mode 100644 labs/L04/application.rkt create mode 100644 labs/L04/functions-as-values.rkt create mode 100644 labs/L04/hello.rkt create mode 100644 labs/L04/recursion.rkt diff --git a/journal/_src/posts/2022-09-21-lab-four.md b/journal/_src/posts/2022-09-21-lab-four.md new file mode 100644 index 0000000..6ace84a --- /dev/null +++ b/journal/_src/posts/2022-09-21-lab-four.md @@ -0,0 +1,17 @@ + Title: Lab Four + Date: 2022-09-21T08:30:00 + Tags: cs2163, lab, racket, scribble + +In this lab I learned about using functions as values, recursion, scribble, and modules in Racket. + +## Functions as values +You can pass functions as values into other functions which can then be used inside another function, or pass values into said function. This makes it easy to use a function a lot, or build a list of a function for example, with increasing values as its arguments. + +## Recursion +In racket I implemented a factorial function with recursion, and then tested the function to assure that the function is performing correctly. + +## Scribble Demo +I learned how you can use Scribble to use racket in a web page, to programatically generate web content. + +## Modules +I leanned about how to make modules, submodules, testing modules, and a main module. This was shown in a simple program that defined and exported one function called `hello` which simply printed "Hello!" I then used it in another application by using the `require` keyword. I then defined a main module that says when a the hello module is loaded it should print "Hello!" \ No newline at end of file diff --git a/journal/_src/posts/2022-09-21-lab-three-scribble-demo.scrbl b/journal/_src/posts/2022-09-21-lab-three-scribble-demo.scrbl new file mode 100644 index 0000000..8f2e9a7 --- /dev/null +++ b/journal/_src/posts/2022-09-21-lab-three-scribble-demo.scrbl @@ -0,0 +1,14 @@ +#lang scribble/manual + +Title: Lab Three Scribble Demo +Date: 2022-09-21T09:00:00 +Tags: cs2613, lab, racket, scribble + +Demo of how Scribble works + + + +@(define (hello) "hello") +@(define (todo hdr . lst) (list (bold hdr) (apply itemlist (map item lst)))) +@hello{} +@todo["Shopping" "cheese" "fish" "shuriken"] \ No newline at end of file diff --git a/journal/index.html b/journal/index.html index 160224e..3454761 100644 --- a/journal/index.html +++ b/journal/index.html @@ -6,7 +6,7 @@ CS2163 Blog - + @@ -57,7 +57,7 @@ @@ -90,6 +90,32 @@
+
+

Lab Three Scribble Demo

+

+ - cs2613, lab, racket, scribble

+

By: Isaac Shoebottom

+
+ +

Demo of how Scribble works

+ +
+
+
+

Lab Four

+

+ - cs2163, lab, racket, scribble

+

By: Isaac Shoebottom

+
+ +

In this lab I learned about using functions as values, recursion, scribble, and modules in Racket.

+ +
+

Lab Three

diff --git a/journal/sitemap.txt b/journal/sitemap.txt index 376c4c7..6da839e 100644 --- a/journal/sitemap.txt +++ b/journal/sitemap.txt @@ -1,4 +1,6 @@ http://www.example.com/2022\09\lab-three.html +http://www.example.com/2022\09\lab-three-scribble-demo.html http://www.example.com/2022\09\lab-two.html +http://www.example.com/2022\09\lab-four.html http://www.example.com/2022\09\lab-one.html http://www.example.com/About.html diff --git a/labs/L04/application.rkt b/labs/L04/application.rkt new file mode 100644 index 0000000..c357333 --- /dev/null +++ b/labs/L04/application.rkt @@ -0,0 +1,4 @@ +#lang racket +(require "hello.rkt") +(require rackunit) +(hello) \ No newline at end of file diff --git a/labs/L04/functions-as-values.rkt b/labs/L04/functions-as-values.rkt new file mode 100644 index 0000000..6c2d045 --- /dev/null +++ b/labs/L04/functions-as-values.rkt @@ -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)))) + diff --git a/labs/L04/hello.rkt b/labs/L04/hello.rkt new file mode 100644 index 0000000..01b15c5 --- /dev/null +++ b/labs/L04/hello.rkt @@ -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))) \ No newline at end of file diff --git a/labs/L04/recursion.rkt b/labs/L04/recursion.rkt new file mode 100644 index 0000000..ecc9a64 --- /dev/null +++ b/labs/L04/recursion.rkt @@ -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)) \ No newline at end of file