Skip to content

Latest commit

 

History

History
687 lines (513 loc) · 9.42 KB

index.md

File metadata and controls

687 lines (513 loc) · 9.42 KB

Documentation

Index Page

Pages = ["index.md"]
Depth = 5

Functions Contents

Pages = ["lib/functions.md"]
Depth = 3

Tutorial Contents

Pages = ["man/tutorial.md"]

Index

Embedded @ref links headers: ccall

#60 #61

zeros(5, 5)
zeros(50, 50)
DocTestSetup = quote
    using Base
    x = -3:0.01:3
    y = -4:0.02:5
    z = [Float64((xi^2 + yi^2)) for xi in x, yi in y]
end
julia> [1.0, 2.0, 3.0]
3-element Array{Float64,1}:
 1.0
 2.0
 3.0

julia> println(" "^5)

julia> "\nfoo\n\nbar\n\n\nbaz"
"\nfoo\n\nbar\n\n\nbaz"

julia> println(ans)

foo

bar


baz
  • one two three

  • four five six

  • one
    

Raw Blocks

<center class="raw-html-block">
    <strong>CENTER</strong>
</center>
\begin{verbatim}
\end{verbatim}

Symbols in doctests

julia> a = :undefined
:undefined

julia> a
:undefined

Named doctests

julia> a = 1
1
julia> a + 1
2

Filtered doctests

Global

julia> print("Ptr{0x123456}")
Ptr{0x654321}

Local

DocTestFilters = [r"foo[a-z]+"]
julia> print("foobar")
foobuu
DocTestFilters = [r"foo[a-z]+", r"[0-9]+"]
julia> print("foobar123")
foobuu456
DocTestFilters = r"foo[a-z]+"
julia> print("foobar")
foobuu
DocTestFilters = nothing
julia> print("foobar")
foobar
DocTestFilters = []

Errors

DocTestFilters = [r"Stacktrace:\n \[1\][\s\S]+"]
julia> error()
ERROR:
Stacktrace:
 [1] error() at ./thisfiledoesnotexist.jl:123456789
julia> error()
ERROR:
Stacktrace:
[...]
DocTestFilters = []

Doctest keyword arguments

julia> f(2)
4

julia> g(2)
2
julia> f(2)
ERROR: UndefVarError: f not defined
julia> f(2)
4

julia> g(2)
2
julia> f(2)
4

julia> g(2)
2
julia> print("foobar")
foobuu
julia> print("foobar123")
foobuu456
julia> print("foobar")
foobuu
julia> f()
foobuu
foo(a, b) = a * b
foo(2, 3)

# output

6

World age issue for show

julia> @enum Color red blue green

julia> instances(Color)
(red, blue, green)

Sanitise module names

julia> struct T end

julia> t = T()
T()

julia> fullname(@__MODULE__)
(:Main,)

julia> fullname(Base.Broadcast)
(:Base, :Broadcast)

julia> @__MODULE__
Main

Issue398

DocTestSetup = quote
    module Issue398

    struct TestType{T} end

    function _show end
    Base.show(io::IO, t::TestType) = _show(io, t)

    macro define_show_and_make_object(x, y)
        z = Expr(:quote, x)
        esc(quote
            $(Issue398)._show(io::IO, t::$(Issue398).TestType{$z}) = print(io, $y)
            const $x = $(Issue398).TestType{$z}()
        end)
    end

    export @define_show_and_make_object

    end # module

    using .Issue398
end
julia> @define_show_and_make_object q "abcd"
abcd
DocTestSetup = nothing

Issue653

julia> struct MyException <: Exception
           msg::AbstractString
       end

julia> function Base.showerror(io::IO, err::MyException)
           print(io, "MyException: ")
           print(io, err.msg)
       end

julia> err = MyException("test exception")
MyException("test exception")

julia> sprint(showerror, err)
"MyException: test exception"

julia> throw(MyException("test exception"))
ERROR: MyException: test exception

Issue418

julia> f(x::Float64) = x
f (generic function with 1 method)

julia> f("")
ERROR: MethodError: no method matching f(::String)
Closest candidates are:
  f(!Matched::Float64) at none:1
julia> a = 1
1

julia> b = 2
2

julia> ex = :(a + b)
:(a + b)

julia> eval(ex)
3
ex = :(1 + 5)
eval(ex)
ex = :(1 + 5)
eval(ex)
a = 1
:(a + 1)

Issue #793

julia> write("issue793.jl", "\"Hello!\"");

julia> include("issue793.jl")
"Hello!"

julia> rm("issue793.jl");
write("issue793.jl", "\"Hello!\"")
include("issue793.jl")
rm("issue793.jl")
write("issue793.jl", "\"Hello!\"")
r = include("issue793.jl")
rm("issue793.jl")
r
julia> a = 1
1

