Skip to content

Commit 85c9c66

Browse files
authored
Merge pull request #34424 from JuliaLang/kf/docrollup
Roll up stalled out doc PRs
2 parents d759b5b + 06c4a88 commit 85c9c66

File tree

8 files changed

+90
-75
lines changed

8 files changed

+90
-75
lines changed

doc/src/manual/calling-c-and-fortran-code.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ julia> typeof(ans)
7575
Int32
7676
```
7777

78-
`clock` takes no arguments and returns an [`Int32`](@ref). One common gotcha is that a 1-tuple of
78+
`clock` takes no arguments and returns an [`Int32`](@ref). One common mistake is forgetting that a 1-tuple of
7979
argument types must be written with a trailing comma. For example, to call the `getenv` function
8080
to get a pointer to the value of an environment variable, one makes a call like this:
8181

@@ -87,7 +87,7 @@ julia> unsafe_string(path)
8787
"/bin/bash"
8888
```
8989

90-
Note that the argument type tuple must be written as `(Cstring,)`, rather than `(Cstring)`. This
90+
Note that the argument type tuple must be written as `(Cstring,)`, not `(Cstring)`. This
9191
is because `(Cstring)` is just the expression `Cstring` surrounded by parentheses, rather than
9292
a 1-tuple containing `Cstring`:
9393

@@ -101,7 +101,7 @@ julia> (Cstring,)
101101

