Skip to content
This repository has been archived by the owner on Mar 15, 2019. It is now read-only.

Commit

Permalink
7.12 e35b83b18e
Browse files Browse the repository at this point in the history
  • Loading branch information
wlbksy committed Jul 12, 2014
1 parent 5abc088 commit 50908bf
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 16 deletions.
15 changes: 10 additions & 5 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
import sys, os, re

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down Expand Up @@ -56,10 +56,15 @@
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.3'
# The full version, including alpha/beta/rc tags.
release = '0.3.0-dev'
try:

This comment has been minimized.

Copy link
@GaZ3ll3

GaZ3ll3 Jul 13, 2014

Contributor

虽然不是太重要,但是我们没有上级目录的VERSION, 我建议把JuliaLang的VERSION拖到同级目录,把那个

with open("../VERSION") as f

改了

with open("./VERSION") as f

不然pdf上会有个X.Y.Z-unknown...略蛋疼。

This comment has been minimized.

Copy link
@wlbksy

wlbksy via email Jul 15, 2014

Author Member
# The full version, including alpha/beta/rc tags.
with open("../VERSION") as f:
release = f.read().rstrip()
# The short X.Y version.
version = '.'.join(re.split('[.-]', release)[:2])
except:
release = 'X.Y.Z-unknown'
version = 'X.Y'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
12 changes: 6 additions & 6 deletions manual/constructors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@

type T2
x::Int64
T2(x::Int64) = new(x)
T2(x) = new(x)
end

julia> T1(1)
Expand All @@ -104,10 +104,10 @@
T2(1)

julia> T1(1.0)
no method T1(Float64,)
T1(1)

julia> T2(1.0)
no method T2(Float64,)
T2(1)

内部构造方法能不写就不写。提供默认值之类的事儿,应该写成外部构造方法,由它们调用内部构造方法。

Expand Down Expand Up @@ -229,21 +229,21 @@
Point{Int64}(1,2)

julia> Point{Int64}(1.0,2.5)
ERROR: no method Point{Int64}(Float64, Float64)
ERROR: InexactError()

julia> Point{Float64}(1.0,2.5)
Point{Float64}(1.0,2.5)

julia> Point{Float64}(1,2)
ERROR: no method Point{Float64}(Int64, Int64)
Point{Float64}(1.0,2.0)

上面的参数化构造方法等价于下面的声明: ::

type Point{T<:Real}
x::T
y::T

Point(x::T, y::T) = new(x,y)
Point(x,y) = new(x,y)
end

Point{T<:Real}(x::T, y::T) = Point{T}(x,y)
Expand Down
3 changes: 3 additions & 0 deletions manual/control-flow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ It will be evaluated and returned depending on the preceding conditionals:
(2,3)
(2,4)

A ``break`` statement inside such a loop exits the entire nest of loops,

This comment has been minimized.

Copy link
@GaZ3ll3

GaZ3ll3 Jul 12, 2014

Contributor

try:

for i = 1:10, j = 1:3
    if j == 1
        break
    end
end

如果能跳出双重循环,应该第一个之后就停下来。好像不是这样的。是我的julia版本太低?

 Version 0.3.0-prerelease+3921 (2014-06-28 02:01 UTC)

This comment has been minimized.

Copy link
@GaZ3ll3

GaZ3ll3 Jul 12, 2014

Contributor

OK, 我找到了。
JuliaLang/julia#5154
JuliaLang/julia#7430
这是9天前的合并的。我没及时更新。最好加个标注比较好。

This comment has been minimized.

Copy link
@wlbksy

wlbksy Jul 13, 2014

Author Member

我很久没看这个列表了。这个更新是我单独跟踪的julia 的文档,一并更新到了我提交时的julia文档的状态。

not just the inner one.

.. _man-exception-handling:

异常处理
Expand Down
36 changes: 36 additions & 0 deletions manual/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,42 @@ But here is a thing you should pay attention to: suppose ``x`` is bound to an Ar

