-
-
Notifications
You must be signed in to change notification settings - Fork 284
/
Getting started.jl
196 lines (153 loc) Β· 9.83 KB
/
Getting started.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
### A Pluto.jl notebook ###
# v0.11.14
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local el = $(esc(element))
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : missing
el
end
end
# βββ‘ b129ba7c-953a-11ea-3379-17adae34924c
md"# _Welcome to Pluto!_
Pluto is a programming environment for _Julia_, designed to be **interactive** and **helpful**.
In this introduction, we will go through the basics of using Pluto. To make it interesting, this notebook does something special: it **changes while you work on it**. Computer magic β¨"
# βββ‘ 4d88b926-9543-11ea-293a-1379b1b5ae64
md"## Cats
Let's say you're like my grandma, and you have a lot of cats. Our story will be about them."
# βββ‘ 3e8e381e-953f-11ea-3d3e-71d0fea52560
cat = "Ks*;lj"
# βββ‘ aeb3a6bc-9540-11ea-0b8f-6d37412bfe68
if cat == "Ks*;lj"
md"Oh no! Someone messed with my pretty introduction. Change the code above to give our cat a proper name!"
else
HTML("""<p><b>Well done, your cat is called $cat now.</b> This text gets updated every time you change the name. To see how the magic works, click on the <img src="https://cdn.jsdelivr.net/gh/ionic-team/ionicons@5.5.1/src/svg/eye-outline.svg" style="width: 1em; height: 1em; margin-bottom: -.2em;"> to the left of this text.</p>""")
end
# βββ‘ 611c28fa-9542-11ea-1751-fbdedcfb7690
html"""<p>To edit any code, just click on it. When you're done programming, press the <img src="https://cdn.jsdelivr.net/gh/ionic-team/ionicons@5.5.1/src/svg/caret-forward-circle-outline.svg" style="width: 1em; height: 1em; margin-bottom: -.2em;"> in the lower-right corner of a cell to run the code. You can also use `Shift+Enter` if you are in a hurry.</p>"""
# βββ‘ 6f7eecec-9543-11ea-1284-dd52fce3ecca
md"I feel like our cat needs a friend. Let's call them $(friend)."
# βββ‘ a1a20314-9543-11ea-17de-0b658da18992
if !@isdefined friend
md"Uh oh, what is this? I forgot to add a cell defining our friend. Can you do it for me?"
else
md"**Well done!** $cat and $friend are both happy with your performance."
end
# βββ‘ f112b662-9543-11ea-3dcb-2906a99b2188
html"""<p>A cell is a container for code & output. To add one, click on the <img src="https://cdn.jsdelivr.net/gh/ionic-team/ionicons@5.5.1/src/svg/add-outline.svg" style="width: 1em; height: 1em; margin-bottom: -.2em;"> above or below another cell. You can do it wherever you like. After you're done writing code in your cell, remember to run it!</p>"""
# βββ‘ e0642f42-9545-11ea-14ee-fde52cb54ccc
md"## Feeding neighbors
Our cats have some neighbors. Let's involve them in the story too!"
# βββ‘ 3653b1ac-9546-11ea-2a44-ddd3054636fe
neighbors = [cat, friend, "Smerfetka", "Latte"]
# βββ‘ 19ff8d36-9547-11ea-0e08-e5cdd8338673
md"Now, if you're like my grandma, you're feeding the entire neighborhood by yourself. Let's see how many cans of cat food you need to prepare."
# βββ‘ 270ac49e-9549-11ea-3ffd-71ddaee9f134
md"But what does `confusing_function` do? If you ever need help, click on π **Live docs** in the lower right, and then place your cursor on the code you need help with.
If you don't see it, then your screen is too small! Maybe you need to zoom out?"
# βββ‘ 745a4584-954a-11ea-028e-59011f268ec6
cans_in_stock = "π₯«π₯«π₯«π₯«"
# βββ‘ 55ad7422-954e-11ea-0a33-a3b03febb56e
if @isdefined cans_in_stock
md"Actually, I have a hunch there will be another cat coming. Uncomment the code below (remove the #) to add one more can. Remember to run it after making the change!"
else
md"**Whoopsie!** Because Pluto figures out execution order for you, it doesn't really make sense to assign to the same variable twice. A smarter way to plan ahead is to write `cans_in_stock = consumption` β Pluto will take care of updating everything."
end
# βββ‘ eac62fea-954e-11ea-2768-39ce6f4059ab
# cans_in_stock = "π₯«π₯«π₯«π₯«π₯«"
# βββ‘ 6c8e2108-9550-11ea-014d-235770ed4771
md"## Saving cats and notebooks
Alright, we have a neighborhood full of well-fed cats. But oh no, here comes..."
# βββ‘ 9e89fc9a-9550-11ea-14b4-7f0e96225ec0
scary_dog = "Piesio"
# βββ‘ bdd5d268-9550-11ea-1046-31efedc36872
if @isdefined scary_dog
md" $scary_dog is terrorizing the neighborhood! We must do something about it!"
else
md"You saved the neighborhood! Referencing `scary_dog` leads to an `UndefVarError`, as if it never even existed."
end
# βββ‘ 36cd006a-9551-11ea-3c0c-df8b7f2843c1
HTML("""<p>To delete a cell like the one defining $scary_dog, click on the <img src="https://cdn.jsdelivr.net/gh/ionic-team/ionicons@5.5.1/src/svg/close-circle-outline.svg" style="width: 1em; height: 1em; margin-bottom: -.2em;"> on the right of its code.</p>""")
# βββ‘ fb4e471c-9551-11ea-1ab5-41bbd5de76b8
md"""
Speaking of saving, this notebook is autosaved whenever you change something. The default location for new notebooks is $(joinpath(first(DEPOT_PATH), "pluto_notebooks")), you can find it using your file explorer. To change the name or the directory of a notebook, scroll to the top - you enter the notebook's path next to the Pluto logo.
"""
# βββ‘ 9d3af596-9554-11ea-21bd-bf427c91c424
md"## β‘ Pluto power β‘
Oof, that dog situation was intense. Let's give our cats superpowers to make sure it never happens again!"
# βββ‘ 3150bf1a-9555-11ea-306f-0fd4d9229a51
md"Remember learning HTML in junior high? Now you can use it for something! Pluto lets you `@bind` variables to HTML elements. As always, every time you change something, Pluto knows what to update!"
# βββ‘ f2c79746-9554-11ea-39ca-298fd09248ad
@bind power_level html"<input type='range'>"
# βββ‘ 0b094cea-9556-11ea-268e-0d270fd04d56
md"The power level is $power_level, but we should do more than just say it - let's equip our cats with $power_level emoji!"
# βββ‘ 1908f9f2-9557-11ea-2abd-dd52f8d776f4
power_emoji = "β‘"
power = repeat(power_emoji, power_level)
# βββ‘ 784b1774-9557-11ea-315e-d1ea277ce0fd
if !@isdefined power
md"Uh oh! Pluto doesn't support multiple expressions per cell. This is a conscious choice - this restriction helps you write less buggy code once you get used to it. To fix the code, you can either split the above cell, or wrap it in a `begin ... end` block. Both work."
else
md"**Well done!** Your cats have powers now."
end
# βββ‘ 5edadcd2-9554-11ea-1714-b5b7692c4797
html"""<p>We're almost done! It's time to share your amazing story. Scroll to the top of the notebook, and click on <img src="https://cdn.jsdelivr.net/gh/ionic-team/ionicons@5.5.1/src/svg/shapes-outline.svg" style="width: 1em; height: 1em; margin-bottom: -.2em;"> to see the export options - or you can always share this notebook's save file. (The file is pure Julia, by the way, and it's runnable! You'll learn more about this in the advanced introduction.)</p>"""
# βββ‘ 4634c856-9553-11ea-008d-3539195970ea
md"## Final notes"
# βββ‘ 4d0ebb46-9553-11ea-3431-2d203f594815
md"If anything about this introduction left you confused, something doesn't work, or you have a cool new idea - don't hesitate to contact us! You can do it right from this screen, using the `Instant feedback` form in the bottom right."
# βββ‘ d736e096-9553-11ea-3ba5-277afde1afe7
md"Also, if you were wondering where `confusing_function` came from, here you go! Remember that you, too, can place code wherever you like."
# βββ‘ 7366f1b6-954c-11ea-3f68-b12444c902c3
"""
confusing_function(text::String, array::Array)
Repeats the `text` as many times as there are elements in `array`.
"""
confusing_function(text::String, array::Array) = repeat(text, length(array))
# βββ‘ a4a60262-9547-11ea-3a81-5bf7f9ee5d16
consumption = confusing_function("π₯«", neighbors)
# βββ‘ e11e1660-9549-11ea-22f6-8bb53dc045fe
md"Now we know to prepare $(length(consumption)) cans. Let's stock up!"
# βββ‘ f27f90c2-954f-11ea-3f93-17acb2ce4280
md"We have $(length(cans_in_stock)) cans of cat food, and our cats need $(length(consumption)). Try adding another cat to the neighborhood to see what changes!"
# βββ‘ 1deaaf36-9554-11ea-3dae-85851f73dbc6
md"**Have fun using Pluto!**
_~ Fons van der Plas & Nicholas Bochenski_"
# βββ‘ Cell order:
# ββb129ba7c-953a-11ea-3379-17adae34924c
# ββ4d88b926-9543-11ea-293a-1379b1b5ae64
# β β3e8e381e-953f-11ea-3d3e-71d0fea52560
# ββaeb3a6bc-9540-11ea-0b8f-6d37412bfe68
# ββ611c28fa-9542-11ea-1751-fbdedcfb7690
# β β6f7eecec-9543-11ea-1284-dd52fce3ecca
# ββa1a20314-9543-11ea-17de-0b658da18992
# ββf112b662-9543-11ea-3dcb-2906a99b2188
# ββe0642f42-9545-11ea-14ee-fde52cb54ccc
# β β3653b1ac-9546-11ea-2a44-ddd3054636fe
# ββ19ff8d36-9547-11ea-0e08-e5cdd8338673
# β βa4a60262-9547-11ea-3a81-5bf7f9ee5d16
# ββ270ac49e-9549-11ea-3ffd-71ddaee9f134
# ββe11e1660-9549-11ea-22f6-8bb53dc045fe
# β β745a4584-954a-11ea-028e-59011f268ec6
# ββ55ad7422-954e-11ea-0a33-a3b03febb56e
# β βeac62fea-954e-11ea-2768-39ce6f4059ab
# ββf27f90c2-954f-11ea-3f93-17acb2ce4280
# ββ6c8e2108-9550-11ea-014d-235770ed4771
# β β9e89fc9a-9550-11ea-14b4-7f0e96225ec0
# ββbdd5d268-9550-11ea-1046-31efedc36872
# ββ36cd006a-9551-11ea-3c0c-df8b7f2843c1
# ββfb4e471c-9551-11ea-1ab5-41bbd5de76b8
# ββ9d3af596-9554-11ea-21bd-bf427c91c424
# ββ3150bf1a-9555-11ea-306f-0fd4d9229a51
# β βf2c79746-9554-11ea-39ca-298fd09248ad
# ββ0b094cea-9556-11ea-268e-0d270fd04d56
# β β1908f9f2-9557-11ea-2abd-dd52f8d776f4
# ββ784b1774-9557-11ea-315e-d1ea277ce0fd
# ββ5edadcd2-9554-11ea-1714-b5b7692c4797
# ββ4634c856-9553-11ea-008d-3539195970ea
# ββ4d0ebb46-9553-11ea-3431-2d203f594815
# ββd736e096-9553-11ea-3ba5-277afde1afe7
# ββ7366f1b6-954c-11ea-3f68-b12444c902c3
# ββ1deaaf36-9554-11ea-3dae-85851f73dbc6