Skip to content

Commit 583275c

Browse files
committed
chap 21, 22
only 20 remains
1 parent 1970cb3 commit 583275c

File tree

3 files changed

+68
-67
lines changed

3 files changed

+68
-67
lines changed

19-sigils.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Sigil原意是“魔符,图章,印记”,
66
如古代西方魔幻传说中的巫女、魔法师画的封印或者召唤魔鬼的六芒星,
77
中国道士画的咒符,火影里面召唤守护兽的血印等。
88
在计算机编程领域,Sigil指的是在变量名称上做的标记,用来标明它的作用域或者类型什么的。
9-
例如某语言里面```$var```中的```$```就是这样的东西,表示其为全局变量。
9+
例如某语言里面`$var`中的`$`就是这样的东西,表示其为全局变量。
1010
不同的魔法印赋予变量不同的属性,这么看,翻译成“魔法印”还挺带感呢。
1111
本章(或者本文)所有的*sigil*都会翻译成“魔法印”或是采用英文原文。
1212

21-erlang-lib.md

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
============
33

44
Elixir对Erlang库提供了完善的交互。实际上,Elixir不是简单地去对Erlang库进行语言包装,
5-
而是直接连接Erlang的代码。本章将展示一些Elixir中没有,但是常用(常见+有用)的Erlang功能。
5+
而是直接连接Erlang的代码(因为同源,Elixir以特定语法来直接调用Erlang库函数)。
6+
本章将展示一些Elixir中没有,但是常用(常见+有用)的Erlang功能函数。
67