Here we created a function ``change_array!()``, that assigns ``5`` to the first element of the Array. We passed ``x`` (which was previously bound to an Array) to the function. Notice that, after the function call, ``x`` is still bound to the same Array, but the content of that Array changed.


Can I use ``using`` or ``import`` inside a function?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

No, you are not allowed to have a ``using`` or ``import`` statement inside
a function. If you want to import a module but only use its symbols
inside a specific function or set of functions, you have two options:

1. Use ``import``::

import Foo
function bar(...)
... refer to Foo symbols via Foo.baz ...
end


This loads the module Foo and defines a variable ``Foo`` that refers
to the module, but does not import any of the other symbols from the
module into the current namespace. You refer to the ``Foo`` symbols by
their qualified names ``Foo.bar`` etc.


2. Wrap your function in a module::

module Bar
export bar
using Foo
function bar(...)
... refer to Foo.baz as simply baz ....
end
end
using Bar

This imports all the symbols from Foo, but only inside the module Bar.


类型,类型声明和构造方法
------------------------

Expand Down
4 changes: 2 additions & 2 deletions manual/packages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ This creates the directory ``~/.julia/v0.3/FooBar``, initializes it as a git rep
src/FooBar.jl | 5 +++++
4 files changed, 44 insertions(+)

At the moment, the package manager knows about the MIT "Expat" License, indicated by ``"MIT"``, and the Simplified BSD License, indicated by ``"BSD"``.
If you want to use a different license, you can ask us to add it to the package generator, or just pick one of these two and then modify the ``~/.julia/v0.3/PACKAGE/LICENSE.md`` file after it has been generated.
At the moment, the package manager knows about the MIT "Expat" License, indicated by ``"MIT"``, the Simplified BSD License, indicated by ``"BSD"``, and version 2.0 of the Apache Software License, indicated by ``"ASL"``.
If you want to use a different license, you can ask us to add it to the package generator, or just pick one of these three and then modify the ``~/.julia/v0.3/PACKAGE/LICENSE.md`` file after it has been generated.

If you created a GitHub account and configured git to know about it, ``Pkg.generate`` will set an appropriate origin URL for you.
It will also automatically generate a ``.travis.yml`` file for using the `Travis <https://travis-ci.org>`_ automated testing service.
Expand Down
18 changes: 15 additions & 3 deletions manual/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,22 @@ not a declaration.
Foo("Hello, world.",23,1.5)

julia> typeof(foo)
Foo (constructor with 1 method)
Foo (constructor with 2 methods)

由于没有约束 ``bar`` 的类型,它可以被赋任意值; ``baz`` 则必须是 ``Int`` , ``qux`` 必须是 ``Float64`` 。参数必须与构造类型签名 ``(Any,Int,Float64)`` 相匹配:
When a type is applied like a function it is called a *constructor*.
Two constructors are generated automatically (these are called *default
constructors*). One accepts any arguments and calls ``convert`` to convert
them to the types of the fields, and the other accepts arguments that
match the field types exactly. The reason both of these are generated is
that this makes it easier to add new definitions without inadvertently
replacing a default constructor.

由于没有约束 ``bar`` 的类型,它可以被赋任意值;但是 ``baz`` 必须能被转换为 ``Int`` :

.. doctest::

julia> Foo((), 23.5, 1)
ERROR: no method Foo((), Float64, Int64)
ERROR: InexactError()

You may find a list of field names using the ``names`` function.

Expand Down Expand Up @@ -456,6 +464,10 @@ Julia 的类型系统支持参数化:类型可以引入参数,这样类型

julia> Point{Float64}(1.0,2.0,3.0)
ERROR: no method Point{Float64}(Float64, Float64, Float64)

Only one default constructor is generated for parametric types, since
overriding it is not possible. This constructor accepts any arguments
and converts them to the field types.

大多数情况下不需要提供 ``Point`` 对象的类型,它可由参数类型来提供信息。因此,可以不提供 ``T`` 的值:

Expand Down

0 comments on commit 50908bf

Please sign in to comment.