Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update episodes from Literate.jl source files #89

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion episodes/05_Write_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ Closest candidates are:

````

### Errors and macros
### Errors and finding documentation

This error tells her two things:

Expand Down Expand Up @@ -405,6 +405,7 @@ Base

Now Melissa knows she needs to add a method to `Base.size` with the
signature `(::Trebuchet)`.

She can also lookup the docstring using the `@doc` macro

````julia
Expand Down Expand Up @@ -461,10 +462,24 @@ She can also lookup the docstring using the `@doc` macro

With that information she can now implement this method:

````julia
function Base.size(::Trebuchet)
return tuple(2)
end
````

But that is a 3 lines of text for a very short definition.
Melissa can also using the short form notation to fit this in a single line:

````julia
Base.size(::Trebuchet) = tuple(2)
````

!!! callout Omitting unneeded arguments
Melissa could also name the argument in the signature.
Like this: `(trebuchet::Trebuchet)`, but since the argument is not needed to compute
the output of the function she can omit it.
The argument is in this case only used to dispatch to the correct method.
Now she can try again

````julia
Expand Down
30 changes: 15 additions & 15 deletions episodes/07_Loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ Trebuchet( rand() * 500, rand() * pi/2 )

````output
2-element Trebuchet:
353.42697829091327
1.5481002998262625
301.45863866265444
0.5147801124901857
````

will give her a Trebuchet with a weight between 0 and 500 and a release angle between 0 and pi/2 radians at random.
Expand All @@ -121,9 +121,9 @@ distances = [shoot_distance(Trebuchet(rand() * 500, rand() * pi / 2), env) for _

````output
3-element Vector{Float64}:
118.13337827163429
82.95579691187152
117.13566809575129
107.31486215571258
116.5961233156913
3.006112235174449
````

This is called an _array comprehension_.
Expand All @@ -138,16 +138,16 @@ distances = [(w,a) => shoot_distance(Trebuchet(w, a), env) for (w, a) in zip(wei

````output
10-element Vector{Pair{Tuple{Float64, Float64}, Float64}}:
(324.2732442832362, 0.71302644795678) => 114.55947796494196
(335.37667874032854, 0.6341110514590834) => 116.68767139752573
(103.60031609976255, 0.03878975933920561) => 51.650885425681984
(482.63166698166805, 0.11246399230891459) => 81.89097177495029
(300.6724895776015, 0.25573753399679877) => 97.56213345772589
(471.0242182881435, 1.1388331155474132) => 82.73493540156431
(253.00933394709475, 0.36203702332969495) => 102.38374906456522
(156.7643321929057, 0.5764919513105045) => 103.44235911682252
(32.41843752500701, 1.3341566788703363) => 15.176619860993625
(53.610542563477026, 1.4033289299752423) => 19.162338180404383
(316.3006668666567, 0.2763285950708336) => 101.94306047739477
(184.81067380921974, 0.21663020097625554) => 87.01600131363767
(118.28342636599143, 0.16251023948500737) => 71.41041926553547
(495.4627412106457, 0.2337213045007839) => 100.84254397856022
(121.54718006057836, 1.2933538749770221) => 44.31450096256152
(50.49083319279707, 1.3999293689100087) => 18.58057814648708
(463.0506320312314, 0.32643937336190937) => 108.22484752113716
(296.1556297915833, 0.035353940515857406) => 62.1859221237384
(134.340007097649, 1.2511802453356395) => 51.71612933008983
(493.7526856775179, 0.5068383250394274) => 118.81200975980546
````

### Gradient descent
Expand Down
2 changes: 1 addition & 1 deletion episodes/10_Adding_tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ end
````

````output
Test.DefaultTestSet("Test arithmetic equalities", Any[], 1, false, false, true, 1.731578522519902e9, 1.731578522550699e9, false)
Test.DefaultTestSet("Test arithmetic equalities", Any[], 1, false, false, true, 1.731584626736792e9, 1.731584626767338e9, false)
````

With this Melissa can run her test using the pkg mode of the REPL:
Expand Down