english improved

This commit is contained in:
2026-03-05 20:09:16 +01:00
parent c6609d15f5
commit 733fe8c290
21 changed files with 954 additions and 1042 deletions

View File

@@ -18,15 +18,15 @@ using InteractiveUtils
- Names may contain letters, digits, underscores `_`, and exclamation marks `!`.
- The first character must be a letter or an underscore.
- Case is significant: `Nmax` and `NMAX` are different variables.
- The character set used is [Unicode](https://home.unicode.org/), which provides access to over 150 scripts and numerous symbols.
- The character set used is [Unicode](https://home.unicode.org/), which covers over 150 scripts and numerous symbols.
- There is a short [list of reserved keywords](https://docs.julialang.org/en/v1/base/base/#Keywords): `if, then, function, true, false,...`
:::{.callout-tip}
## Example
Permissible: `i, x, Ω, x2, DieUnbekannteZahl, neuer_Wert, 🎷, Zähler, лічильник, einself!!!!,...`
Permissible: `i, x, Ω, x2, TheUnknownNumber, new_Value, 🎷, Counter_2, лічильник, yes!!!!,...`
Impermissible: `Uwe's_Funktion, 3achsen, A#B, $this_is_not_Perl, true,...`
Impermissible: `Karen's_Funktion, 3achsen, A#B, $this_is_not_Perl, true,...`
:::
----
@@ -35,7 +35,7 @@ Impermissible: `Uwe's_Funktion, 3achsen, A#B, $this_is_not_Perl, true,...`
## Note:
In addition to the *reserved keywords* of the core language, numerous additional functions and objects are predefined, such as the mathematical functions `sqrt(), log(), sin()`.
These definitions are found in the module `Base`, which Julia loads automatically at startup.
These definitions are found in the `Base` module, which Julia loads automatically on startup.
Names from `Base` can be redefined as long as they have not yet been used:
```{julia}
@@ -43,7 +43,7 @@ Names from `Base` can be redefined as long as they have not yet been used:
log = 3
1 + log
```
Now, of course, the logarithm is broken:
Now, of course, `log()` no longer works:
```{julia}
#| error: true
x = log(10)
@@ -53,7 +53,7 @@ x = log(10)
## Statements
- In normal circumstances, each line contains one statement.
- Usually, each line contains one statement.
- If a statement is recognizable as incomplete at the end of a line through
- open parentheses
- operators,
@@ -84,14 +84,14 @@ x = sum([i^2 for i=1:10]);
:::{.callout-warning }
For multi-line statements, the line to be continued must end with an open operator or parenthesis.
For multi-line statements, a continued line should end with an open operator or parenthesis.
```{julia}
x = sin(π/2) +
3 * cos(0)
```
Therefore, the following goes wrong, but—unfortunately—**without an error message**!
Therefore, the following fails, but—unfortunately—**without an error message**!
```{julia}
#| error: true
#| warning: true
@@ -122,26 +122,26 @@ x = 2 # everything from '#' to the end of the line is a comment and is ignore
```{julia}
#=
Single and multi-line comments can be enclosed between `#= ... =#`. Nested comments are possible.
Single and multi-line comments can be enclosed in `#= ... =#`. Nested comments are possible.
`#=`
i.e., unlike in C/C++/Java, the comment does not end with the first comment-end character, but the `#=...=#` pairs act like parentheses.
`=#`
The automatic 'syntax highlighter' does not yet know this, as the alternating
The automatic 'syntax highlighter' doesn't support this yet, as the alternating
gray shading of this comment shows.
=#
x #= das ist ein seltener Variablenname! =# = 3
x #= this is a really rare name for a variable! =# = 3
```
## Data Types Part I
- Julia is a [strongly typed](https://de.wikipedia.org/wiki/Starke_Typisierung) language. All objects have a type. Functions and operations expect arguments of the correct type.
- Julia is a [dynamically typed](https://de.wikipedia.org/wiki/Dynamische_Typisierung) language. Variables have no type. They are names that can be bound to objects via assignment `x = ...`.
- Julia is a [strongly typed](https://en.wikipedia.org/wiki/Type_safety#Strong_and_weak_typing) language. All objects have a type. Functions and operations expect arguments of the correct type.
- Julia is a [dynamically typed](https://en.wikipedia.org/wiki/Dynamic_programming_language) language. Variables have no type. They are names that can be bound to objects via assignment `x = ...`.
- When speaking of the "type of a variable", one means the type of the object currently assigned to the variable.
- Functions and operators can implement different *methods* for different argument types.
- Depending on the concrete argument types, it is decided at function usage which method is used ([*dynamic dispatch*](https://en.wikipedia.org/wiki/Dynamic_dispatch)).
- Depending on the concrete argument types, it is decided at call time which method is selected ([*dynamic dispatch*](https://en.wikipedia.org/wiki/Dynamic_dispatch)).
Simple basic types are, for example:
@@ -162,7 +162,7 @@ x, typeof(x), sizeof(x)
```
```{julia}
x = "Hallo!"
x = "Hello!"
x, typeof(x), sizeof(x)
```
@@ -179,7 +179,7 @@ x, typeof(x), sizeof(x)
- `sizeof()` returns the size of an object or type in bytes (1 byte = 8 bits)
- 64-bit integers and 64-bit floating-point numbers correspond to the instruction set of modern processors and are therefore the standard numeric types.
- Characters/*chars* `'A'` and strings/*strings* `"A"` of length 1 are different objects.
- Character literals like `'A'` and single-character strings like `"A"` are different objects.
## Control Flow
@@ -193,7 +193,7 @@ x = 33
y = 44
z = 34
if x < y && z != x # elseif- and else-branches are optional
if x < y && z != x # elseif or else branches are optional
println("yes")
x += 10
elseif x < z # any number of elseif branches
@@ -201,7 +201,7 @@ elseif x < z # any number of elseif branches
elseif x == z+1
println(" x is successor of z")
else # at most one else block
println("Alles falsch")
println("All wrong")
end # value of the entire block is the value of the
# last evaluated statement
```
@@ -211,7 +211,7 @@ Short blocks can be written on one line:
if x > 10 println("x is larger than 10") end
```
The value of an `if` block can of course be assigned:
The value of an `if` block can be assigned:
```{julia}
y = 33
z = if y > 10
@@ -258,7 +258,7 @@ As usual, the equality test `==` must be distinguished from the assignment opera
Well, almost anything:
```{julia}
3 < "vier"
3 < "four"
```
The error message shows a few fundamental principles of Julia:
@@ -283,7 +283,7 @@ Finally: comparisons can be chained.
### Tests
Some functions of type `f(c::Char) -> Bool`
Some functions of type `f(c::Char) -> Bool`
```{julia}
isnumeric('a'), isnumeric('7'), isletter('a')
@@ -315,10 +315,10 @@ x ∈ [1, 2, 33, 4, 5]
3 < 4 && !(2 > 8) && !contains("aaa", "b")
```
#### Conditional Evaluation (_short circuit evaluation_)
#### Conditional Evaluation (_short-circuit evaluation_)
- in `a && b` `b` is only evaluated if `a == true`
- in `a || b` `b` is only evaluated if `a == false`
- In `a && b`, `b` is only evaluated if `a == true`
- In `a || b`, `b` is only evaluated if `a == false`
(i) Thus, `if test statement end` can also be written as `test && statement`.
@@ -346,7 +346,7 @@ x = 3 < 4
y = 5 ∈ [1, 2, 5, 7]
z = x && y
if z # equivalent to: if 3 < 4 && 5 in [1,2,5,7]
println("Stimmt alles!")
println("All correct!")
end
```
@@ -354,7 +354,7 @@ end
- There is no implicit conversion such as *"0 is false and 1 (or anything != 0) is true"*
- If `x` is a numeric type, then the C idiom `if(x)` must be written as `if x != 0`.
- There is an exception to support the _short circuit evaluation_:
- in the constructs `a && b && c...` or `a || b || c...` the last subexpression does not need to be of type `Bool` if these constructs are not used as tests in `if` or `while`:
- in the constructs `a && b && c...` or `a || b || c...` the last subexpression does not need to be of type `Bool` if these constructs are not used as tests in `if` or `while`:
```{julia}
@@ -367,9 +367,9 @@ z = 3 < 4 && 10 < 50 && sqrt(3^3)
z, typeof(z)
```
## Loops *(loops)*
## Loops
### The `while` ("while") loop
### The `while` loop
Syntax:
@@ -408,7 +408,7 @@ while i<10
end
end
println("Fertig!")
println("Done!")
```
With `break` one can also exit infinite loops:
@@ -438,19 +438,19 @@ The loop body is executed for all items from a container.
Instead of `in`, $\in$ can always be used. In the header of a `for` loop, `=` can also be used.
```{julia}
for i ∈ ["Mutter", "Vater", "Tochter"]
for i ∈ ["Mother", "Father", "Daughter"]
println(i)
end
```
Often a numerical loop counter is needed. For this purpose, there is the *range* construct. The simplest forms are
A numerical loop counter is often needed. For this purpose, we have the `range` construct. The simplest forms are
`Start:End` and `Start:Step:End`.
```{julia}
endwert = 5
end_value = 5
for i ∈ 1:endwert
for i ∈ 1:end_value
println(i^2)
end
```
@@ -471,8 +471,7 @@ for k = 14 : -2.5 : 1 print(" $k") end
#### Nested Loops _(nested loops)_
#### Nested Loops
A `break` ends the innermost loop.
```{julia}
@@ -486,7 +485,7 @@ for i = 1:3
end
```
*Nested loops* can also be combined in a single `for` statement. Then a `break` ends the entire loop.
Nested loops can also be combined in a single `for` statement. Then a `break` ends the entire loop.
```{julia}
for i = 1:3, j=1:3 # essentially the same as above, but:
@@ -526,7 +525,7 @@ end
## Unicode
Julia uses Unicode as its character set. This allows identifiers from non-Latin scripts (e.g., Cyrillic, Korean, Sanskrit, runes,
Julia uses Unicode as its character set. This allows identifiers in non-Latin scripts (e.g., Cyrillic, Korean, Sanskrit, runes,
emojis,...) to be used for variables, functions, etc. The question of how one can enter such characters in their editor and whether the used screen font can display them is not Julia's problem.
- Some Unicode characters, e.g., `≤, ≠, ≥, π, ∈, √`, can be used instead of `<=, !=, >=, pi, in, sqrt`.
@@ -586,25 +585,25 @@ x = 4
```{julia}
Wichtig = 21
Wichtig! = 42 # identifiers can also contain !
(Wichtig, Wichtig!)
Important = 21
Important! = 42 # identifiers can also contain !
(Important, Important!)
```
```{julia}
Wichtig!=88
Important!=88
```
Julia interprets this as the comparison `Wichtig != 88`.
Julia interprets this as the *comparison* `Important != 88`.
Spaces help:
Again, spaces around operators help:
```{julia}
Wichtig! = 88
Wichtig!
Important! = 88
Important!
```
- Operators of the form `.*`, `.+`,... have a special meaning in Julia (*broadcasting*, i.e., vectorized operations).