Skip to content

Commit a8e0efb

Browse files
committed
Add lecture 6
1 parent 70a8434 commit a8e0efb

File tree

5 files changed

+1718
-5
lines changed

5 files changed

+1718
-5
lines changed

docs_vitepress/make.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ pages = [
5656
"Lab" => "lab.md",
5757
"Homework" => "hw.md",
5858
]),
59-
# "6: Lanuage introspection" => add_prefix("lecture_06", [
60-
# "Lecture" => "lecture.md",
61-
# "Lab" => "lab.md",
62-
# "Homework" => "hw.md",
63-
# ]),
59+
"6: Lanuage introspection" => add_prefix("lecture_06", [
60+
"Lecture" => "lecture.md",
61+
"Lab" => "lab.md",
62+
"Homework" => "hw.md",
63+
]),
6464
"7: Macros" => add_prefix("lecture_07", [
6565
"Lecture" => "lecture.md",
6666
"Lab" => "lab.md",
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Homework 6: Find variables
2+
3+
Following the lab exercises, you may think that metaprogramming is a fun little exercise. Let's challenge this notion in this homework, where *YOU* are being trusted with catching all the edge cases in an AST.
4+
5+
## How to submit?
6+
7+
Put the code of the compulsory task inside `hw.jl`. Zip only this file (not its parent folder) and upload it to BRUTE. Your file should not use any 3rd party dependency.
8+
9+
::: danger Homework (2 points)
10+
11+
Your task is to find all single letter variables in an expression, i.e. for example when given expression
12+
13+
```julia
14+
x + 2*y*z - c*x
15+
```
16+
17+
return an array of *unique alphabetically sorted symbols* representing variables in an expression.
18+
19+
```julia
20+
[:c, :x, :y, :z]
21+
```
22+
23+
Implement this in a function called `find_variables`. Note that there may be some edge cases that you may have to handle in a special way, such as
24+
25+
- variable assignments `r = x*x` should return the variable on the left as well (`r` in this case)
26+
- ignoring symbols representing single letter function calls such as `f(x)`
27+
28+
:::
29+
30+
::: details Show solution
31+
32+
Nothing to see here.
33+
34+
:::
35+
36+
# Voluntary exercise
37+
38+
::: danger Voluntary exercise
39+
40+
Create a function that replaces each of `+`, `-`, `*` and `/` with the respective checked operation, which checks for overflow. E.g. `+` should be replaced by `Base.checked_add`.
41+
42+
:::
43+
44+
::: details Show solution
45+
46+
Not yet published.
47+
48+
:::

0 commit comments

Comments
 (0)