June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,38 +1,16 @@
julia> "Inspired by Python's `input` function."
function input(prompt::AbstractString="")
print(prompt)
chomp(readline())
end
input (generic function with 2 methods)
function input(prompt::AbstractString)
print(prompt)
return readline()
end
julia> n = parse(Int, input("Upper bound for dimension 1: ")) # parse as `Int`
Upper bound for dimension 1: 5
5
n = input("Upper bound for dimension 1: ") |>
x -> parse(Int, x)
m = input("Upper bound for dimension 2: ") |>
x -> parse(Int, x)
julia> m = parse(Int, input("Upper bound for dimension 2: "))
Upper bound for dimension 2: 5
5
julia> x = rand(n, m) # create an n·m random matrix
5x5 Array{Float64,2}:
0.80217 0.422318 0.594049 0.45547 0.208822
0.0533981 0.304858 0.0276755 0.797732 0.828796
0.522506 0.563856 0.216759 0.865961 0.034306
0.792363 0.815744 0.868697 0.42509 0.588946
0.112034 0.539611 0.674581 0.508299 0.939373
julia> x[3, 3] # overloads `getindex` generic function
0.21675944652281487
julia> x[3, 3] = 5 # overloads `setindex!` generic function
5
julia> x::Matirx # `Matrix{T}` is an alias for `Array{T, 2}`
5x5 Array{Float64,2}:
0.80217 0.422318 0.594049 0.45547 0.208822
0.0533981 0.304858 0.0276755 0.797732 0.828796
0.522506 0.563856 5.0 0.865961 0.034306
0.792363 0.815744 0.868697 0.42509 0.588946
0.112034 0.539611 0.674581 0.508299 0.939373
julia> x = 0; gc() # Julia has no `del` command, rebind `x` and call the garbage collector
x = rand(n, m)
display(x)
x[3, 3] # overloads `getindex` generic function
x[3, 3] = 5.0 # overloads `setindex!` generic function
x::Matrix # `Matrix{T}` is an alias for `Array{T, 2}`
x = 0; gc() # Julia has no `del` command, rebind `x` and call the garbage collector