Add lab 4 content.
This commit is contained in:
parent
baf9b933de
commit
3bb4db362e
17
journal/_src/posts/2022-09-21-lab-four.md
Normal file
17
journal/_src/posts/2022-09-21-lab-four.md
Normal file
@ -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.
|
||||||
|
<!-- more -->
|
||||||
|
## 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!"
|
14
journal/_src/posts/2022-09-21-lab-three-scribble-demo.scrbl
Normal file
14
journal/_src/posts/2022-09-21-lab-three-scribble-demo.scrbl
Normal file
@ -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
|
||||||
|
|
||||||
|
<!-- more -->
|
||||||
|
|
||||||
|
@(define (hello) "hello")
|
||||||
|
@(define (todo hdr . lst) (list (bold hdr) (apply itemlist (map item lst))))
|
||||||
|
@hello{}
|
||||||
|
@todo["Shopping" "cheese" "fish" "shuriken"]
|
@ -6,7 +6,7 @@
|
|||||||
<title>CS2163 Blog</title>
|
<title>CS2163 Blog</title>
|
||||||
<meta name="description" content="CS2163 Blog">
|
<meta name="description" content="CS2163 Blog">
|
||||||
<meta name="author" content="Isaac Shoebottom">
|
<meta name="author" content="Isaac Shoebottom">
|
||||||
<meta name="keywords" content="frog, lab, all, git, racket, cs2163">
|
<meta name="keywords" content="frog, cs2613, lab, all, scribble, git, racket, cs2163">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link rel="icon" href="/favicon.ico">
|
<link rel="icon" href="/favicon.ico">
|
||||||
<link rel="canonical" href="http://www.example.com/index.html">
|
<link rel="canonical" href="http://www.example.com/index.html">
|
||||||
@ -57,7 +57,7 @@
|
|||||||
</a>
|
</a>
|
||||||
|
|
||||||
<div class="dropdown-menu">
|
<div class="dropdown-menu">
|
||||||
<a class="dropdown-item" href="/tags\cs2163.html">cs2163</a><a class="dropdown-item" href="/tags\frog.html">frog</a><a class="dropdown-item" href="/tags\git.html">git</a><a class="dropdown-item" href="/tags\lab.html">lab</a><a class="dropdown-item" href="/tags\racket.html">racket</a>
|
<a class="dropdown-item" href="/tags\cs2163.html">cs2163</a><a class="dropdown-item" href="/tags\cs2613.html">cs2613</a><a class="dropdown-item" href="/tags\frog.html">frog</a><a class="dropdown-item" href="/tags\git.html">git</a><a class="dropdown-item" href="/tags\lab.html">lab</a><a class="dropdown-item" href="/tags\racket.html">racket</a><a class="dropdown-item" href="/tags\scribble.html">scribble</a>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
@ -89,6 +89,32 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<article>
|
||||||
|
<header>
|
||||||
|
<h2><a href='/2022\09\lab-three-scribble-demo.html'>Lab Three Scribble Demo</a></h2>
|
||||||
|
<p class='date-and-tags'>
|
||||||
|
<time datetime="2022-09-21" pubdate="true">2022-09-21</time> - <span class="tags"><a href="/tags\cs2613.html">cs2613</a>, <a href="/tags\lab.html">lab</a>, <a href="/tags\racket.html">racket</a>, <a href="/tags\scribble.html">scribble</a></span></p>
|
||||||
|
<p class='authors'>By: <span class="authors">Isaac Shoebottom</span></p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<p>Demo of how Scribble works</p>
|
||||||
|
<footer>
|
||||||
|
<a href='/2022\09\lab-three-scribble-demo.html'>… more …</a>
|
||||||
|
</footer>
|
||||||
|
</article>
|
||||||
|
<article>
|
||||||
|
<header>
|
||||||
|
<h2><a href='/2022\09\lab-four.html'>Lab Four</a></h2>
|
||||||
|
<p class='date-and-tags'>
|
||||||
|
<time datetime="2022-09-21" pubdate="true">2022-09-21</time> - <span class="tags"><a href="/tags\cs2163.html">cs2163</a>, <a href="/tags\lab.html">lab</a>, <a href="/tags\racket.html">racket</a>, <a href="/tags\scribble.html">scribble</a></span></p>
|
||||||
|
<p class='authors'>By: <span class="authors">Isaac Shoebottom</span></p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<p>In this lab I learned about using functions as values, recursion, scribble, and modules in Racket.</p>
|
||||||
|
<footer>
|
||||||
|
<a href='/2022\09\lab-four.html'>… more …</a>
|
||||||
|
</footer>
|
||||||
|
</article>
|
||||||
<article>
|
<article>
|
||||||
<header>
|
<header>
|
||||||
<h2><a href='/2022\09\lab-three.html'>Lab Three</a></h2>
|
<h2><a href='/2022\09\lab-three.html'>Lab Three</a></h2>
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
http://www.example.com/2022\09\lab-three.html
|
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-two.html
|
||||||
|
http://www.example.com/2022\09\lab-four.html
|
||||||
http://www.example.com/2022\09\lab-one.html
|
http://www.example.com/2022\09\lab-one.html
|
||||||
http://www.example.com/About.html
|
http://www.example.com/About.html
|
||||||
|
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))
|
Loading…
Reference in New Issue
Block a user