Skip to content

Instantly share code, notes, and snippets.

@hayd
Created March 26, 2015 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hayd/9cbd69e5e85693d1f6eb to your computer and use it in GitHub Desktop.
Save hayd/9cbd69e5e85693d1f6eb to your computer and use it in GitHub Desktop.
WIP julia docs (rst to md)
@doc """
""" Base
# Essentials
# ==========
#
# Introduction
# ------------
#
# The Julia standard library contains a range of functions and macros appropriate for performing scientific and numerical computing, but is also as broad as those of many general purpose programming languages. Additional functionality is available from a growing collection of available packages. Functions are grouped by topic below.
#
# Some general notes:
#
# - Except for functions in built-in modules (~Base.Pkg, ~Base.Collections, ~Base.Graphics, ~Base.Test and ~Base.Profile), all functions documented here are directly available for use in programs.
# - To use module functions, use `import Module` to import the module, and `Module.fn(x)` to use the functions.
# - Alternatively, `using Module` will import all exported `Module` functions into the current namespace.
# - By convention, function names ending with an exclamation point (`!`) modify their arguments. Some functions have both modifying (e.g., `sort!`) and non-modifying (`sort`) versions.
#
# Getting Around
# --------------
#
@doc """Quit (or control-D at the prompt). The default exit code is zero, indicating that the processes completed successfully.
""" exit([code])
@doc """Quit the program indicating that the processes completed successfully. This function calls `exit(0)` (see exit).
""" quit()
@doc """Register a zero-argument function to be called at exit.
""" atexit(f)
@doc """Determine whether Julia is running an interactive session.
""" isinteractive() -> Bool
@doc """Print information about exported global variables in a module, optionally restricted to those matching `pattern`.
""" whos([Module,] [pattern::Regex])
@doc """Edit a file optionally providing a line number to edit at. Returns to the julia prompt when you quit the editor.
""" edit(file::AbstractString, [line])
@doc """Edit the definition of a function, optionally specifying a tuple of types to indicate which method to edit.
""" edit(function, [types])
@doc """Evaluates the arguments to the function call, determines their types, and calls the `edit` function on the resulting expression
""" @edit
@doc """Show a file using the default pager, optionally providing a starting line number. Returns to the julia prompt when you quit the pager.
""" less(file::AbstractString, [line])
@doc """Show the definition of a function using the default pager, optionally specifying a tuple of types to indicate which method to see.
""" less(function, [types])
@doc """Evaluates the arguments to the function call, determines their types, and calls the `less` function on the resulting expression
""" @less
@doc """Send a printed form of `x` to the operating system clipboard ("copy").
""" clipboard(x)
@doc """Return a string with the contents of the operating system clipboard ("paste").
""" clipboard() -> AbstractString
@doc """Load source files once, in the context of the `Main` module, on every active node, searching standard locations for files. `require` is considered a top-level operation, so it sets the current `include` path but does not use it to search for files (see help for `include`). This function is typically used to load library code, and is implicitly called by `using` to load packages.
When searching for files, `require` first looks in the current working directory, then looks for package code under `Pkg.dir()`, then tries paths in the global array `LOAD_PATH`.
""" require(file::AbstractString...)
@doc """Like `require`, except forces loading of files regardless of whether they have been loaded before. Typically used when interactively developing libraries.
""" reload(file::AbstractString)
@doc """Evaluate the contents of a source file in the current context. During including, a task-local include path is set to the directory containing the file. Nested calls to `include` will search relative to that path. All paths refer to files on node 1 when running in parallel, and files will be fetched from node 1. This function is typically used to load source interactively, or to combine files in packages that are broken into multiple source files.
""" include(path::AbstractString)
@doc """Like `include`, except reads code from the given string rather than from a file. Since there is no file path involved, no path processing or fetching from node 1 is done.
""" include_string(code::AbstractString)
@doc """Get help for a function. `name` can be an object or a string.
""" help(name)
@doc """
""" Base
# Collections and Data Structures
# ===============================
#
# Iteration
# ---------
#
# Sequential iteration is implemented by the methods start, done, and next. The general `for` loop:
#
# for i = I # or "for i in I"
# # body
# end
#
# is translated into:
#
# state = start(I)
# while !done(I, state)
# (i, state) = next(I, state)
# # body
# end
#
# The `state` object may be anything, and should be chosen appropriately for each iterable type.
#
@doc """Get initial iteration state for an iterable object
""" start(iter) -> state
@doc """Test whether we are done iterating
""" done(iter, state) -> Bool
@doc """For a given iterable object and iteration state, return the current item and the next iteration state
""" next(iter, state) -> item, state
@doc """For a set of iterable objects, returns an iterable of tuples, where the `i`th tuple contains the `i`th component of each input iterable.
Note that zip is its own inverse: `[zip(zip(a...)...)...] == [a...]`.
""" zip(iters...)
@doc """Return an iterator that yields `(i, x)` where `i` is an index starting at 1, and `x` is the `i`th value from the given iterator. It's useful when you need not only the values `x` over which you are iterating, but also the index `i` of the iterations.
```doctest
julia> a = ["a", "b", "c"];
julia> for (index, value) in enumerate(a)
println("$index $value")
end
1 a
2 b
3 c
```""" enumerate(iter)
# Fully implemented by:
#
# - Range
# - UnitRange
# - NDRange
# - Tuple
# - Number
# - AbstractArray
# - IntSet
# - ObjectIdDict
# - Dict
# - WeakKeyDict
# - EachLine
# - AbstractString
# - Set
# - Task
#
# General Collections
# ===================
#
@doc """Determine whether a collection is empty (has no elements).
```doctest
julia> isempty([])
true
julia> isempty([1 2 3])
false
```""" isempty(collection) -> Bool
@doc """Remove all elements from a `collection`.
""" empty!(collection) -> collection
@doc """For ordered, indexable collections, the maximum index `i` for which `getindex(collection, i)` is valid. For unordered collections, the number of elements.
""" length(collection) -> Integer
@doc """Returns the last index of the collection.
```doctest
julia> endof([1,2,4])
3
```""" endof(collection) -> Integer
# Fully implemented by:
#
# - Range
# - UnitRange
# - Tuple
# - Number
# - AbstractArray
# - IntSet
# - Dict
# - WeakKeyDict
# - AbstractString
# - Set
#
# Iterable Collections
# ====================
#
s = doc"""Determine whether an item is in the given collection, in the sense that it is `==` to one of the values generated by iterating over the collection. Some collections need a slightly different definition; for example Sets check whether the item isequal to one of the elements. Dicts look for `(key,value)` pairs, and the key is compared using isequal. To test for the presence of a key in a dictionary, use haskey or `k in keys(dict)`.
"""
for f in [in(item, collection) -> Bool, ∈(item,collection) -> Bool, ∋(collection,item) -> Bool, ∉(item,collection) -> Bool, ∌(collection,item) -> Bool, ]
@doc s f
end
@doc """Determine the type of the elements generated by iterating `collection`. For associative collections, this will be a `(key,value)` tuple type.
""" eltype(collection)
@doc """Returns a vector containing the highest index in `b` for each value in `a` that is a member of `b` . The output vector contains 0 wherever `a` is not a member of `b`.
""" indexin(a, b)
@doc """Returns the indices of elements in collection `a` that appear in collection `b`
""" findin(a, b)
@doc """Returns an array containing only the unique elements of the iterable `itr`, in the order that the first of each set of equivalent elements originally appears. If `dim` is specified, returns unique regions of the array `itr` along `dim`.
""" unique(itr[, dim])
@doc """Reduce the given collection `ìtr` with the given binary operator `op`. `v0` must be a neutral element for `op` that will be returned for empty collections. It is unspecified whether `v0` is used for non-empty collections.
Reductions for certain commonly-used operators have special implementations which should be used instead: `maximum(itr)`, `minimum(itr)`, `sum(itr)`, `prod(itr)`, `any(itr)`, `all(itr)`.
The associativity of the reduction is implementation dependent. This means that you can't use non-associative operations like `-` because it is undefined whether `reduce(-,[1,2,3])` should be evaluated as `(1-2)-3` or `1-(2-3)`. Use `foldl` or `foldr` instead for guaranteed left or right associativity.
Some operations accumulate error, and parallelism will also be easier if the reduction can be executed in groups. Future versions of Julia might change the algorithm. Note that the elements are not reordered if you use an ordered collection.
""" reduce(op, v0, itr)
@doc """Like `reduce(op, v0, itr)`. This cannot be used with empty collections, except for some special cases (e.g. when `op` is one of `+`, `*`, `max`, `min`, `&`, `|`) when Julia can determine the neutral element of `op`.
""" reduce(op, itr)
@doc """
""" Dates
# Dates and Time
# ==============
#
# Dates and Time Types
# --------------------
#
s = doc"""`Period` types represent discrete, human representations of time.
"""
for f in [Period ,Year ,Month ,Week ,Day ,Hour ,Minute ,Second ,Millisecond ,]
@doc s f
end
@doc """`Instant` types represent integer-based, machine representations of time as continuous timelines starting from an epoch.
""" Instant
@doc """The `UTInstant` represents a machine timeline based on UT time (1 day = one revolution of the earth). The `{T}` is a `Period` parameter that indicates the resolution or precision of the instant.
""" UTInstant{T}
@doc """`TimeType` types wrap `Instant` machine instances to provide human representations of the machine instant.
""" TimeType
@doc """`DateTime` wraps a `UTInstant{Millisecond}` and interprets it according to the proleptic Gregorian calendar.
""" DateTime
@doc """`Date` wraps a `UTInstant{Day}` and interprets it according to the proleptic Gregorian calendar.
""" Date
# Dates Functions
# ===============
#
# All Dates functions are defined in the `Dates` module; note that only the `Date`, `DateTime`, and `now` functions are exported; to use all other `Dates` functions, you'll need to prefix each function call with an explicit `Dates.`, e.g. `Dates.dayofweek(dt)`; alternatively, you could call `using Dates` to bring all exported functions into `Main` to be used without the `Dates.` prefix.
#
@doc """Construct a DateTime type by parts. Arguments must be convertible to `Int64`.
""" DateTime(y, [m, d, h, mi, s, ms]) -> DateTime
@doc """Constuct a DateTime type by `Period` type parts. Arguments may be in any order. DateTime parts not provided will default to the value of `Dates.default(period)`.
""" DateTime(periods::Period...) -> DateTime
@doc """Create a DateTime through the adjuster API. The starting point will be constructed from the provided `y, m, d...` arguments, and will be adjusted until `f::Function` returns true. The step size in adjusting can be provided manually through the `step` keyword. If `negate=true`, then the adjusting will stop when `f::Function` returns false instead of true. `limit` provides a limit to the max number of iterations the adjustment API will pursue before throwing an error (in the case that `f::Function` is never satisfied).
""" DateTime(f::Function, y[, m, d, h, mi, s]; step=Day(1), negate=false, limit=10000) -> DateTime
@doc """Converts a `Date` type to a `DateTime`. The hour, minute, second, and millisecond parts of the new `DateTime` are assumed to be zero.
""" DateTime(dt::Date) -> DateTime
@doc """Construct a DateTime type by parsing the `dt` date string following the pattern given in the `format` string. The following codes can be used for constructing format strings:
| Code | Matches | Comment |
|------------|-----------|--------------------------------------------------------------|
| `y` | 1996, 96 | Returns year of 1996, 0096 |
| `m` | 1, 01 | Matches 1 or 2-digit months |
| `u` | Jan | Matches abbreviated months according to the `locale` keyword |
| `U` | January | Matches full month names according to the `locale` keyword |
| `d` | 1, 01 | Matches 1 or 2-digit days |
| `H` | 00 | Matches hours |
| `M` | 00 | Matches minutes |
| `S` | 00 | Matches seconds |
| `s` | .500 | Matches milliseconds |
| `e` | Mon, Tues | Matches abbreviated days of the week |
| `E` | Monday | Matches full name days of the week |
| `yyyymmdd` | 19960101 | Matches fixed-width year, month, and day |
All characters not listed above are treated as delimiters between date and time slots. So a `dt` string of "1996-01-15T00:00:00.0" would have a `format` string like "y-m-dTH:M:S.s".
""" DateTime(dt::AbstractString, format::AbstractString; locale="english") -> DateTime
@doc """Construct a `Date` type by parts. Arguments must be convertible to `Int64`.
""" Date(y, [m, d]) -> Date
@doc """Constuct a Date type by `Period` type parts. Arguments may be in any order. Date parts not provided will default to the value of `Dates.default(period)`.
""" Date(period::Period...) -> Date
@doc """Create a Date through the adjuster API. The starting point will be constructed from the provided `y, m` arguments, and will be adjusted until `f::Function` returns true. The step size in adjusting can be provided manually through the `step` keyword. If `negate=true`, then the adjusting will stop when `f::Function` returns false instead of true. `limit` provides a limit to the max number of iterations the adjustment API will pursue before throwing an error (given that `f::Function` is never satisfied).
""" Date(f::Function, y[, m]; step=Day(1), negate=false, limit=10000) -> Date
@doc """Converts a `DateTime` type to a `Date`. The hour, minute, second, and millisecond parts of the `DateTime` are truncated, so only the year, month and day parts are used in construction.
""" Date(dt::DateTime) -> Date
@doc """Construct a Date type by parsing a `dt` date string following the pattern given in the `format` string. Follows the same conventions as `DateTime` above.
""" Date(dt::AbstractString, format::AbstractString; locale="english") -> Date
@doc """Returns a DateTime corresponding to the user's system time including the system timezone locale.
""" now() -> DateTime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment