Skip to content

Commit

Permalink
adjust teaching orders for varied parts for julia syntax episode
Browse files Browse the repository at this point in the history
  • Loading branch information
code4yonglei committed Dec 5, 2024
1 parent 9e0f3d6 commit 63a7288
Showing 1 changed file with 66 additions and 61 deletions.
127 changes: 66 additions & 61 deletions content/syntax-intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ Vectors and arrays
| | - ``zeros(4,4,4,4)`` Zero 4×4×4×4 Array{Float64,4} |
| | - ``rand(12,4)`` Random 12×4 Matrix{Float64} |
+------------------+-------------------------------------------------------------------+
| Manipulating | - ``push!(a, 10)`` Append in-place |
| arrays | - ``insert!(a, 1, 42)`` Insert in given position |
| | - ``append!(a, [3, 5, 7])`` Append another array |
| | - ``splice!(a, 3, -1)`` Rm in given pos and replace |

Check warning on line 196 in content/syntax-intro.rst

View workflow job for this annotation

GitHub Actions / Build and gh-pages

Blank line required after table.
+------------------+-------------------------------------------------------------------+

Check warning on line 197 in content/syntax-intro.rst

View workflow job for this annotation

GitHub Actions / Build and gh-pages

Line block ends without a blank line.

Check failure on line 197 in content/syntax-intro.rst

View workflow job for this annotation

GitHub Actions / Build and gh-pages

Malformed table.
| Inspecting | - ``length(a)`` |
| array properties | - ``first(a)`` |
| | - ``last(a)`` |
Expand All @@ -198,11 +203,7 @@ Vectors and arrays
| | - ``argmin(a)`` |
| | - ``argmax(a)`` |
| | - ``size(a)`` |
+------------------+-------------------------------------------------------------------+
| Manipulating | - ``push!(a, 10)`` Append in-place |
| arrays | - ``insert!(a, 1, 42)`` Insert in given position |
| | - ``append!(a, [3, 5, 7])`` Append another array |
| | - ``splice!(a, 3, -1)`` Rm in given pos and replace |

Check warning on line 206 in content/syntax-intro.rst

View workflow job for this annotation

GitHub Actions / Build and gh-pages

Blank line required after table.
+------------------+-------------------------------------------------------------------+

We can play around with Vectors and Arrays to get used to their syntax:
Expand Down Expand Up @@ -237,6 +238,7 @@ We can play around with Vectors and Arrays to get used to their syntax:
# true
Loops and conditionals
----------------------

Expand Down Expand Up @@ -299,62 +301,6 @@ While loops:
end
Working with files
------------------

Obtain a file handle to start reading from file,
and then close it:

.. code-block:: julia
f = open("myfile.txt")
# work with file...
close(f)
The recommended way to work with files is to use a do-block.
At the end of the do-block the file will be closed automatically:

.. code-block:: julia
open("myfile.txt") do f
# read from file
lines = readlines(f)
println(lines)
end
Writing to a file:

.. code-block:: julia
open("myfile.txt", "w") do f
write(f, "another line")
end
Some useful functions to work with files:

+----------------------+---------------------------------------------------------+
| Function | What it does |
+======================+=========================================================+
| ``pwd()`` | Show current directory |
+----------------------+---------------------------------------------------------+
| ``cd(path)`` | Change directory |
+----------------------+---------------------------------------------------------+
| ``readdir(path)`` | Return list of current directory |
+----------------------+---------------------------------------------------------+
| ``mkdir(path)`` | Create directory |
+----------------------+---------------------------------------------------------+
| ``abspath(path)`` | Add current dir to filename |
+----------------------+---------------------------------------------------------+
| ``joinpath(p1, p2)`` | Join two paths |
+----------------------+---------------------------------------------------------+
| ``isdir(path)`` | Check if path is a directory |
+----------------------+---------------------------------------------------------+
| ``splitdir(path)`` | Split path into tuple of dirname and filename |
+----------------------+---------------------------------------------------------+
| ``homedir()`` | Return home directory |
+----------------------+---------------------------------------------------------+

Functions
---------
Expand Down Expand Up @@ -524,6 +470,65 @@ Compare, for example:
sum!([1 1], A) # mutates A into 1x2 Matrix with elements 4, 6
Working with files
------------------

Obtain a file handle to start reading from file,
and then close it:

.. code-block:: julia
f = open("myfile.txt")
# work with file...
close(f)
The recommended way to work with files is to use a do-block.
At the end of the do-block the file will be closed automatically:

.. code-block:: julia
open("myfile.txt") do f
# read from file
lines = readlines(f)
println(lines)
end
Writing to a file:

.. code-block:: julia
open("myfile.txt", "w") do f
write(f, "another line")
end
Some useful functions to work with files:

+----------------------+---------------------------------------------------------+
| Function | What it does |
+======================+=========================================================+
| ``pwd()`` | Show current directory |
+----------------------+---------------------------------------------------------+
| ``cd(path)`` | Change directory |
+----------------------+---------------------------------------------------------+
| ``readdir(path)`` | Return list of current directory |
+----------------------+---------------------------------------------------------+
| ``mkdir(path)`` | Create directory |
+----------------------+---------------------------------------------------------+
| ``abspath(path)`` | Add current dir to filename |
+----------------------+---------------------------------------------------------+
| ``joinpath(p1, p2)`` | Join two paths |
+----------------------+---------------------------------------------------------+
| ``isdir(path)`` | Check if path is a directory |
+----------------------+---------------------------------------------------------+
| ``splitdir(path)`` | Split path into tuple of dirname and filename |
+----------------------+---------------------------------------------------------+
| ``homedir()`` | Return home directory |
+----------------------+---------------------------------------------------------+



Exception handling
------------------

Expand Down

0 comments on commit 63a7288

Please sign in to comment.