Skip to content

Commit

Permalink
doc/manual: squeeze out unnecessary ':\n\n' tokens before code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
nolta committed Sep 19, 2012
1 parent 79f45cd commit c3e269d
Show file tree
Hide file tree
Showing 18 changed files with 372 additions and 1,116 deletions.
28 changes: 7 additions & 21 deletions doc/manual/arrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ Comprehensions

Comprehensions provide a general and powerful way to construct arrays.
Comprehension syntax is similar to set construction notation in
mathematics:

::
mathematics::

A = [ F(x,y,...) for x=rx, y=ry, ... ]

Expand Down Expand Up @@ -129,9 +127,7 @@ variables.
Indexing
--------

The general syntax for indexing into an n-dimensional array A is:

::
The general syntax for indexing into an n-dimensional array A is::

X = A[I_1, I_2, ..., I_n]

Expand All @@ -146,15 +142,11 @@ The result X has the dimensions
``(i_1, i_2, ..., i_n)`` of X containing the value
``A[I_1[i_1], I_2[i_2], ..., I_n[i_n]]``.

Indexing syntax is equivalent to a call to ``ref``:

::
Indexing syntax is equivalent to a call to ``ref``::

X = ref(A, I_1, I_2, ..., I_n)

Example:

::
Example::

julia> x = reshape(1:16, 4, 4)
4x4 Int64 Array
Expand All @@ -171,9 +163,7 @@ Example:
Assignment
----------

The general syntax for assigning values in an n-dimensional array A is:

::
The general syntax for assigning values in an n-dimensional array A is::

A[I_1, I_2, ..., I_n] = X

Expand All @@ -187,15 +177,11 @@ The size of X should be ``(size(I_1), size(I_2), ..., size(I_n))``, and
the value in location ``(i_1, i_2, ..., i_n)`` of A is overwritten with
the value ``X[I_1[i_1], I_2[i_2], ..., I_n[i_n]]``.

Index assignment syntax is equivalent to a call to ``assign``:

::
Index assignment syntax is equivalent to a call to ``assign``::

A = assign(A, X, I_1, I_2, ..., I_n)

Example:

::
Example::

julia> x = reshape(1:9, 3, 3)
3x3 Int64 Array
Expand Down
48 changes: 12 additions & 36 deletions doc/manual/calling-c-and-fortran-code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,14 @@ access to the functionality of the POSIX ``dlopen(3)`` call: it locates
a shared library binary and loads it into the process' memory allowing
the program to access functions and variables contained in the library.
The following call loads the standard C library, and stores the
resulting handle in a Julia variable called ``libc``:

::
resulting handle in a Julia variable called ``libc``::

libc = dlopen("libc")

Once a library has been loaded, functions can be looked up by name using
the ``dlsym`` function, which exposes the functionality of the POSIX
``dlsym(3)`` call. This returns a handle to the ``clock`` function from
the standard C library:

::
the standard C library::

libc_clock = dlsym(libc, :clock)

Expand All @@ -62,9 +58,7 @@ library function. Inputs to ``ccall`` are as follows:
passed to the function.

As a complete but simple example, the following calls the ``clock``
function from the standard C library:

::
function from the standard C library::

julia> t = ccall(dlsym(libc, :clock), Int32, ())
5380445
Expand All @@ -75,9 +69,7 @@ function from the standard C library:
``clock`` takes no arguments and returns an ``Int32``. One common gotcha
is that a 1-tuple must be written with with a trailing comma. For
example, to call the ``getenv`` function to get a pointer to the value
of an environment variable, one makes a call like this:

::
of an environment variable, one makes a call like this::

julia> path = ccall(dlsym(libc, :getenv), Ptr{Uint8}, (Ptr{Uint8},), "SHELL")
Ptr{Uint8} @0x00007fff5fbfd670
Expand All @@ -87,9 +79,7 @@ of an environment variable, one makes a call like this:

Note that the argument type tuple must be written as ``(Ptr{Uint8},)``,
rather than ``(Ptr{Uint8})``. This is because ``(Ptr{Uint8})`` is just
``Ptr{Uint8}``, rather than a 1-tuple containing ``Ptr{Uint8}``:

