cs-julia.md 34 KB



0.5-dev

✶ Troubleshoot errors when running the unstable DEV branch

ToDo Status

  1. Closures : Functions with data inside (captured variables) ex. adder(x) = y -> y+x A function that returns an adding function. If you give x and it returns x after adding some data to it as the data is wrapped in it. Not sure how they relate to generic functions and methods

HDF5

  • Array based storage using HDF5 and JLD
    • To use HDF5 (with JLD, which has been split recently), use Pkg.add("JLD") and in future, to use it say "using JLD" rather than "using HDF5, JLD."

Current changes in 0.4

Your "subtype declaration" section is wrong: the abstract type does not define a block (you should just have "abstract Foo", not "abstract Foo ... end")

The "String" type is deprecated in favor of AbstractString in 0.4

[1:10] is deprecated in 0.4, in favor of [1:10;] to explicitly vcat.

You can just use +, not .+, for element-wise addition. (It doesn't hurt to do .+, but it is unnecessary.)

help("func") is gone in 0.4

Pkg.build("Package") is useful to rebuild a package if the package build failed or your system configuration changed.

char(n) is deprecated in favor of Char(n) in 0.4

"Beware of multi-byte Unicode characters" is a bit misleading; it is not the Unicode "character" (technically you are referring to "codepoints") that is multi-byte, but rather the codepoint's encoding in UTF-8 (the default in Julia). Maybe "Beware of multi-byte Unicode encodings in UTF-8"

(Of course, there are many other subtleties with Unicode: e.g. your example string "Ångström" can also be written "Ångström", which looks identical but actually uses a different set of codepoints via "combining characters".)

UintN in Julia 0.4 is deprecated in favor of UIntN (note caps).

Note there is also Complex{T}; Complex128 is just a shorthand for Complex{Float64}.

im is the "imaginary unit", not the "imaginary number".

eps() is an abbreviation for eps(Float64). eps(T) is also defined for other types.

  • In 0.4, TypeName(val) automatically calls convert(TypeName, val) if no other constructor is available. This also means that, when you are defining your own type, you should extend Base.convert if you have new conversions, rather than adding constructors.

  • eye(N) is an NxN identity; calling it "N-dimensional" may confuse people into thinking it returns an N-dimensional array.

  • M' is a synonym for ctranspose(M) (conjugate transpose). M.' is transpose(M) without conjugation. Of course, for real matrices they are equivalent.

  • Note that we can also do "for i in 1:10" ... this syntax is perhaps a bit clearer in that it generalizes to iterating over other kinds of containers.

  • To exit a loop you do "break", not "exit" (which is a function).

  • Functions with ! appended mutate at least one of their arguments. Not necessarily the first one (e.g. see A_ldiv_B!), although this is the most common.

  • If you need tail-call optimization, it is more idiomatic to simply write a loop.

  • Instead of in(val,arr), you can simply do "val in arr"

  • The dictionary syntax has changed in 0.4: use Dict(a=>b, ...)

{...} is deprecated in 0.4. Use Any[...].

it is more idiomatic to put "do" on the same line:

map(collection) do elem
   ...
end

You can override Base.show(io, ex) rather than Base.showerror.