102102
In practice, especially when providing reusable functionality, one generally wraps [`ccall`](@ref)
103103
uses in Julia functions that set up arguments and then check for errors in whatever manner the
104-
C or Fortran function indicates them, propagating to the Julia caller as exceptions. This is especially
104+
C or Fortran function specifies. And if an error occurs it is thrown as a normal Julia exception. This is especially
105105
important since C and Fortran APIs are notoriously inconsistent about how they indicate error
106106
conditions. For example, the `getenv` C library function is wrapped in the following Julia function,
107107
which is a simplified version of the actual definition from [`env.jl`](https://github.com/JuliaLang/julia/blob/master/base/env.jl):
@@ -146,11 +146,11 @@ function gethostname()
146146
end
147147
```
148148

149-
This example first allocates an array of bytes, then calls the C library function `gethostname`
150-
to fill the array in with the hostname, takes a pointer to the hostname buffer, and converts the
149+
This example first allocates an array of bytes. It then calls the C library function `gethostname`
150+
to populate the array with the hostname. Finally, it takes a pointer to the hostname buffer, and converts the
151151
pointer to a Julia string, assuming that it is a NUL-terminated C string. It is common for C libraries
152152
to use this pattern of requiring the caller to allocate memory to be passed to the callee and
153-
filled in. Allocation of memory from Julia like this is generally accomplished by creating an
153+
populated. Allocation of memory from Julia like this is generally accomplished by creating an
154154
uninitialized array and passing a pointer to its data to the C function. This is why we don't
155155
use the `Cstring` type here: as the array is uninitialized, it could contain NUL bytes. Converting
156156
to a `Cstring` as part of the [`ccall`](@ref) checks for contained NUL bytes and could therefore
@@ -177,7 +177,7 @@ Julia function. The arguments to [`@cfunction`](@ref) are:
177177
178178
!!! note
179179
Currently, only the platform-default C calling convention is supported. This means that
180-
`@cfunction`-generated pointers cannot be used in calls where WINAPI expects `stdcall`
180+
`@cfunction`-generated pointers cannot be used in calls where WINAPI expects a `stdcall`
181181
function on 32-bit Windows, but can be used on WIN64 (where `stdcall` is unified with the
182182
C calling convention).
183183
@@ -193,8 +193,8 @@ each. `compare` is a callback function which takes pointers to two elements `a`
193193
an integer less/greater than zero if `a` should appear before/after `b` (or zero if any order
194194
is permitted).
195195

196-
Now, suppose that we have a 1d array `A` of values in Julia that we want to sort
197-
using the `qsort` function (rather than Julia's built-in `sort` function). Before we worry about
196+
Now, suppose that we have a 1-d array `A` of values in Julia that we want to sort
197+
using the `qsort` function (rather than Julia's built-in `sort` function). Before we consider
198198
calling `qsort` and passing arguments, we need to write a comparison function:
199199

200200
```jldoctest mycompare
@@ -238,7 +238,7 @@ julia> A
238238
4.4
239239
```
240240

241-
As can be seen, `A` is changed to the sorted array `[-2.7, 1.3, 3.1, 4.4]`. Note that Julia
241+
As the example shows, the original Julia array `A` has now been sorted: `[-2.7, 1.3, 3.1, 4.4]`. Note that Julia
242242
[takes care of converting the array to a `Ptr{Cdouble}`](@ref automatic-type-conversion)), computing
243243
the size of the element type in bytes, and so on.
244244

@@ -265,7 +265,7 @@ to the specified type. For example, the following call:
265265
ccall((:foo, "libfoo"), Cvoid, (Int32, Float64), x, y)
266266
```
267267

268-
will behave as if the following were written:
268+
will behave as if it were written like this:
269269

270270
```julia
271271
ccall((:foo, "libfoo"), Cvoid, (Int32, Float64),
@@ -349,7 +349,7 @@ same:
349349

350350
On all systems we currently support, basic C/C++ value types may be translated to Julia types
351351
as follows. Every C type also has a corresponding Julia type with the same name, prefixed by C.
352-
This can help for writing portable code (and remembering that an `int` in C is not the same as
352+
This can help when writing portable code (and remembering that an `int` in C is not the same as
353353
an `Int` in Julia).
354354

355355

@@ -410,7 +410,7 @@ checks and is only meant to improve readability of the call.
410410

411411
!!! warning
412412
For string arguments (`char*`) the Julia type should be `Cstring` (if NUL- terminated data is
413-
expected) or either `Ptr{Cchar}` or `Ptr{UInt8}` otherwise (these two pointer types have the same
413+
expected), or either `Ptr{Cchar}` or `Ptr{UInt8}` otherwise (these two pointer types have the same
414414
effect), as described above, not `String`. Similarly, for array arguments (`T[]` or `T*`), the
415415
Julia type should again be `Ptr{T}`, not `Vector{T}`.
416416

@@ -419,19 +419,19 @@ checks and is only meant to improve readability of the call.
419419
`wint_t`) on all platforms.
420420

421421
!!! warning
422-
A return type of `Union{}` means the function will not return i.e. C++11 `[[noreturn]]` or C11
422+
A return type of `Union{}` means the function will not return, i.e., C++11 `[[noreturn]]` or C11
423423
`_Noreturn` (e.g. `jl_throw` or `longjmp`). Do not use this for functions that return no value
424424
(`void`) but do return, use `Cvoid` instead.
425425

426426
!!! note
427427
For `wchar_t*` arguments, the Julia type should be [`Cwstring`](@ref) (if the C routine expects a
428-
NUL-terminated string) or `Ptr{Cwchar_t}` otherwise. Note also that UTF-8 string data in Julia is
428+
NUL-terminated string), or `Ptr{Cwchar_t}` otherwise. Note also that UTF-8 string data in Julia is
429429
internally NUL-terminated, so it can be passed to C functions expecting NUL-terminated data without
430430
making a copy (but using the `Cwstring` type will cause an error to be thrown if the string itself
431431
contains NUL characters).
432432

433433
!!! note
434-
C functions that take an argument of the type `char**` can be called by using a `Ptr{Ptr{UInt8}}`
434+
C functions that take an argument of type `char**` can be called by using a `Ptr{Ptr{UInt8}}`
435435
type within Julia. For example, C functions of the form:
436436

437437
```c
@@ -450,7 +450,7 @@ checks and is only meant to improve readability of the call.
450450
are provided as *hidden arguments*. Type and position of these arguments in the list are compiler
451451
specific, where compiler vendors usually default to using `Csize_t` as type and append the hidden
452452
arguments at the end of the argument list. While this behaviour is fixed for some compilers (GNU),
453-
others *optionally* permit placing hidden arguments directly after the character argument (Intel,PGI).
453+
others *optionally* permit placing hidden arguments directly after the character argument (Intel, PGI).
454454
For example, Fortran subroutines of the form
455455

456456
```fortran
@@ -479,7 +479,7 @@ checks and is only meant to improve readability of the call.
479479

480480
### Struct Type Correspondences
481481

482-
Composite types, aka `struct` in C or `TYPE` in Fortran90 (or `STRUCTURE` / `RECORD` in some variants
482+
Composite types such as `struct` in C or `TYPE` in Fortran90 (or `STRUCTURE` / `RECORD` in some variants
483483
of F77), can be mirrored in Julia by creating a `struct` definition with the same
484484
field layout.
485485

@@ -855,12 +855,12 @@ When passing data to a [`ccall`](@ref), it is best to avoid using the [`pointer`
855855
Instead define a convert method and pass the variables directly to the [`ccall`](@ref). [`ccall`](@ref)
856856
automatically arranges that all of its arguments will be preserved from garbage collection until
857857
the call returns. If a C API will store a reference to memory allocated by Julia, after the [`ccall`](@ref)
858-
returns, you must arrange that the object remains visible to the garbage collector. The suggested
859-
way to handle this is to make a global variable of type `Array{Ref,1}` to hold these values, until
858+
returns, you must ensure that the object remains visible to the garbage collector. The suggested
859+
way to do this is to make a global variable of type `Array{Ref,1}` to hold these values, until
860860
the C library notifies you that it is finished with them.
861861

862862
Whenever you have created a pointer to Julia data, you must ensure the original data exists until
863-
you are done with using the pointer. Many methods in Julia such as [`unsafe_load`](@ref) and
863+
you have finished using the pointer. Many methods in Julia such as [`unsafe_load`](@ref) and
864864
[`String`](@ref) make copies of data instead of taking ownership of the buffer, so that it is
865865
safe to free (or alter) the original data without affecting Julia. A notable exception is
866866
[`unsafe_wrap`](@ref) which, for performance reasons, shares (or can be told to take ownership of) the
@@ -888,7 +888,8 @@ when wrapping libraries that contain many similar functions.
888888
A similar example can be constructed for [`@cfunction`](@ref).
889889

890890
However, doing this will also be very slow and leak memory, so you should usually avoid this and instead keep
891-
reading. The next section discusses how to use indirect calls to efficiently accomplish a similar effect.
891+
reading.
892+
The next section discusses how to use indirect calls to efficiently achieve a similar effect.
892893

893894
## Indirect Calls
894895

doc/src/manual/conversion-and-promotion.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ ERROR: MethodError: Cannot `convert` an object of type String to an object of ty
9393
```
9494

9595
Some languages consider parsing strings as numbers or formatting numbers as strings to be conversions
96-
(many dynamic languages will even perform conversion for you automatically), however Julia does
97-
not: even though some strings can be parsed as numbers, most strings are not valid representations
96+
(many dynamic languages will even perform conversion for you automatically). This is not the case in Julia.
97+
Even though some strings can be parsed as numbers, most strings are not valid representations
9898
of numbers, and only a very limited subset of them are. Therefore in Julia the dedicated [`parse`](@ref)
9999
function must be used to perform this operation, making it more explicit.
100100

doc/src/manual/documentation.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
Julia enables package developers and users to document functions, types and other objects easily
44
via a built-in documentation system since Julia 0.4.
55

6-
The basic syntax is simple: any string appearing at the top-level right before an object
7-
(function, macro, type or instance) will be interpreted as documenting it (these are called *docstrings*).
8-
Note that no blank lines or comments may intervene between a docstring and the documented object.
9-
Here is a basic example:
6+
The basic syntax is simple: any string appearing at the toplevel right before an object
7+
(function, macro, type or instance) will be interpreted as documenting it (these are called
8+
*docstrings*). Note that no blank lines or comments may intervene between a docstring and
9+
the documented object. Here is a basic example:
1010

1111
```julia
1212
"Tell whether there are too foo items in the array."
@@ -187,16 +187,16 @@ As in the example above, we recommend following some simple conventions when wri
187187
f(x, y) = ...
188188
```
189189

190-
This makes it more clear where docstrings start and end.
190+
This makes it clearer where docstrings start and end.
191191
9. Respect the line length limit used in the surrounding code.
192192

193193
Docstrings are edited using the same tools as code. Therefore, the same conventions should apply.
194-
It is advised to add line breaks after 92 characters.
194+
It is recommended that lines are at most 92 characters wide.
195195
6. Provide information allowing custom types to implement the function in an
196-
`# Implementation` section. These implementation details intended for developers
197-
rather than users, explaining e.g. which functions should be overridden and which functions
198-
automatically use appropriate fallbacks, are better kept separate from the main description of
199-
the function's behavior.
196+
`# Implementation` section. These implementation details are intended for developers
197+
rather than users, explaining e.g. which functions should be overridden and which
198+
functions automatically use appropriate fallbacks. Such details are best kept separate
199+
from the main description of the function's behavior.
200200

201201
## Accessing Documentation
202202

@@ -209,8 +209,9 @@ by typing `?` followed by the name of a function or macro, and pressing `Enter`.
209209
?r""
210210
```
211211

212-
will bring up docs for the relevant function, macro or string macro respectively. In [Juno](http://junolab.org)
213-
using `Ctrl-J, Ctrl-D` will bring up documentation for the object under the cursor.
212+
will show documentation for the relevant function, macro or string macro respectively. In
213+
[Juno](http://junolab.org) using `Ctrl-J, Ctrl-D` will show the documentation for the object
214+
under the cursor.
214215

215216
## Functions & Methods
216217

@@ -334,7 +335,9 @@ y = MyType("y")
334335

335336
## Syntax Guide
336337

337-
A comprehensive overview of all documentable Julia syntax.
338+
This guide provides a comprehensive overview of how to attach documentation to all Julia syntax
339+
constructs for which providing documentation is possible.
340+
338341
In the following examples `"..."` is used to illustrate an arbitrary docstring.
339342

340343
### `$` and `\` characters
@@ -520,8 +523,8 @@ the referenced value itself.
520523
sym
521524
```
522525

523-
Adds docstring `"..."` to the value associated with `sym`. Users should prefer documenting `sym`
524-
at its definition.
526+
Adds docstring `"..."` to the value associated with `sym`. However, it is preferred that
527+
`sym` is documented where it is defined.
525528

526529
### Multiple Objects
527530

@@ -551,9 +554,9 @@ two functions are related, such as non-mutating and mutating versions `f` and `f
551554
@m expression
552555
```
553556

554-
Adds docstring `"..."` to expression generated by expanding `@m expression`. This allows for expressions
555-
decorated with `@inline`, `@noinline`, `@generated`, or any other macro to be documented in the
556-
same way as undecorated expressions.
557+
Adds docstring `"..."` to the expression generated by expanding `@m expression`. This allows
558+
for expressions decorated with `@inline`, `@noinline`, `@generated`, or any other macro to
559+
be documented in the same way as undecorated expressions.
557560

558561
Macro authors should take note that only macros that generate a single expression will automatically
559562
support docstrings. If a macro returns a block containing multiple subexpressions then the subexpression

doc/src/manual/environment-variables.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ determined by evaluating `ENV["JULIA_EDITOR"]`.
1111

1212
The environment variables that Julia uses generally start with `JULIA`. If
1313
[`InteractiveUtils.versioninfo`](@ref) is called with the keyword `verbose=true`, then the
14-
output will list defined environment variables relevant for Julia, including
15-
those for which `JULIA` appears in the name.
14+
output will list any defined environment variables relevant for Julia,
15+
including those which include `JULIA` in their names.
1616

1717
!!! note
1818

@@ -148,10 +148,10 @@ $(DEPOT_PATH[1])/logs/repl_history.jl
148148

149149
### `JULIA_PKGRESOLVE_ACCURACY`
150150

151-
A positive `Int` that determines how much time the max-sum subroutine
152-
`MaxSum.maxsum()` of the package dependency resolver
153-
will devote to attempting satisfying constraints before giving up: this value is
154-
by default `1`, and larger values correspond to larger amounts of time.
151+
A positive `Int` that determines how much time the package dependency resolver's max-sum
152+
subroutine `MaxSum.maxsum()` will devote to attempting to satisfy constraints before giving
153+
up. This value's default is `1`, with higher values corresponding to longer amounts of
154+
time.
155155

156156
Suppose the value of `$JULIA_PKGRESOLVE_ACCURACY` is `n`. Then
157157

doc/src/manual/faq.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ When calling `change_value!(x)` in the above example, `y` is a newly created var
141141
to the value of `x`, i.e. `10`; then `y` is rebound to the constant `17`, while the variable
142142
`x` of the outer scope is left untouched.
143143

144-
But here is a thing you should pay attention to: suppose `x` is bound to an object of type `Array`
144+
However, if `x` is bound to an object of type `Array`
145145
(or any other *mutable* type). From within the function, you cannot "unbind" `x` from this Array,
146-
but you can change its content. For example:
146+
but you *can* change its content. For example:
147147

148148
```jldoctest
149149
julia> x = [1,2,3]
@@ -334,8 +334,8 @@ unstable (generic function with 1 method)
334334

335335
It returns either an `Int` or a [`Float64`](@ref) depending on the value of its argument.
336336
Since Julia can't predict the return type of this function at compile-time, any computation
337-
that uses it will have to guard against both types possibly occurring, making generation of
338-
fast machine code difficult.
337+
that uses it must be able to cope with values of both types, which makes it hard to produce
338+
fast machine code.
339339

340340
### [Why does Julia give a `DomainError` for certain seemingly-sensible operations?](@id faq-domain-errors)
341341

@@ -770,8 +770,9 @@ generate efficient code when working with `Union{T, Nothing}` arguments or field
770770
To represent missing data in the statistical sense (`NA` in R or `NULL` in SQL), use the
771771
[`missing`](@ref) object. See the [`Missing Values`](@ref missing) section for more details.
772772

773-
The empty tuple (`()`) is another form of nothingness. But, it should not really be thought of
774-
as nothing but rather a tuple of zero values.
773+
In some languages, the empty tuple (`()`) is considered the canonical
774+
form of nothingness. However, in julia it is best thought of as just
775+
a regular tuple that happens to contain zero values.
775776

776777
The empty (or "bottom") type, written as `Union{}` (an empty union type), is a type with
777778
no values and no subtypes (except itself). You will generally not need to use this type.

0 commit comments

Comments
 (0)