-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow-basics.qmd
75 lines (56 loc) · 1.33 KB
/
workflow-basics.qmd
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
---
title: "Workflow: Basics"
---
## Coding basics
You can use Julia to do basic math calculations:
```{julia}
#| eval: false
1 / 200 * 30
(59 + 73 + 2) / 3
sin(pi / 2)
```
You can create new objects with the assignment operator `=`:
```{julia}
#| eval: false
x = 3 * 4
```
Note that the value of `x` is not printed, it’s just stored. If you want to view the value, type `x` in the Julia REPL.
Combine multiple values into a vector with square brackets:
```{julia}
primes = [2, 3, 5, 7, 11]
```
Apply basic arithmetics on each elemt of the vector:
```{julia}
#| eval: false
primes * 2
primes .+1
```
## Comments
Comments are statements in a code that are ignored by the compiler at the time of execution, but their purpose is to be read by other humans. Comments provide an explanation for the steps that are used in the code. During coding, proper use of comments makes maintenance easier and finding bugs easily.
```{julia}
#| eval: false
# Create a vector of primes
primes = [2, 3, 5, 7, 11]
# Multiply primes by 2
primes * 2
```
## What is in a name?
```{julia}
object_name = primes
this_is_a_really_long_name = 2.5
```
```{julia}
julia_rocks = 2^3
```
```{julia}
#| eval: false
julia_rocks
#> ERROR: UndefVarError: `julia_rock` not defined
```
## Calling functions
```{julia}
add_x_and_y(x, y) = x + y
```
```{julia}
add_x_and_y(3, 4)
```