|
| 1 | +module CtagsTest |
| 2 | + |
| 3 | +using Test |
| 4 | +using Base.Sort.QuickSort |
| 5 | +using Base.Sort: MergeSort, InsertionSort |
| 6 | + |
| 7 | +#= |
| 8 | +using Documenter |
| 9 | +=# |
| 10 | + |
| 11 | +import Distributed |
| 12 | +import Base.show |
| 13 | +import DelimitedFiles: readdlm, writedlm |
| 14 | + |
| 15 | +struct ImmutablePoint{T} |
| 16 | + x::T |
| 17 | + y::T |
| 18 | +end |
| 19 | + |
| 20 | +mutable struct MutablePoint{T} |
| 21 | + x::T |
| 22 | + y::T |
| 23 | +end |
| 24 | + |
| 25 | +""" |
| 26 | + Names(first, last) |
| 27 | +
|
| 28 | +Contains the first and last name of a person. |
| 29 | +Can be called with keywords. |
| 30 | +
|
| 31 | +# Example |
| 32 | +
|
| 33 | +```julia-repl |
| 34 | +julia> Names(last="Bond", first="James") # Bond |
| 35 | +Names("James", "Bond") |
| 36 | +``` |
| 37 | +""" |
| 38 | +Base.@kwdef struct Names |
| 39 | + first::AbstractString |
| 40 | + last::AbstractString |
| 41 | +end |
| 42 | + |
| 43 | +""" |
| 44 | + Names(first, last) |
| 45 | +
|
| 46 | +Contains the first and last name of a person. |
| 47 | +Can be called with keywords. |
| 48 | +
|
| 49 | +# Examples |
| 50 | +```jldoctest |
| 51 | +julia> Names(last="Bond", first="James") # Bond |
| 52 | +Names("James", "Bond") |
| 53 | +``` |
| 54 | +""" |
| 55 | +Base.@kwdef mutable struct VariableNames |
| 56 | + first::AbstractString |
| 57 | + last::AbstractString |
| 58 | +end |
| 59 | + |
| 60 | +# Lambda function |
| 61 | +""" |
| 62 | + returnsquarepower() |
| 63 | +
|
| 64 | +Return the power used to square numbers. |
| 65 | +
|
| 66 | +# Examples |
| 67 | +```jldoctest; output = false |
| 68 | +mysquarepower = returnsquarepower() |
| 69 | +# or |
| 70 | +const myconstsquarepower = returnsquarepower() |
| 71 | +
|
| 72 | +# output |
| 73 | +
|
| 74 | +2 |
| 75 | +``` |
| 76 | +""" |
| 77 | +returnsquarepower = () -> 2 |
| 78 | + |
| 79 | +#= |
| 80 | +deprecated_returnsquarepower() = 2.0 |
| 81 | +const deprecated_squarepower = deprecated_returnsquarepower() |
| 82 | +=# |
| 83 | + |
| 84 | +"Number used to square – not cube – numbers." |
| 85 | +squarepower = returnsquarepower |
| 86 | +"A universally accepted greeting." |
| 87 | +const greeting = "Hello" |
| 88 | + |
| 89 | +function square(x) |
| 90 | + x ^ squarepower |
| 91 | +end |
| 92 | + |
| 93 | +function addone!(x::T) where {T <: Number} |
| 94 | + x += one(T) |
| 95 | +end |
| 96 | + |
| 97 | +addtwo!(x::T) where {T <: Number} = (x += one(T) + one(T)) |
| 98 | + |
| 99 | +addcoment(string::AbstractString, comment, spaces=1) = begin # Maybe write without `begin`? |
| 100 | + string * " "^spaces * "# " * comment |
| 101 | +end |
| 102 | + |
| 103 | +multiply(x, y) = x * y |
| 104 | +multiply(x, y...) = begin |
| 105 | + multiply(y...) * x |
| 106 | +end |
| 107 | + |
| 108 | +""" |
| 109 | + greet(x) |
| 110 | +
|
| 111 | +Generate different greeting strings depending on who you are talking to. |
| 112 | +
|
| 113 | +# Examples |
| 114 | +```@meta |
| 115 | +DocTestSetup = quote |
| 116 | + function printgreeting(x) |
| 117 | + println(greet(x)) |
| 118 | + end |
| 119 | +end |
| 120 | +``` |
| 121 | +
|
| 122 | +```jldoctest |
| 123 | +julia> greet("Julia") |
| 124 | +Hello Julia! |
| 125 | +
|
| 126 | +julia> greet(3141) |
| 127 | +Hello Robot 3141! |
| 128 | +
|
| 129 | +julia> greet(0x1f) |
| 130 | +Hello Robot 0x1f! |
| 131 | +
|
| 132 | +julia> greet(BitVector([1, 0, 1])) |
| 133 | +Hello binary data 101! |
| 134 | +``` |
| 135 | +""" |
| 136 | +@generated function greet(x) |
| 137 | + if x <: Union{AbstractString, AbstractChar} |
| 138 | + :("$greeting $x!") |
| 139 | + elseif x <: Unsigned |
| 140 | + :("$greeting Robot 0x$(string(x, base=16))!") |
| 141 | + elseif x <: Number |
| 142 | + :("$greeting Robot $(string(x))!") |
| 143 | + else |
| 144 | + :("$greeting binary data $(bitstring(x))!") |
| 145 | + end |
| 146 | +end |
| 147 | + |
| 148 | +# TODO add `greet` for aliens |
| 149 | + |
| 150 | +greet("Julia") |
| 151 | + |
| 152 | +end # module |
| 153 | + |
0 commit comments