julia> ans
1
julia> "hello"; "world"
"world"

julia> ans
"world"

Issue #1148

write("issue1148.jl", "x = 1148")
r = include("issue1148.jl")
rm("issue1148.jl")
x
@assert x == 1148

Issue513

julia> a = 1
1

julia> ans
1

Filtering of Main.

julia> struct Point end;

julia> println(Point)
Point

julia> sqrt(100)
10.0

julia> sqrt = 4
ERROR: cannot assign variable Base.sqrt from module Main
julia> g(x::Float64, y) = 2x + y
g (generic function with 1 method)

julia> g(x, y::Float64) = x + 2y
g (generic function with 2 methods)

julia> g(2.0, 3)
7.0

julia> g(2, 3.0)
8.0

julia> g(2.0, 3.0)
ERROR: MethodError: g(::Float64, ::Float64) is ambiguous. Candidates:
  g(x, y::Float64) in Main at none:1
  g(x::Float64, y) in Main at none:1
Possible fix, define
  g(::Float64, ::Float64)

Anonymous function declaration

julia> x->x # ignore error on 0.7
#1 (generic function with 1 method)

Assigning symbols example

r = :a

Bad links (Windows)

  • Colons not allowed on Windows -- some:path
  • No "drive" -- :path
  • Absolute Windows paths -- X:\some\path

Rendering text/markdown

struct MarkdownOnly
    value::String
end
Base.show(io::IO, ::MIME"text/markdown", mo::MarkdownOnly) = print(io, mo.value)

MarkdownOnly("""
**bold** output from MarkdownOnly
""")

Empty heading

Issue 1392

julia> function foo end;

Issue 890

I will pay $1 if $x^2$ is displayed correctly. People may also write $s or even money bag$$.

Module scrubbing from @repl and @example

None of these expressions should result in the gensym'd module in the output

@__MODULE__
println("@__MODULE__ is ", @__MODULE__) # sandbox printed to stdout
function f()
    println("@__MODULE__ is ", @__MODULE__)
    @warn "Main as the module for this log message"
    @__MODULE__
end
f()
@warn "Main as the module for this log message"
module A
    function f()
        println("@__MODULE__ is ", @__MODULE__)
        @warn "Main.A as the module for this log message"
        @__MODULE__
    end
end
A.f()
@__MODULE__ # sandbox as return value
println("@__MODULE__ is ", @__MODULE__) # sandbox printed to stdout
function f()
    println("@__MODULE__ is ", @__MODULE__)
end
f()
function f()
    @__MODULE__
end
f()
@warn "Main as the module for this log message"
module A
    function f()
        println("@__MODULE__ is ", @__MODULE__)
        @warn "Main.A as the module for this log message"
        @__MODULE__
    end
end
A.f()

Headings in block context

!!! error "Blocks in block context"

```julia
x^2
```

Headings:

# Heading 1
## Heading 2
### Heading 3
#### Heading 4
##### Heading 5
###### Heading 6

Also in block quotes:

x^2

Headings:

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

JuliaValue

It is possible to create pseudo-interpolations with the Markdown parser: $foo.

$([1 2 3; 4 5 6])

They do not get evaluated.

Admonitions

!!! note "'note' admonition" Admonitions look like this. This is a !!! note-type admonition.

Note that admonitions themselves can contain other block-level elements too,
such as code blocks. E.g.

```julia
f(x) = x^2
```

However, you **can not** have at-blocks, docstrings, doctests etc. in an admonition.

Headings are OK though:
# Heading 1
## Heading 2
### Heading 3
#### Heading 4
##### Heading 5
###### Heading 6

!!! info "'info' admonition" This is a !!! info-type admonition.

!!! tip "'tip' admonition" This is a !!! tip-type admonition.

!!! warning "'warning' admonition" This is a !!! warning-type admonition.

!!! danger "'danger' admonition" This is a !!! danger-type admonition.

!!! compat "'compat' admonition" This is a !!! compat-type admonition.

!!! details "'details' admonition" This is a !!! details-type admonition.

!!! ukw "Unknown admonition class" Admonition with an unknown admonition class.

@example outputs to file

Main.AT_EXAMPLE_FILES[("png", :big)]
Main.AT_EXAMPLE_FILES[("png", :tiny)]
Main.AT_EXAMPLE_FILES[("webp", :big)]
Main.AT_EXAMPLE_FILES[("webp", :tiny)]
Main.AT_EXAMPLE_FILES[("gif", :big)]
Main.AT_EXAMPLE_FILES[("jpeg", :tiny)]