7-
随着对Elixir更加深入的学习和使用,你可能会更多地参考Erlang的
8+
>随着对Elixir更加深入的学习和使用,你可能会更多地阅读参考Erlang的
89
[标准库手册](http://erlang.org/doc/apps/stdlib/index.html)
910

1011
## 二进制串模块
@@ -82,18 +83,14 @@ iex> Base.encode16(:crypto.hash(:sha256, "Elixir"))
8283
end
8384
```
8485

85-
## The digraph module
86+
## 有向图模块
8687

87-
[The digraph module](http://erlang.org/doc/man/digraph.html) (as well as
88-
[digraph_utils](http://erlang.org/doc/man/digraph_utils.html)) contains
89-
functions for dealing with directed graphs built of vertices and edges.
90-
After constructing the graph, the algorithms in there will help finding
91-
for instance the shortest path between two vertices, or loops in the graph.
88+
[有向图模块](http://erlang.org/doc/man/digraph.html) (以及
89+
[有向图模块工具](http://erlang.org/doc/man/digraph_utils.html)
90+
包含了处理有向图(有丁点和边构成)的函数。
91+
创建了一个图实例之后,模块的算法即可帮助找寻顶点最短路径、图中的环等。
9292

93-
Note that the functions in `:digraph` alter the graph structure indirectly
94-
as a side effect, while returning the added vertices or edges.
95-
96-
Given three vertices, find the shortest path from the first to the last.
93+
给出三个顶点,找寻从第一个到最后一个顶点的最短路径:
9794

9895
```iex
9996
iex> digraph = :digraph.new()
@@ -105,19 +102,16 @@ iex> :digraph.get_short_path(digraph, v0, v2)
105102
[{0.0, 0.0}, {1.0, 0.0}, {1.0, 1.0}]
106103
```
107104

108-
## Erlang Term Storage
105+
## ETS(Erlang Term Storage):Erlang的“Term存储”机制
109106

110-
The modules [`ets`](http://erlang.org/doc/man/ets.html) and
111-
[`dets`](http://erlang.org/doc/man/dets.html) handle storage of large
112-
data structures in memory or on disk respectively.
107+
模块[`ets`](http://erlang.org/doc/man/ets.html)以及
108+
[`dets`](http://erlang.org/doc/man/dets.html)
109+
分别处理在内存中、磁盘上存储大型数据结构。
113110

114-
ETS lets you create a table containing tuples. By default, ETS tables
115-
are protected, which means only the owner process may write to the table
116-
but any other process can read. ETS has some functionality to be used as
117-
a simple database, a key-value store or as a cache mechanism.
111+
ETS创建一个表来存储元祖。默认情况下,ETS表是受保护的:只有owner进程才能写表,
112+
其它进程只可以读。ETS提供了一些功能,可被当做简单的数据库、键值存储或cache机制使用。
118113

119-
The functions in the `ets` module will modify the state of the table as a
120-
side-effect.
114+
作为副作用,`ets`模块中的函数会修改表的状态。
121115

122116
```iex
123117
iex> table = :ets.new(:ets_test, [])
@@ -131,11 +125,10 @@ iex> :ets.i(table)
131125
<3 > {"India", 1_284_000_000}
132126
```
133127

134-
## The math module
128+
## 数学模块
135129

136-
[The `math` module](http://erlang.org/doc/man/math.html) contains common
137-
mathematical operations covering trigonometry, exponential and logarithmic
138-
functions.
130+
[数学模块](http://erlang.org/doc/man/math.html) 包含了常用数学操作,
131+
如三角函数、指数或底数函数等等。
139132

140133
```iex
141134
iex> angle_45_deg = :math.pi() * 45.0 / 180.0
@@ -147,10 +140,10 @@ iex> :math.log(7.694785265142018e23)
147140
55.0
148141
```
149142

150-
## The queue module
143+
## 队列(queue)模块
151144

152-
The [`queue` is a data structure](http://erlang.org/doc/man/queue.html)
153-
that implements (double-ended) FIFO (first-in first-out) queues efficiently:
145+
[队列 `queue` 是一种数据结构](http://erlang.org/doc/man/queue.html)
146+
实现了双向先进先出的高效率队列:
154147

155148
```iex
156149
iex> q = :queue.new
@@ -167,10 +160,9 @@ iex> value
167160
:empty
168161
```
169162

170-
## The rand module
163+
## 随机值(rand)模块
171164

172-
[`rand` has functions](http://erlang.org/doc/man/rand.html) for returning
173-
random values and setting the random seed.
165+
[`rand`模块函数](http://erlang.org/doc/man/rand.html) 可以返回随机值或是设置随机seed:
174166

175167
```iex
176168
iex> :rand.uniform()
@@ -182,20 +174,20 @@ iex> :rand.uniform(6)
182174
6
183175
```
184176

185-
## The zip and zlib modules
177+
## zip和zlib模块
186178

187-
[The `zip` module](http://erlang.org/doc/man/zip.html) lets you read and write zip files to and from disk or memory,
188-
as well as extracting file information.
179+
[`zip`模块](http://erlang.org/doc/man/zip.html) 可以让你读写磁盘或内存中的zip文件,
180+
以及提取其文件信息等。
189181

190-
This code counts the number of files in a zip file:
182+
以下代码计算了zip压缩包中的文件数量:
191183

192184
```iex
193185
iex> :zip.foldl(fn _, _, _, acc -> acc + 1 end, 0, :binary.bin_to_list("file.zip"))
194186
{:ok, 633}
195187
```
196188

197-
[The `zlib` module](http://erlang.org/doc/man/zlib.html) deals with data compression in zlib format, as found in the
198-
`gzip` command.
189+
[`zlib`模块](http://erlang.org/doc/man/zlib.html) 处理zlib格式的数据压缩
190+
(如gzip中用的):
199191

200192
```iex
201193
iex> song = "

22-next.md

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,59 @@
11
20-下一步
22
==========
3-
[构建你第一个Elixir工程]() <br/>
4-
[社区和其它资源]() <br/>
5-
[Erlang一瞥]() <br/>
63

74
还想学习更多?继续阅读吧!
85

9-
## 20.1-构建你第一个Elixir工程
10-
Elixir提供了一个构建工具叫做Mix。你可以简单地执行以下命令来开始你的项目:
6+
## 构建第一个Elixir工程
7+
8+
Elixir提供了一个构建工具叫做Mix。你可以简单地执行以下命令来开始构建项目:
9+
1110
```
1211
mix new path/to/new/project
1312
```
14-
我们已经写好了一份手册,涵盖了如何构建一个Elixir程序,包括它自己的监督树,配置,测试等等。
15-
这个程序是一个分布式的键值对存储程序:
16-
- [Mix and OTP](http://elixir-lang.org/getting_started/mix_otp/1.html)
17-
18-
19-
## 20.2-社区和其它资源
20-
[Blog](http://elixir-lang.org/blog/) <br/>
21-
[文档](http://elixir-lang.org/docs.html) <br/>
22-
23-
# Seriously, please check out my next works about [advanced Elixir programming](https://github.com/straightdave/elixir_adv) !
24-
请看拙作《高级Elixir编程》.名字随便起的,主要是Elixir编程一些进阶的知识。翻译、整理自官网或者自己理解等。
25-
https://github.com/straightdave/elixir_adv
26-
27-
28-
29-
30-
31-
32-
33-
34-
35-
36-
3713

14+
这里已经写好了一份手册,讲述了如何构建一个Elixir应用程序,包括它自己的监督树,配置,测试等等。
15+
这个应用程序是一个分布式的键-值对存储程序。它以键-值对的形式将数据存储在“桶”里,
16+
并且把这些“桶”分发到不同的节点:
3817

18+
- [Advanced Elixir](https://github.com/straightdave/advanced_elixir)
3919

20+
## 元编程
4021

22+
感谢语言上的元编程支持,Elixir具有可扩展性和高度定制性。
23+
Elixir的元编程主要是由“宏”实现。在许多情景,特别是开发DSL特别有用。
24+
这里也有一份手册文档,讲述了宏背后的基础原理,以及如何利用宏实现元编程来创建DSL:
4125

26+
- [Elixir元编程](https://github.com/straightdave/elixir_meta_programming)
4227

28+
## 社区和其它资源
4329

30+
社区内的[“学习”部分](http://elixir-lang.org/learning.html)
31+
推荐了一些书籍、视频等资源来学习Elixir,探索其生态系统。
32+
还有一些,如程序大会的演讲、开源项目等由社区创建的学习资料在那里。
4433

34+
记住如果遇到困难,可以访问 __#elixir-lang__ 频道(__irc.freenode.net__),
35+
或是向邮件列表中发信。可以肯定那里会有人愿意提供帮助。收藏博客或是
36+
[订阅邮件列表](https://groups.google.com/group/elixir-lang-core)
37+
以接收最新的新闻和声明。
4538

39+
别忘记还可以阅读Elixir的源码,其大部分使用Elixir写的(主要是lib那个目录下)。
40+
或是[阅读Elixir的文档](http://elixir-lang.org/docs.html)
4641

42+
## 来点Erlang
4743

44+
Elixir运行于Erlang虚拟机。不久之后,Elixir的开发者会完成对所有Erlang库的连接。
45+
以下这些在线资源包含了Erlang的基础知识及高级特性:
4846

47+
- [Erlang语法速成](http://elixir-lang.org/crash-course.html)
48+
提供了Erlang语法的简要介绍。每个代码片段都附有对等的Elixir代码。
49+
这不但有助于你一窥Erlang的语法,还可以复习你在本指导书里学到的知识。
4950

51+
- Erlang的官方站点有份简短的
52+
[图文教程](http://www.erlang.org/course/concurrent_programming.html)
53+
简要描述了Erlang并行编程的原语。
5054

55+
- [为你好学点Erlang吧](http://learnyousomeerlang.com/)
56+
是极好的Erlang介绍:它的设计原则、标准库、最佳实践等等等等。
57+
只要阅读上述速成,你就可以安全地忽略一些Erlang教课书前面介绍基础语法的几章。当阅读到
58+
[并发指南](http://learnyousomeerlang.com/the-hitchhikers-guide-to-concurrency)
59+
时,真正的愉悦开始了。

0 commit comments

Comments
 (0)