使用帮助?
September 27th, 2007 :: jackyz
如何输入Erlang代码?
2007.04.16. update.
通过 Hack PEAR/Highliter 增加了 Erlang 的语法加亮支持。
2007.04.16.
安装了 Coolcode 插件,以解决输入 Erlang 代码显示时格式丢失的问题。编辑器也从 tinyMCE 改为了 WordPress Classic 输入代码的方式示例如下:
基本用法,输入:
<coolcode>
-module(tut4).
-export([list_length/1]).
list_length([]) ->
0;
list_length([First | Rest]) ->
1 + list_length(Rest).
</coolcode>
结果:
- -module(tut4).
- -export([list_length/1]).
- list_length([]) ->
- 0;
- list_length([First | Rest]) ->
- 1 + list_length(Rest).
加上 Erlang 语法加亮,输入:
<coolcode lang="erlang">
-module(tut4).
-export([list_length/1]).
list_length([]) ->
0;
list_length([First | Rest]) ->
1 + list_length(Rest).
</coolcode>
结果:
- -module(tut4).
- -export([list_length/1]).
- list_length([]) ->
- 0;
- list_length([First | Rest]) ->
- 1 + list_length(Rest).
加上 Erlang 语法加亮,并关闭行号,输入:
<coolcode lang="erlang" linenum="off">
-module(tut4).
-export([list_length/1]).
list_length([]) ->
0;
list_length([First | Rest]) ->
1 + list_length(Rest).
</coolcode>
结果:
-module(tut4).
-export([list_length/1]).
list_length([]) ->
0;
list_length([First | Rest]) ->
1 + list_length(Rest).
-export([list_length/1]).
list_length([]) ->
0;
list_length([First | Rest]) ->
1 + list_length(Rest).
加上 Erlang 语法加亮,并加上源文件下载链接,输入:
<coolcode lang="erlang" download="tut4.erl">
-module(tut4).
-export([list_length/1]).
list_length([]) ->
0;
list_length([First | Rest]) ->
1 + list_length(Rest).
</coolcode>
结果:
下载: tut4.erl
- -module(tut4).
- -export([list_length/1]).
- list_length([]) ->
- 0;
- list_length([First | Rest]) ->
- 1 + list_length(Rest).
目前支持的程序设计语言有(lang的取值):
* actionscript
* cpp
* css
* diff
* dtd
* html
* java
* javascript
* mysql
* perl
* php
* python
* ruby
* sql
* xml
The goal of this assignment is to make a distributed fault-tolerant application for a simple
computation of prime numbers. (Large prime numbers are user in security algorithms, if you
like to know a practical application of this algorithm).
A prime number is a number that is only dividable by 1 and itself, i.e. for N to be prime it
must hold that for all M between 2 and N-1 the erlang expression N rem M evaluates to
something unequal zero. The first few prime numbers are 1,2,3,5,7,11,13,…
Write a demonstrator for a fault-tolerant distributed application. A number of computers
should be connected in a network, say 1 to N.
It is known how they are positioned, i.e., 1 nest to 2, next to 3, … next to N.
On each computer you run the same program. This program computes the prime numbers, but
it skips numbers that other computers have already analyzed. Thus, if computer 1 starts to
compute whether 1 is a prime, then it informs the others, which decide to go on to the next
number (2, 3, 4, etc). In the end, all computers print a list of all prime numbers, but never
compute a prime number if one of the other computers already took that task.
As soon as a computer is disconnected from the network, or the Erlang node that it runs is
killed (simulating a crash), then the other computers continue working.
When a crashed computer is restarted (or the Erlang node restarted), the program joins the
pool and starts doing computations again.