-
Notifications
You must be signed in to change notification settings - Fork 15
7ML7W Julia Day 1: Resistance Is Futile
July 3rd, 2018 - Unboxed.
Strings are now just strings, ASCIIString
no longer seems to be the default inferred type for stringy things.
julia> typeof("julia")
String
We also soon learned that the following { } vector syntax
was 'discontinued':
julia> typeof({ :key => "value" })
ERROR: syntax: { } vector syntax is discontinued
The new way to do this seems to be:
julia> typeof(Dict(:key => "value"))
Dict{Symbol,String}
This is seems to infer the types where the deprecated syntax would have given Dict{Any,Any}
for the same input. It seems to get this now you need to create an empty Dict first:
julia> typeof(Dict())
Dict{Any,Any}
The 'explicit' [:key => "value"]
syntax now also seems to construct arrays now - not Dicts:
julia> typeof([:key => "value"])
Array{Pair{Symbol,String},1}
We pondered a little about the use case for this reverse division operator:
julia> 10 \ 2
0.2
julia> 10 / 2
5.0
We also spent some time thinking about the type coercion:
julia> [1, 1.2, 3]
3-element Array{Float64,1}:
1.0
1.2
3.0
julia> push!(Int[1,2,3], 1.2)
ERROR: InexactError()
Stacktrace:
[1] convert(::Type{Int64}, ::Float64) at ./float.jl:679
[2] push!(::Array{Int64,1}, ::Float64) at ./array.jl:646
We also discovered that the one top of the type hierarchy seemed to be Datatype
:
julia> typeof(Float64)
DataType
julia> typeof(Int64)
DataType
julia> typeof(DataType)
DataType
julia> typeof(typeof)
Core.#typeof
julia> typeof(+)
Base.#+
We didn't get round to looking into what the difference between Any
and DataType
was.
julia> typeof(Any)
DataType
Next came arrays, something that's not quite as you know it in Julia.
Indexing is from 1 and there's :end
to get the last position:
julia> [1,2,3,4][2:end]
3-element Array{Int64,1}:
2
3
4
You can assign to ranges in arrays but only if they're the same length:
julia> [1,2,3,4][3:end] = [1,2]
2-element Array{Int64,1}:
1
2
julia> [1,2,3,4][3:end] = [1,2,3]
ERROR: DimensionMismatch("tried to assign 3 elements to 2 destinations")
Stacktrace:
[1] throw_setindex_mismatch(::Array{Int64,1}, ::Tuple{Int64}) at ./indices.jl:92
[2] setindex_shape_check(::Array{Int64,1}, ::Int64) at ./indices.jl:143
[3] setindex!(::Array{Int64,1}, ::Array{Int64,1}, ::UnitRange{Int64}) at ./array.jl:613
We then came across an unusual new syntax for multi dimensional arrays:
julia> [1 2 3; 4 5 6]
2×3 Array{Int64,2}:
1 2 3
4 5 6
julia> [1, 2, 3; 4, 5, 6]
ERROR: syntax: unexpected semicolon in array expression
- Home
- Documentation
- Choosing a Topic
- Shows & Tells
- Miscellaneous
- Opt Art
- Reinforcement Learning: An Introduction
- 10 Technical Papers Every Programmer Should Read (At Least Twice)
- 7 More Languages in 7 Weeks
- Lua, Day 1: The Call to Adventure
- Lua, Day 2: Tables All the Way Down
- Lua, Day 3
- Factor, Day 1: Stack On, Stack Off
- Factor, Day 2: Painting the Fence
- Factor, Day 3: Balancing on a Boat
- Elm, Day 1: Handling the Basics
- Elm, Day 2: The Elm Architecture
- Elm, Day 3: The Elm Architecture
- Elixir, Day 1: Laying a Great Foundation
- Elixir, Day 2: Controlling Mutations
- Elixir, Day 3: Spawning and Respawning
- Julia, Day 1: Resistance Is Futile
- Julia, Day 2: Getting Assimilated
- Julia, Day 3: Become One With Julia
- Minikanren, Days 1-3
- Minikanren, Einstein's Puzzle
- Idris Days 1-2
- Types and Programming Languages
- Chapter 1: Introduction
- Chapter 2: Mathematical Preliminaries
- Chapter 3: Untyped Arithmetic Expressions
- Chapter 4: An ML Implementation of Arithmetic Expressions
- Chapter 5: The Untyped Lambda-Calculus
- Chapters 6 & 7: De Bruijn Indices and an ML Implementation of the Lambda-Calculus
- Chapter 8: Typed Arithmetic Expressions
- Chapter 9: The Simply-Typed Lambda Calculus
- Chapter 10: An ML Implementation of Simple Types
- Chapter 11: Simple Extensions
- Chapter 11 Redux: Simple Extensions
- Chapter 13: References
- Chapter 14: Exceptions
- Chapter 15: Subtyping – Part 1
- Chapter 15: Subtyping – Part 2
- Chapter 16: The Metatheory of Subtyping
- Chapter 16: Implementation
- Chapter 18: Case Study: Imperative Objects
- Chapter 19: Case Study: Featherweight Java
- The New Turing Omnibus
- Errata
- Chapter 11: Search Trees
- Chapter 8: Random Numbers
- Chapter 35: Sequential Sorting
- Chapter 58: Predicate Calculus
- Chapter 27: Perceptrons
- Chapter 9: Mathematical Research
- Chapter 16: Genetic Algorithms
- Chapter 37: Public Key Cryptography
- Chapter 6: Game Trees
- Chapter 5: Gödel's Theorem
- Chapter 34: Satisfiability (also featuring: Sentient)
- Chapter 44: Cellular Automata
- Chapter 47: Storing Images
- Chapter 12: Error-Correcting Codes
- Chapter 32: The Fast Fourier Transform
- Chapter 36: Neural Networks That Learn
- Chapter 41: NP-Completeness
- Chapter 55: Iteration and Recursion
- Chapter 19: Computer Vision
- Chapter 61: Searching Strings
- Chapter 66: Church's Thesis
- Chapter 52: Text Compression
- Chapter 22: Minimum spanning tree
- Chapter 64: Logic Programming
- Chapter 60: Computer Viruses
- Show & Tell
- Elements of Computing Systems
- Archived pages