::
``Ptr{Uint8}``, rather than a 1-tuple containing ``Ptr{Uint8}``::

julia> (Ptr{Uint8})
Ptr{Uint8}
Expand All @@ -105,9 +95,7 @@ especially important since C and Fortran APIs are notoriously
inconsistent about how they indicate error conditions. For example, the
``getenv`` C library function is wrapped in the following Julia function
in
`env.jl <https://github.com/JuliaLang/julia/blob/master/base/env.jl>`_:

::
`env.jl <https://github.com/JuliaLang/julia/blob/master/base/env.jl>`_::

function getenv(var::String)
val = ccall(dlsym(libc, :getenv),
Expand All @@ -122,9 +110,7 @@ The C ``getenv`` function indicates an error by returning ``NULL``, but
other standard C functions indicate errors in various different ways,
including by returning -1, 0, 1 and other special values. This wrapper
throws an exception clearly indicating the problem if the caller tries
to get a non-existent environment variable:

::
to get a non-existent environment variable::

julia> getenv("SHELL")
"/bin/zsh"
Expand All @@ -133,9 +119,7 @@ to get a non-existent environment variable:
getenv: undefined variable: FOOBAR

Here is a slightly more complex example that discovers the local
machine's hostname:

::
machine's hostname::

function gethostname()
hostname = Array(Uint8, 128)
Expand Down Expand Up @@ -195,16 +179,12 @@ Mapping C Types to Julia
------------------------

Julia automatically inserts calls to the ``convert`` function to convert
each argument to the specified type. For example, the following call:

::
each argument to the specified type. For example, the following call::

ccall(dlsym(libfoo, :foo), Void, (Int32, Float64),
x, y)

will behave as if the following were written:

::
will behave as if the following were written::

ccall(dlsym(libfoo, :foo), Void, (Int32, Float64),
convert(Int32, x), convert(Float64, y))
Expand Down Expand Up @@ -265,15 +245,11 @@ systems we currently support (UNIX), it is a 32 bits.

C functions that take an arguments of the type ``char**`` can be called
by using a ``Ptr{Ptr{Uint8}}`` type within Julia. For example, C
functions of the form:

::
functions of the form::

int main(int argc, char **argv);

can be called via the following Julia code:

::
can be called via the following Julia code::

argv = [ "a.out", "arg1", "arg2" ]
ccall(:main, Int32, (Int32, Ptr{Ptr{Uint8}}), length(argv), argv)
Expand Down
76 changes: 19 additions & 57 deletions doc/manual/complex-and-rational-numbers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@ index variable name. Since Julia allows numeric literals to be
:ref:`juxtaposed with identifiers as
coefficients <man-numeric-literal-coefficients>`,
this binding suffices to provide convenient syntax for complex numbers,
similar to the traditional mathematical notation:

::
similar to the traditional mathematical notation::

julia> 1 + 2im
1 + 2im

You can perform all the standard arithmetic operations with complex
numbers:

::
numbers::

julia> (1 + 2im)*(2 - 3im)
8 + 1im
Expand Down Expand Up @@ -66,9 +62,7 @@ numbers:
0.20689655172413793 + 0.5172413793103449im

The promotion mechanism ensures that combinations of operands of
different types just work:

::
different types just work::

julia> 2(1 - 1im)
2 - 2im
Expand Down Expand Up @@ -100,9 +94,7 @@ different types just work:
Note that ``3/4im == 3/(4*im) == -(3/4*im)``, since a literal
coefficient binds more tightly than division.

Standard functions to manipulate complex values are provided:

::
Standard functions to manipulate complex values are provided::

julia> real(1 + 2im)
1
Expand All @@ -123,9 +115,7 @@ As is common, the absolute value of a complex number is its distance
from zero. The ``abs2`` function gives the square of the absolute value,
and is of particular use for complex numbers, where it avoids taking a
square root. The full gamut of other mathematical functions are also
defined for complex numbers:

::
defined for complex numbers::

julia> sqrt(im)
0.7071067811865476 + 0.7071067811865475im
Expand All @@ -145,9 +135,7 @@ defined for complex numbers:
Note that mathematical functions always return real values when applied
to real numbers and complex values when applied to complex numbers.
Thus, ``sqrt``, for example, behaves differently when applied to ``-1``
versus ``-1 + 0im`` even though ``-1 == -1 + 0im``:

::
versus ``-1 + 0im`` even though ``-1 == -1 + 0im``::

julia> sqrt(-1)
NaN
Expand All @@ -157,27 +145,21 @@ versus ``-1 + 0im`` even though ``-1 == -1 + 0im``:

If you need to construct a complex number using variables, the literal
numeric coefficient notation will not work, although explicitly writing
the multiplication operation will:

::
the multiplication operation will::

julia> a = 1; b = 2; a + b*im
1 + 2im

Constructing complex numbers from variable values like this, however, is
not recommended. Use the ``complex`` function to construct a complex
value directly from its real and imaginary parts instead:

::
value directly from its real and imaginary parts instead::

julia> complex(a,b)
1 + 2im

This construction is preferred for variable arguments because it is more
efficient than the multiplication and addition construct, but also
because certain values of ``b`` can yield unexpected results:

::
because certain values of ``b`` can yield unexpected results::

julia> 1 + Inf*im
NaN + Inf*im
Expand All @@ -188,9 +170,7 @@ because certain values of ``b`` can yield unexpected results:
These results are natural and unavoidable consequences of the
interaction between the rules of complex multiplication and IEEE-754
floating-point arithmetic. Using the ``complex`` function to construct
complex values directly, however, gives more intuitive results:

::
complex values directly, however, gives more intuitive results::

julia> complex(1,Inf)
complex(1.0,Inf)
Expand All @@ -208,17 +188,13 @@ Rational Numbers
----------------

Julia has a rational number type to represent exact ratios of integers.
Rationals are constructed using the ``//`` operator:

::
Rationals are constructed using the ``//`` operator::

julia> 2//3
2//3

If the numerator and denominator of a rational have common factors, they
are reduced to lowest terms such that the denominator is non-negative:

::
are reduced to lowest terms such that the denominator is non-negative::

julia> 6//9
2//3
Expand All @@ -235,9 +211,7 @@ are reduced to lowest terms such that the denominator is non-negative:
This normalized form for a ratio of integers is unique, so equality of
rational values can be tested by checking for equality of the numerator
and denominator. The standardized numerator and denominator of a
rational value can be extracted using the ``num`` and ``den`` functions:

::
rational value can be extracted using the ``num`` and ``den`` functions::

julia> num(2//3)
2
Expand All @@ -247,9 +221,7 @@ rational value can be extracted using the ``num`` and ``den`` functions:

Direct comparison of the numerator and denominator is generally not
necessary, since the standard arithmetic and comparison operations are
defined for rational values:

::
defined for rational values::

julia> 2//3 == 6//9
true
Expand All @@ -275,25 +247,19 @@ defined for rational values:
julia> 6//5 / 10//7
21//25

Rationals can be easily converted to floating-point numbers:

::
Rationals can be easily converted to floating-point numbers::

julia> float(3//4)
0.75

Conversion from rational to floating-point respects the following
identity for any integral values of ``a`` and ``b``, with the exception
of the case ``a == 0`` and ``b == 0``:

::
of the case ``a == 0`` and ``b == 0``::

julia> isequal(float(a//b), a/b)
true

Constructing infinite rational values is acceptable:

::
Constructing infinite rational values is acceptable::

julia> 5//0
Inf
Expand All @@ -304,17 +270,13 @@ Constructing infinite rational values is acceptable:
julia> typeof(ans)
Rational{Int64}

Trying to construct a NaN rational value, however, is not:

::
Trying to construct a NaN rational value, however, is not::

julia> 0//0
invalid rational: 0//0

As usual, the promotion system makes interactions with other numeric
types effortless:

::
types effortless::

julia> 3//5 + 1
8//5
Expand Down
Loading

0 comments on commit c3e269d

Please sign in to comment.