Reading parameter descriptions in Julia Documentation

Viewed 43

Compared to the Python documentation, I find that Julia documentation are much harder to read.

For example, the rand function:

rand([rng=GLOBAL_RNG], [S], [dims...])

How should I interpret this? What do the brackets mean? Which parameters are optional, and which are not?

Also, in Flux's documentation for Dense:

Dense(in, out, σ=identity; bias=true, init=glorot_uniform)

Why are some parameters separated by commas and others by semicolons?

1 Answers

The parameters is square brackets [] are optional - this is a convention for documentation across many programming languages - this is not a part of language syntax though. Hence all parameters for rand are optional and you can do just rand.

Actually it is a good idea to try to type methods(rand) in the console to see the huge number of methods required to cover all such use cases:

julia> methods(rand)
# 80 methods for generic function "rand":
[1] rand() in Random at c:\Julia-1.7.2\share\julia\stdlib\v1.7\Random\src\Random.jl:257
.....

Semicolon is a part of syntax used for separating positional parameters from named parameters in Julia functions. As an example consider a function:

function foo(a, b=4; c, d=8)
   return a+b+c+d
end

Than you could do:

julia> foo(1,c=100)
113
Related