diff options
Diffstat (limited to 'julia.html.markdown')
-rw-r--r-- | julia.html.markdown | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/julia.html.markdown b/julia.html.markdown index 2fe05c49..5e9ef1b8 100644 --- a/julia.html.markdown +++ b/julia.html.markdown @@ -46,6 +46,13 @@ div(5, 2) # => 2 # for a truncated result, use div # Enforce precedence with parentheses (1 + 3) * 2 # => 8 +# Julia (unlike Python for instance) has integer under/overflow +10^19 # => -8446744073709551616 +# use bigint or floating point to avoid this +big(10)^19 # => 10000000000000000000 +1e19 # => 1.0e19 +10.0^19 # => 1.0e19 + # Bitwise Operators ~2 # => -3 # bitwise not 3 & 5 # => 1 # bitwise and @@ -93,21 +100,22 @@ ascii("This is a string")[1] # Julia indexes from 1 # Otherwise, iterating over strings is recommended (map, for loops, etc). +# String can be compared lexicographically +"good" > "bye" # => true +"good" == "good" # => true +"1 + 2 = 3" == "1 + 2 = $(1 + 2)" # => true + # $ can be used for string interpolation: "2 + 2 = $(2 + 2)" # => "2 + 2 = 4" # You can put any Julia expression inside the parentheses. +# Printing is easy +println("I'm Julia. Nice to meet you!") # => I'm Julia. Nice to meet you! + # Another way to format strings is the printf macro from the stdlib Printf. using Printf @printf "%d is less than %f\n" 4.5 5.3 # => 5 is less than 5.300000 -# Printing is easy -println("I'm Julia. Nice to meet you!") # => I'm Julia. Nice to meet you! - -# String can be compared lexicographically -"good" > "bye" # => true -"good" == "good" # => true -"1 + 2 = 3" == "1 + 2 = $(1 + 2)" # => true #################################################### ## 2. Variables and Collections @@ -163,6 +171,8 @@ matrix = [1 2; 3 4] # => 2×2 Array{Int64,2}: [1 2; 3 4] b = Int8[4, 5, 6] # => 3-element Array{Int8,1}: [4, 5, 6] # Add stuff to the end of a list with push! and append! +# By convention, the exclamation mark '!'' is appended to names of functions +# that modify their arguments push!(a, 1) # => [1] push!(a, 2) # => [1,2] push!(a, 4) # => [1,2,4] |