From 38ddfd326aca8f19c252822b0cdef4b146cec23b Mon Sep 17 00:00:00 2001 From: Niklas Heim Date: Tue, 20 Feb 2024 19:17:18 +0100 Subject: [PATCH] Lecture 02 (#1) --- .github/workflows/deploy.yml | 7 +- .vitepress/config.mts | 3 +- img/tree.svg | 1 + labs/lab01.md | 26 +- lectures/index.md | 9 +- lectures/lecture01.md | 11 +- lectures/lecture02.md | 692 +++++++++++++++++++++++++++++++++++ package-lock.json | 2 +- 8 files changed, 728 insertions(+), 23 deletions(-) create mode 100644 img/tree.svg create mode 100644 lectures/lecture02.md diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1c1a42e..bbb7233 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,11 +3,13 @@ name: Deploy VitePress site to Pages on: - # Runs on pushes targeting the `main` branch. Change this to `master` if you're - # using the `master` branch as the default branch. push: branches: [main] + pull_request: + branches: + - main + # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -54,6 +56,7 @@ jobs: # Deployment job deploy: + if: github.event.pull_request.base.ref == 'refs/heads/main' environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} diff --git a/.vitepress/config.mts b/.vitepress/config.mts index 44c3492..d504dc1 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -27,7 +27,8 @@ export default defineConfig({ text: 'Lectures', link: '/lectures/', items: [ - { text: '01: Introduction', link: '/lectures/lecture01'} + { text: '01: Introduction', link: '/lectures/lecture01'}, + { text: '02: Lists & Trees', link: '/lectures/lecture02'}, ] }, diff --git a/img/tree.svg b/img/tree.svg new file mode 100644 index 0000000..04fedae --- /dev/null +++ b/img/tree.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/labs/lab01.md b/labs/lab01.md index 3c55156..051726c 100644 --- a/labs/lab01.md +++ b/labs/lab01.md @@ -4,19 +4,17 @@ outline: deep # Lab 1: Introduction to Racket -This lab aims to familiarize the students with the IDE we will use for Racket and help them write -simple programs. +In this lab you will familiarize yourself with the IDE we will use to write Racket programs. ## Dr. Racket IDE -The IDE can be downloaded for free for Linux, Windows, and MAC from: -https://racket-lang.org/ +The IDE can be downloaded for free for Linux, Windows, and MAC from: https://racket-lang.org/ -The students can use the one installed in the lab computers. The teacher may help the students (to a -reasonable degree) to get the IDE running on students’ laptops. +You can use the one installed in the lab computers or install it on your own laptop. Don't hesitate +to ask for help! -Get familiar with the definition window and REPL in DrRacket. The documentation of implemented -functions is accessible via Help Desk in the menu. +To get familiar with the definition window and REPL in DrRacket you can: +* Read documentation of implemented functions which is accessible via **Help Desk** in the menu. DrRacket allows writing programs in several languages. We focus on Racket, so your first line in the code should be: @@ -25,7 +23,7 @@ code should be: ``` ## Exercises - Racket basics -Start interaction in REPL. Racket uses prefix notation for all functions. Let students compute +Start interaction in REPL. Racket uses prefix notation for all functions. Try and compute a simple formulas, e.g., $2+3/5$. ### Exercise 1 @@ -80,7 +78,7 @@ consisting of a sequence of consecutive characters starting with `fst`, ending w following the order in the ASCII table. For example `(consecutive-chars #\A #\D) => "ABCD"` or `(consecutive-chars #\z #\u) => "zyxwvu"`. For converting characters into positions in the ASCII table, use functions -`char->integer` and `integer->char`. To convert a character into a +`char->integer` and `integer->char`. To convert a character into a string, apply the function `string`. ::: details Solution @@ -98,9 +96,11 @@ string, apply the function `string`. (iter (+ k step) (string-append acc (integer->string k))))) (iter first-index "")) +``` -; alternatively: -#| +Alternatively, and maybe slightly more elegantly, you can define two helper functions `char+1` and +`char-1` and use an accumulator: +```scheme (define (char+1 c) (integer->char (add1 (char->integer c)))) (define (char-1 c) (integer->char (sub1 (char->integer c)))) @@ -111,8 +111,6 @@ string, apply the function `string`. (consecutive-chars (char+1 fst) lst (string-append acc (string fst)))] [(char>? fst lst) (consecutive-chars (char-1 fst) lst (string-append acc (string fst)))])) -|# - ``` ::: diff --git a/lectures/index.md b/lectures/index.md index b9bc25b..2ccec62 100644 --- a/lectures/index.md +++ b/lectures/index.md @@ -7,14 +7,17 @@ due to other obligations. ## [Lecture 01](lecture01): Introduction Discusses the key ideas behind functional programming. It further introduces the programming language [Racket](https://racket-lang.org/). + [Slides](https://drive.google.com/file/d/1e1aw5Mf5qts0DxLJFDZUWDbGlwI0hdeM/view?usp=drive_link). [Log](https://drive.google.com/file/d/1I3uoTART5UmWsWLRR_bYuNrzolTl2cO5/view?usp=share_link). +## [Lecture 02](lecture02): Lists & Trees +Focuses on Racket lists and trees. Further, it introduces the unit testing library +[Rackunit](https://docs.racket-lang.org/rackunit/index.html). -