Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

- _Antonello Lobianco (2019), "Julia Quick Syntax Refererence", Apress_

- [https://julia-book.com(https://julia-book.com/) (includes community forum and link to code repository)
- [https://julia-book.com](https://julia-book.com/) (includes community forum and link to code repository)

- This tutorial itself is still updated and may include new stuff that will be the base of further editions of the book.

Expand Down
2 changes: 1 addition & 1 deletion language-core/11-developing-julia-packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Modules can be entered in the REPL as normal Julia code or in a script that is i

There is no connection between a given file and a given module as in other languages, so the logical structure of a program can be decoupled from its actual division in files. For example, one file could contain multiple modules.

A more common way to use modules is by loading a package that will consists, at least, of a module with the same name of the package.
A more common way to use modules is by loading a package that will consist, at least, of a module with the same name of the package.

All modules are children of the module `Main`, the default module for global objects in Julia, and each module defines its own set of global names.

Expand Down
12 changes: 6 additions & 6 deletions language-core/control-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Julia support list comprehension and maps:
* `[myfunction(i) for i in [1, 2, 3]]`
* `[x + 2y for x in [10, 20, 30], y in [1, 2, 3]]`
* `mydict = Dict(); [mydict[i]=value for (i, value) in enumerate(mylist)]` \(`enumerate` returns an iterator to tuples with the index and the value of elements in an array\)
* `[students[name] = sex for (name,sex) in zip(names,sexes)]` \(`zip` returns an iterator of tuples pairing two or multiple lists, e.g. \[\("Marc","M"\),\("Anne","F"\)\] \)
* `map((n,s) -> students[n] = s, names, sexes)` \(`map` applies a function to a list of arguments\) When mapping a function with a single parameter, the parameter can be omitted: `a = map(f, [1, 2, 3])` is equal to `a = map(x->f(x), [1, 2, 3])`.
* `[students[name] = sex for (name,sex) in zip(names,sexes)]` \(`zip` returns an iterator of tuples pairing two or multiple lists, e.g. \[\("Marc", "M"\),\("Anne","F"\)\] \)
* `map((n,s) -> students[n] = s, names, sexes)` \(`map` applies a function to a list of arguments\) When mapping a function with a single parameter, the parameter can be omitted: `a = map(f, [1, 2, 3])` is equal to `a = map(x->f(x), [1, 2, 3])`.

Ternary operator is supported as `a ? b : c` \(if `a` is true, then `b`, else `c`\). Put attenction to wrap the `?` and `:` operators with space.
Ternary operator is supported as `a ? b : c` \(if `a` is true, then `b`, else `c`\). Put attention to wrap the `?` and `:` operators with space.

## Logical operators

Expand All @@ -28,18 +28,18 @@ Ternary operator is supported as `a ? b : c` \(if `a` is true, then `b`, else `c

Not to be confused with the bitwise operators `&` and `|`.

Currently `and` and `or` aliases to respectively `&&` and `||`has not being imlemented.
Currently, `and` and `or` aliases to respectively `&&` and `||`has not being implemented.

## Do blocks

Do blocks allow to define anonymous functions that are passed as first argument to the outer functions. For example, `findall(x -> x == value, myarray)` expects the first argument to be a function. Every time the first argument is a function, this can be written at posteriori with a do block:
Do blocks allow defining anonymous functions that are passed as first argument to the outer functions. For example, `findall(x -> x == value, myarray)` expects the first argument to be a function. Every time the first argument is a function, this can be written at posteriori with a do block:

```text
findall(myarray) do x
x == value
end
```

This defines `x` as a variable that is passed to the inner contend of the `do` block. It is the task of the outer function to where to apply this anonymous function \(in this case to the `myarray` array\) and what to do with its return values \(in this case boolean values used for computing the indexes in the array\). More infos on the do blocks: [https://en.wikibooks.org/wiki/Introducing\_Julia/Controlling\_the\_flow\#Do\_block](https://en.wikibooks.org/wiki/Introducing_Julia/Controlling_the_flow#Do_block) , [https://docs.julialang.org/en/stable/manual/functions/\#Do-Block-Syntax-for-Function-Arguments-1](https://docs.julialang.org/en/stable/manual/functions/#Do-Block-Syntax-for-Function-Arguments-1)
This defines `x` as a variable that is passed to the inner contend of the `do` block. It is the task of the outer function to figure out where to apply this anonymous function \(in this case to the `myarray` array\) and what to do with its return values \(in this case boolean values used for computing the indexes in the array\). More infos on the do blocks: [https://en.wikibooks.org/wiki/Introducing\_Julia/Controlling\_the\_flow\#Do\_block](https://en.wikibooks.org/wiki/Introducing_Julia/Controlling_the_flow#Do_block) , [https://docs.julialang.org/en/stable/manual/functions/\#Do-Block-Syntax-for-Function-Arguments-1](https://docs.julialang.org/en/stable/manual/functions/#Do-Block-Syntax-for-Function-Arguments-1)

_While an updated, expanded and revised version of this chapter is available in "Chapter 3 - Control Flow and Functions" of [Antonello Lobianco (2019), "Julia Quick Syntax Reference", Apress](https://julia-book.com), this tutorial remains in active development._
6 changes: 3 additions & 3 deletions language-core/custom-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Structures \(previously known in Julia as "Types"\) are, for the most \(see later for the difference\), what in other languages are called classes, or "structured data": they define the kind of information that is embedded in the structure, that is a set of fields \(aka "properties" in other languages\), and then individual instances \(or "objects"\) can be produced each with its own specific values for the fields defined by the structure.

They are "composite" types, in the sense that are not made of just a fixed amound of bits as instead "primitive" types.
They are "composite" types, in the sense that are not made of just a fixed amount of bits as instead "primitive" types.

Some syntax that will be used in the examples:

Expand Down Expand Up @@ -30,7 +30,7 @@ mutable struct MyOwnType{T<:Number}
end
```

You can omit the `mutable` keyword in front of `struct` when you want to enforce that once an object of that type has been created, its fields can no longer be changed \(i.e. , structures are immutable by default. Note that mutable objects -as arrays- remain themselves mutable also in a immutable structure\). Although obviously less flexible, immutable structures are much faster.
You can omit the `mutable` keyword in front of `struct` when you want to enforce that once an object of that type has been created, its fields can no longer be changed \(i.e., structures are immutable by default. Note that mutable objects -as arrays- remain themselves mutable also in a immutable structure\). Although obviously less flexible, immutable structures are much faster.

You can create abstract types using the keyword `abstract type`. Abstract types do not have any field, and objects can not be instantiated from them, although concrete types \(structures\) can be defined as subtypes of them \(an [issue](https://github.com/JuliaLang/julia/issues/4935%20) to allow abstract classes to have fields is currently open and may be implemented in the future\).

Expand Down Expand Up @@ -118,7 +118,7 @@ Some useful type-related functions:

This is the complete type hierarchy of `Number in Julia (credits to Wikipedia):`

![](https://github.com/sylvaticus/juliatutorial/tree/53fb590910bcc61cd119e7784eb4afa99addd8ac/assets/type_hierarchy_for_julia_numbers.png)
![Type hierarchy for Julia numbers](https://upload.wikimedia.org/wikipedia/commons/4/40/Type-hierarchy-for-julia-numbers.png)

Note that because concrete types are definitive, i.e. that can't have further subtypes, arrays of `ConcreteType` are not subtypes of arrays of `AbstractType`, even when `ConcreteType` is actually a subtype of `AbstractType`, This is true for any parametric type, not just arrays.
In function signature, when you want to express the concept that you want to accept as argument an array of any subtype of `AbstractType`, you can use a template.
Expand Down
Loading