Skip to content

Commit 6aa14b3

Browse files
committed
lab fix
1 parent de5d903 commit 6aa14b3

File tree

1 file changed

+14
-14
lines changed
  • docs/src/lectures/lecture_07

1 file changed

+14
-14
lines changed

docs/src/lectures/lecture_07/lab.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ end
6565
```
6666

6767
We can remove this boilerplate code by creating a very simple macro that does this for us.
68-
::: warning "Exercise"
68+
!!! warning "Exercise"
6969
```
7070
Define macro `@repeat` that takes two arguments, first one being the number of times a code is to be run and the other being the actual code.
7171
```julia
@@ -88,7 +88,7 @@ We can remove this boilerplate code by creating a very simple macro that does th
8888
What happens if we call `@repeat 3 x = 2`? Is `x` defined?
8989

9090

91-
::: details
91+
!!! details
9292
```@repl lab07_repeat
9393
macro repeat(n::Int, ex)
9494
return _repeat(n, ex)
@@ -125,7 +125,7 @@ p = @poly 3 2 10
125125
p(2)
126126
```
127127

128-
::: warning "Exercise"
128+
!!! warning "Exercise"
129129
Create macro `@poly` that takes multiple arguments and creates an anonymous function that constructs the unrolled code. Instead of directly defining the macro inside the macro body, create helper function `_poly` with the same signature that can be reused outside of it.
130130

131131
Recall Horner's method polynomial evaluation from previous [labs](@ref horner):
@@ -154,7 +154,7 @@ p(2)
154154

155155
[^1]: Explanation of the Horner schema can be found on [https://en.wikipedia.org/wiki/Horner%27s\_method](https://en.wikipedia.org/wiki/Horner%27s_method).
156156

157-
::: details
157+
!!! details
158158
```@repl lab07_poly
159159
using InteractiveUtils #hide
160160
macro poly(a...)
@@ -177,7 +177,7 @@ p(2)
177177

178178
Moving on to the first/harder case, where we need to parse the mathematical expression.
179179

180-
::: warning "Exercise"
180+
!!! warning "Exercise"
181181
Create macro `@poly` that takes two arguments first one being the independent variable and second one being the polynomial written in mathematical notation. As in the previous case this macro should define an anonymous function that constructs the unrolled code.
182182
```julia
183183
julia> p = @poly x 3x^2+2x^1+10x^0 # the first argument being the independent variable to match
@@ -190,7 +190,7 @@ Moving on to the first/harder case, where we need to parse the mathematical expr
190190
1. get maximal rank of the polynomial
191191
2. get coefficient for each power
192192

193-
::: note "`MacroTools.jl`"
193+
!!! note "`MacroTools.jl`"
194194
Though not the most intuitive, [`MacroTools.jl`](https://fluxml.ai/MacroTools.jl/stable/) pkg help us with writing custom macros. We will use two utilities
195195
#### `@capture`
196196
This macro is used to match a pattern in a *single* expression and return values of particular spots. For example
@@ -221,7 +221,7 @@ Moving on to the first/harder case, where we need to parse the mathematical expr
221221
Note that the `x` or the iteration is required, because by default postwalk/prewalk replaces currently read expression with the output of the body of `do` block.
222222

223223

224-
::: details
224+
!!! details
225225
```@example lab07_poly
226226
using MacroTools
227227
using MacroTools: postwalk, prewalk
@@ -314,7 +314,7 @@ Our goal is to be able to define new plants and animal species, while having a c
314314
```
315315
Unfortunately the current version of `Ecosystem` and `EcosystemCore`, already contains some definitions of species such as `Sheep`, `Wolf` and `Mushroom`, which may collide with definitions during prototyping, therefore we have created a modified version of those pkgs, which will be provided in the lab.
316316

317-
::: note "Testing relations"
317+
!!! note "Testing relations"
318318
We can test the current definition with the following code that constructs "eating matrix"
319319
```julia
320320
using Ecosystem
@@ -350,7 +350,7 @@ Unfortunately the current version of `Ecosystem` and `EcosystemCore`, already co
350350
🐑 ❌ ❌ ✅ ✅
351351
🐺 ✅ ❌ ❌ ❌
352352
```
353-
::: warning "Exercise"
353+
!!! warning "Exercise"
354354
Based on the following example syntax,
355355
```julia
356356
@species Plant Broccoli 🥦
@@ -368,7 +368,7 @@ Unfortunately the current version of `Ecosystem` and `EcosystemCore`, already co
368368
_species(:Animal, :Rabbit, :🐇)
369369
```
370370

371-
::: warning "Exercise"
371+
!!! warning "Exercise"
372372
Based on the following example syntax,
373373
```julia
374374
@species Plant Broccoli 🥦
@@ -396,7 +396,7 @@ Unfortunately the current version of `Ecosystem` and `EcosystemCore`, already co
396396
**BONUS**:
397397
Based on `@species` define also macros `@animal` and `@plant` with two arguments instead of three, where the species type is implicitly carried in the macro's name.
398398

399-
::: details
399+
!!! details
400400
Macro `@species`
401401
```julia
402402
macro species(typ, name, icon)
@@ -428,7 +428,7 @@ Unfortunately the current version of `Ecosystem` and `EcosystemCore`, already co
428428

429429
The next exercise applies macros to the agents eating behavior.
430430

431-
::: warning "Exercise"
431+
!!! warning "Exercise"
432432
Define macro `@eats` inside `Ecosystem` pkg that assigns particular species their eating habits via `eat!` and `eats` functions. The macro should process the following example syntax
433433
```julia
434434
@eats Rabbit [Grass => 0.5, Broccoli => 1.0],
@@ -441,7 +441,7 @@ The next exercise applies macros to the agents eating behavior.
441441
- you can create an empty `quote end` block with `code = Expr(:block)` and push new expressions into its `args` incrementally
442442
- use dispatch to create specific code for the different combinations of agents eating other agents (there may be catch in that we have to first `eval` the symbols before calling in order to know if they are animals or plants)
443443

444-
::: note "Reminder of `EcosystemCore` `eat!` and `eats` functionality"
444+
!!! note "Reminder of `EcosystemCore` `eat!` and `eats` functionality"
445445
In order to define that an `Wolf` eats `Sheep`, we have to define two methods
446446
```
447447
EcosystemCore.eats(::Animal{Wolf}, ::Animal{Sheep}) = true
@@ -464,7 +464,7 @@ The next exercise applies macros to the agents eating behavior.
464464
**BONUS**:
465465
You can try running the simulation with the newly added agents.
466466

467-
::: details
467+
!!! details
468468
```julia
469469
macro eats(species::Symbol, foodlist::Expr)
470470
return esc(_eats(species, foodlist))

0 commit comments

Comments
 (0)